Understanding the exclamation mark (!) in bash
I used
history | less
to get the lines of previous commands and from the numbers on the left hand side I found the line I wanted repeated (eg. 22) and did
!22
at the command prompt and it worked -- executing the set of commands on the line I did at that time. I cannot figure out where the exclamation mark is used, what does it represent in terms of actions taken by bash, and where to use it. From the documentation I do not see an explanation that is 'tangible'.
command-line bash command-history
add a comment |
I used
history | less
to get the lines of previous commands and from the numbers on the left hand side I found the line I wanted repeated (eg. 22) and did
!22
at the command prompt and it worked -- executing the set of commands on the line I did at that time. I cannot figure out where the exclamation mark is used, what does it represent in terms of actions taken by bash, and where to use it. From the documentation I do not see an explanation that is 'tangible'.
command-line bash command-history
6
This answer might help
– Michael Mrozek♦
Nov 3 '10 at 21:50
5
Not an answer to your question, but <ctrl>+R will allow you to interactively search your history and then immediately execute if you find what you were looking for.
– kasterma
Nov 3 '10 at 22:25
add a comment |
I used
history | less
to get the lines of previous commands and from the numbers on the left hand side I found the line I wanted repeated (eg. 22) and did
!22
at the command prompt and it worked -- executing the set of commands on the line I did at that time. I cannot figure out where the exclamation mark is used, what does it represent in terms of actions taken by bash, and where to use it. From the documentation I do not see an explanation that is 'tangible'.
command-line bash command-history
I used
history | less
to get the lines of previous commands and from the numbers on the left hand side I found the line I wanted repeated (eg. 22) and did
!22
at the command prompt and it worked -- executing the set of commands on the line I did at that time. I cannot figure out where the exclamation mark is used, what does it represent in terms of actions taken by bash, and where to use it. From the documentation I do not see an explanation that is 'tangible'.
command-line bash command-history
command-line bash command-history
edited Aug 23 '11 at 12:42
Caleb
50.9k9149192
50.9k9149192
asked Nov 3 '10 at 19:41
VassVass
1,82682539
1,82682539
6
This answer might help
– Michael Mrozek♦
Nov 3 '10 at 21:50
5
Not an answer to your question, but <ctrl>+R will allow you to interactively search your history and then immediately execute if you find what you were looking for.
– kasterma
Nov 3 '10 at 22:25
add a comment |
6
This answer might help
– Michael Mrozek♦
Nov 3 '10 at 21:50
5
Not an answer to your question, but <ctrl>+R will allow you to interactively search your history and then immediately execute if you find what you were looking for.
– kasterma
Nov 3 '10 at 22:25
6
6
This answer might help
– Michael Mrozek♦
Nov 3 '10 at 21:50
This answer might help
– Michael Mrozek♦
Nov 3 '10 at 21:50
5
5
Not an answer to your question, but <ctrl>+R will allow you to interactively search your history and then immediately execute if you find what you were looking for.
– kasterma
Nov 3 '10 at 22:25
Not an answer to your question, but <ctrl>+R will allow you to interactively search your history and then immediately execute if you find what you were looking for.
– kasterma
Nov 3 '10 at 22:25
add a comment |
5 Answers
5
active
oldest
votes
!
is a feature that originally appeared in the C shell, back in the days before you could count on terminals to have arrow keys. It's especially useful if you add the current command number to the prompt (PS1="!$ "
) so you can quickly look at your screen to get numbers for past commands.
Now that you can use arrow keys and things like Ctrl-R to search the command history, I don't see much use for the feature.
One variant of it you might still find useful is !!
, which re-executes the previous command. On its own, I don't find !!Enter any faster than just ↑ Enter, but it can be helpful when combined into a larger command.
Example: A common pilot error on sudo
based systems is to forget the sudo
prefix on a command that requires extra privileges. A novice retypes the whole command. The diligent student edits the command from the shell's command history. The enlightened one types sudo !!
.
Bash lets you disable !
processing in the shell with set +o histexpand
or set +H
. You can disable it in Zsh with set -K
.
3
I find Ctrl-P Ctrl-J to be pretty fast; faster than Up Enter, at least.
– ephemient
Nov 5 '10 at 1:55
21
If you just want to run the last command, Up/Enter is fine, but if you want to add to it in some way (say, you forgot tosudo
, or something), then you can dosudo !!
, for example. That might be a bit faster than "Up/Ctrl-A(or Home, if you are lucky enough)/sudo/space/enter". YMMV. :)
– malvim
Jan 14 '11 at 20:57
1
@AquariusPower: Just quote it. Eitherecho 'Hi!'
orecho "Hi!"
orecho Hi!
. All do the same thing.
– Warren Young
Jul 18 '13 at 16:14
add a comment |
If there isn't a longer answer here there's certainly one on Super User, since I've read one recently. In the bash man page you can find a huge section titled HISTORY EXPANSION on the matter.
You can do a whole host more than just run the last command, or command number X. You can do things like !cat
to run the last command that started with cat
. Or !?bash?:s/bash/csh/
runs the last command containing bash
but replaces it with csh
.
2
Although not directly an answer to OP's question, this needs way more upvotes. So useful! Thanks, Havok.
– malvim
Apr 30 '15 at 19:09
Uh, I should really look into the man page before I start googling.
– erikbwork
Jul 27 '15 at 13:39
1
!!:s/bash/csh/
actually runs the last command, then replaces bash with csh, if present. Not the last command that included bash. That would be!?bash?:s/bash/csh/
or maybe!?bash?:s/%/csh/
– cde
Jan 24 '16 at 14:31
Having used Bash extensively for several years, I was shocked to find that I had never known about this keyword before, and even though I have spent hours poring through theman
pages, this feature is incredibly obscure. Thank you for pointing out the relevant section--that's the only place in the actual docs where they explain it sufficiently.
– Steve Benner
Jan 30 at 9:19
add a comment |
A lot more can be done with !
such as:
- execute a command which is typed before 3 commands:
!-3
- execute a command that starts with
!ls
and a lot more. See 15 Linux Bash History Expansion Examples You Should Know
Upvoted this. None of the other answers had any of these clever tricks.
– Gergely Lukacsy
Feb 15 '17 at 14:38
Upvoted because www.thegeekstuff.com is simply a fantastic resource, and this was one of the few linux articles I hadn't seen before. Very helpful.
– Steve Benner
Jan 30 at 9:16
add a comment |
A friend of mine emailed me this:
It's part of GNU history library. In bash it is used to re-run
commands in your history. If you want to be hardcore, grep for
history_expansion_char in bash-4.1/lib/readline/histexpand.c for
implementation details.
add a comment |
Of course you can do !!
to reuse the last command in bash shell. And then there is !$
to reuse the last part of your last command.
e.g. view some file
less path/to/your/file.txt
If you now want to edit the same file, you can use !$
to get only the file path from the last command
vim !$
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f3747%2funderstanding-the-exclamation-mark-in-bash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
!
is a feature that originally appeared in the C shell, back in the days before you could count on terminals to have arrow keys. It's especially useful if you add the current command number to the prompt (PS1="!$ "
) so you can quickly look at your screen to get numbers for past commands.
Now that you can use arrow keys and things like Ctrl-R to search the command history, I don't see much use for the feature.
One variant of it you might still find useful is !!
, which re-executes the previous command. On its own, I don't find !!Enter any faster than just ↑ Enter, but it can be helpful when combined into a larger command.
Example: A common pilot error on sudo
based systems is to forget the sudo
prefix on a command that requires extra privileges. A novice retypes the whole command. The diligent student edits the command from the shell's command history. The enlightened one types sudo !!
.
Bash lets you disable !
processing in the shell with set +o histexpand
or set +H
. You can disable it in Zsh with set -K
.
3
I find Ctrl-P Ctrl-J to be pretty fast; faster than Up Enter, at least.
– ephemient
Nov 5 '10 at 1:55
21
If you just want to run the last command, Up/Enter is fine, but if you want to add to it in some way (say, you forgot tosudo
, or something), then you can dosudo !!
, for example. That might be a bit faster than "Up/Ctrl-A(or Home, if you are lucky enough)/sudo/space/enter". YMMV. :)
– malvim
Jan 14 '11 at 20:57
1
@AquariusPower: Just quote it. Eitherecho 'Hi!'
orecho "Hi!"
orecho Hi!
. All do the same thing.
– Warren Young
Jul 18 '13 at 16:14
add a comment |
!
is a feature that originally appeared in the C shell, back in the days before you could count on terminals to have arrow keys. It's especially useful if you add the current command number to the prompt (PS1="!$ "
) so you can quickly look at your screen to get numbers for past commands.
Now that you can use arrow keys and things like Ctrl-R to search the command history, I don't see much use for the feature.
One variant of it you might still find useful is !!
, which re-executes the previous command. On its own, I don't find !!Enter any faster than just ↑ Enter, but it can be helpful when combined into a larger command.
Example: A common pilot error on sudo
based systems is to forget the sudo
prefix on a command that requires extra privileges. A novice retypes the whole command. The diligent student edits the command from the shell's command history. The enlightened one types sudo !!
.
Bash lets you disable !
processing in the shell with set +o histexpand
or set +H
. You can disable it in Zsh with set -K
.
3
I find Ctrl-P Ctrl-J to be pretty fast; faster than Up Enter, at least.
– ephemient
Nov 5 '10 at 1:55
21
If you just want to run the last command, Up/Enter is fine, but if you want to add to it in some way (say, you forgot tosudo
, or something), then you can dosudo !!
, for example. That might be a bit faster than "Up/Ctrl-A(or Home, if you are lucky enough)/sudo/space/enter". YMMV. :)
– malvim
Jan 14 '11 at 20:57
1
@AquariusPower: Just quote it. Eitherecho 'Hi!'
orecho "Hi!"
orecho Hi!
. All do the same thing.
– Warren Young
Jul 18 '13 at 16:14
add a comment |
!
is a feature that originally appeared in the C shell, back in the days before you could count on terminals to have arrow keys. It's especially useful if you add the current command number to the prompt (PS1="!$ "
) so you can quickly look at your screen to get numbers for past commands.
Now that you can use arrow keys and things like Ctrl-R to search the command history, I don't see much use for the feature.
One variant of it you might still find useful is !!
, which re-executes the previous command. On its own, I don't find !!Enter any faster than just ↑ Enter, but it can be helpful when combined into a larger command.
Example: A common pilot error on sudo
based systems is to forget the sudo
prefix on a command that requires extra privileges. A novice retypes the whole command. The diligent student edits the command from the shell's command history. The enlightened one types sudo !!
.
Bash lets you disable !
processing in the shell with set +o histexpand
or set +H
. You can disable it in Zsh with set -K
.
!
is a feature that originally appeared in the C shell, back in the days before you could count on terminals to have arrow keys. It's especially useful if you add the current command number to the prompt (PS1="!$ "
) so you can quickly look at your screen to get numbers for past commands.
Now that you can use arrow keys and things like Ctrl-R to search the command history, I don't see much use for the feature.
One variant of it you might still find useful is !!
, which re-executes the previous command. On its own, I don't find !!Enter any faster than just ↑ Enter, but it can be helpful when combined into a larger command.
Example: A common pilot error on sudo
based systems is to forget the sudo
prefix on a command that requires extra privileges. A novice retypes the whole command. The diligent student edits the command from the shell's command history. The enlightened one types sudo !!
.
Bash lets you disable !
processing in the shell with set +o histexpand
or set +H
. You can disable it in Zsh with set -K
.
edited Nov 5 '13 at 23:53
answered Nov 3 '10 at 20:06
Warren YoungWarren Young
55.2k11143148
55.2k11143148
3
I find Ctrl-P Ctrl-J to be pretty fast; faster than Up Enter, at least.
– ephemient
Nov 5 '10 at 1:55
21
If you just want to run the last command, Up/Enter is fine, but if you want to add to it in some way (say, you forgot tosudo
, or something), then you can dosudo !!
, for example. That might be a bit faster than "Up/Ctrl-A(or Home, if you are lucky enough)/sudo/space/enter". YMMV. :)
– malvim
Jan 14 '11 at 20:57
1
@AquariusPower: Just quote it. Eitherecho 'Hi!'
orecho "Hi!"
orecho Hi!
. All do the same thing.
– Warren Young
Jul 18 '13 at 16:14
add a comment |
3
I find Ctrl-P Ctrl-J to be pretty fast; faster than Up Enter, at least.
– ephemient
Nov 5 '10 at 1:55
21
If you just want to run the last command, Up/Enter is fine, but if you want to add to it in some way (say, you forgot tosudo
, or something), then you can dosudo !!
, for example. That might be a bit faster than "Up/Ctrl-A(or Home, if you are lucky enough)/sudo/space/enter". YMMV. :)
– malvim
Jan 14 '11 at 20:57
1
@AquariusPower: Just quote it. Eitherecho 'Hi!'
orecho "Hi!"
orecho Hi!
. All do the same thing.
– Warren Young
Jul 18 '13 at 16:14
3
3
I find Ctrl-P Ctrl-J to be pretty fast; faster than Up Enter, at least.
– ephemient
Nov 5 '10 at 1:55
I find Ctrl-P Ctrl-J to be pretty fast; faster than Up Enter, at least.
– ephemient
Nov 5 '10 at 1:55
21
21
If you just want to run the last command, Up/Enter is fine, but if you want to add to it in some way (say, you forgot to
sudo
, or something), then you can do sudo !!
, for example. That might be a bit faster than "Up/Ctrl-A(or Home, if you are lucky enough)/sudo/space/enter". YMMV. :)– malvim
Jan 14 '11 at 20:57
If you just want to run the last command, Up/Enter is fine, but if you want to add to it in some way (say, you forgot to
sudo
, or something), then you can do sudo !!
, for example. That might be a bit faster than "Up/Ctrl-A(or Home, if you are lucky enough)/sudo/space/enter". YMMV. :)– malvim
Jan 14 '11 at 20:57
1
1
@AquariusPower: Just quote it. Either
echo 'Hi!'
or echo "Hi!"
or echo Hi!
. All do the same thing.– Warren Young
Jul 18 '13 at 16:14
@AquariusPower: Just quote it. Either
echo 'Hi!'
or echo "Hi!"
or echo Hi!
. All do the same thing.– Warren Young
Jul 18 '13 at 16:14
add a comment |
If there isn't a longer answer here there's certainly one on Super User, since I've read one recently. In the bash man page you can find a huge section titled HISTORY EXPANSION on the matter.
You can do a whole host more than just run the last command, or command number X. You can do things like !cat
to run the last command that started with cat
. Or !?bash?:s/bash/csh/
runs the last command containing bash
but replaces it with csh
.
2
Although not directly an answer to OP's question, this needs way more upvotes. So useful! Thanks, Havok.
– malvim
Apr 30 '15 at 19:09
Uh, I should really look into the man page before I start googling.
– erikbwork
Jul 27 '15 at 13:39
1
!!:s/bash/csh/
actually runs the last command, then replaces bash with csh, if present. Not the last command that included bash. That would be!?bash?:s/bash/csh/
or maybe!?bash?:s/%/csh/
– cde
Jan 24 '16 at 14:31
Having used Bash extensively for several years, I was shocked to find that I had never known about this keyword before, and even though I have spent hours poring through theman
pages, this feature is incredibly obscure. Thank you for pointing out the relevant section--that's the only place in the actual docs where they explain it sufficiently.
– Steve Benner
Jan 30 at 9:19
add a comment |
If there isn't a longer answer here there's certainly one on Super User, since I've read one recently. In the bash man page you can find a huge section titled HISTORY EXPANSION on the matter.
You can do a whole host more than just run the last command, or command number X. You can do things like !cat
to run the last command that started with cat
. Or !?bash?:s/bash/csh/
runs the last command containing bash
but replaces it with csh
.
2
Although not directly an answer to OP's question, this needs way more upvotes. So useful! Thanks, Havok.
– malvim
Apr 30 '15 at 19:09
Uh, I should really look into the man page before I start googling.
– erikbwork
Jul 27 '15 at 13:39
1
!!:s/bash/csh/
actually runs the last command, then replaces bash with csh, if present. Not the last command that included bash. That would be!?bash?:s/bash/csh/
or maybe!?bash?:s/%/csh/
– cde
Jan 24 '16 at 14:31
Having used Bash extensively for several years, I was shocked to find that I had never known about this keyword before, and even though I have spent hours poring through theman
pages, this feature is incredibly obscure. Thank you for pointing out the relevant section--that's the only place in the actual docs where they explain it sufficiently.
– Steve Benner
Jan 30 at 9:19
add a comment |
If there isn't a longer answer here there's certainly one on Super User, since I've read one recently. In the bash man page you can find a huge section titled HISTORY EXPANSION on the matter.
You can do a whole host more than just run the last command, or command number X. You can do things like !cat
to run the last command that started with cat
. Or !?bash?:s/bash/csh/
runs the last command containing bash
but replaces it with csh
.
If there isn't a longer answer here there's certainly one on Super User, since I've read one recently. In the bash man page you can find a huge section titled HISTORY EXPANSION on the matter.
You can do a whole host more than just run the last command, or command number X. You can do things like !cat
to run the last command that started with cat
. Or !?bash?:s/bash/csh/
runs the last command containing bash
but replaces it with csh
.
edited Jan 26 '18 at 20:44
Jeff Schaller
41k1056131
41k1056131
answered Nov 3 '10 at 20:12
Cry HavokCry Havok
1,4901011
1,4901011
2
Although not directly an answer to OP's question, this needs way more upvotes. So useful! Thanks, Havok.
– malvim
Apr 30 '15 at 19:09
Uh, I should really look into the man page before I start googling.
– erikbwork
Jul 27 '15 at 13:39
1
!!:s/bash/csh/
actually runs the last command, then replaces bash with csh, if present. Not the last command that included bash. That would be!?bash?:s/bash/csh/
or maybe!?bash?:s/%/csh/
– cde
Jan 24 '16 at 14:31
Having used Bash extensively for several years, I was shocked to find that I had never known about this keyword before, and even though I have spent hours poring through theman
pages, this feature is incredibly obscure. Thank you for pointing out the relevant section--that's the only place in the actual docs where they explain it sufficiently.
– Steve Benner
Jan 30 at 9:19
add a comment |
2
Although not directly an answer to OP's question, this needs way more upvotes. So useful! Thanks, Havok.
– malvim
Apr 30 '15 at 19:09
Uh, I should really look into the man page before I start googling.
– erikbwork
Jul 27 '15 at 13:39
1
!!:s/bash/csh/
actually runs the last command, then replaces bash with csh, if present. Not the last command that included bash. That would be!?bash?:s/bash/csh/
or maybe!?bash?:s/%/csh/
– cde
Jan 24 '16 at 14:31
Having used Bash extensively for several years, I was shocked to find that I had never known about this keyword before, and even though I have spent hours poring through theman
pages, this feature is incredibly obscure. Thank you for pointing out the relevant section--that's the only place in the actual docs where they explain it sufficiently.
– Steve Benner
Jan 30 at 9:19
2
2
Although not directly an answer to OP's question, this needs way more upvotes. So useful! Thanks, Havok.
– malvim
Apr 30 '15 at 19:09
Although not directly an answer to OP's question, this needs way more upvotes. So useful! Thanks, Havok.
– malvim
Apr 30 '15 at 19:09
Uh, I should really look into the man page before I start googling.
– erikbwork
Jul 27 '15 at 13:39
Uh, I should really look into the man page before I start googling.
– erikbwork
Jul 27 '15 at 13:39
1
1
!!:s/bash/csh/
actually runs the last command, then replaces bash with csh, if present. Not the last command that included bash. That would be !?bash?:s/bash/csh/
or maybe !?bash?:s/%/csh/
– cde
Jan 24 '16 at 14:31
!!:s/bash/csh/
actually runs the last command, then replaces bash with csh, if present. Not the last command that included bash. That would be !?bash?:s/bash/csh/
or maybe !?bash?:s/%/csh/
– cde
Jan 24 '16 at 14:31
Having used Bash extensively for several years, I was shocked to find that I had never known about this keyword before, and even though I have spent hours poring through the
man
pages, this feature is incredibly obscure. Thank you for pointing out the relevant section--that's the only place in the actual docs where they explain it sufficiently.– Steve Benner
Jan 30 at 9:19
Having used Bash extensively for several years, I was shocked to find that I had never known about this keyword before, and even though I have spent hours poring through the
man
pages, this feature is incredibly obscure. Thank you for pointing out the relevant section--that's the only place in the actual docs where they explain it sufficiently.– Steve Benner
Jan 30 at 9:19
add a comment |
A lot more can be done with !
such as:
- execute a command which is typed before 3 commands:
!-3
- execute a command that starts with
!ls
and a lot more. See 15 Linux Bash History Expansion Examples You Should Know
Upvoted this. None of the other answers had any of these clever tricks.
– Gergely Lukacsy
Feb 15 '17 at 14:38
Upvoted because www.thegeekstuff.com is simply a fantastic resource, and this was one of the few linux articles I hadn't seen before. Very helpful.
– Steve Benner
Jan 30 at 9:16
add a comment |
A lot more can be done with !
such as:
- execute a command which is typed before 3 commands:
!-3
- execute a command that starts with
!ls
and a lot more. See 15 Linux Bash History Expansion Examples You Should Know
Upvoted this. None of the other answers had any of these clever tricks.
– Gergely Lukacsy
Feb 15 '17 at 14:38
Upvoted because www.thegeekstuff.com is simply a fantastic resource, and this was one of the few linux articles I hadn't seen before. Very helpful.
– Steve Benner
Jan 30 at 9:16
add a comment |
A lot more can be done with !
such as:
- execute a command which is typed before 3 commands:
!-3
- execute a command that starts with
!ls
and a lot more. See 15 Linux Bash History Expansion Examples You Should Know
A lot more can be done with !
such as:
- execute a command which is typed before 3 commands:
!-3
- execute a command that starts with
!ls
and a lot more. See 15 Linux Bash History Expansion Examples You Should Know
edited Mar 6 '12 at 10:53
Mat
39.3k8121127
39.3k8121127
answered Mar 6 '12 at 10:34
user379997user379997
47157
47157
Upvoted this. None of the other answers had any of these clever tricks.
– Gergely Lukacsy
Feb 15 '17 at 14:38
Upvoted because www.thegeekstuff.com is simply a fantastic resource, and this was one of the few linux articles I hadn't seen before. Very helpful.
– Steve Benner
Jan 30 at 9:16
add a comment |
Upvoted this. None of the other answers had any of these clever tricks.
– Gergely Lukacsy
Feb 15 '17 at 14:38
Upvoted because www.thegeekstuff.com is simply a fantastic resource, and this was one of the few linux articles I hadn't seen before. Very helpful.
– Steve Benner
Jan 30 at 9:16
Upvoted this. None of the other answers had any of these clever tricks.
– Gergely Lukacsy
Feb 15 '17 at 14:38
Upvoted this. None of the other answers had any of these clever tricks.
– Gergely Lukacsy
Feb 15 '17 at 14:38
Upvoted because www.thegeekstuff.com is simply a fantastic resource, and this was one of the few linux articles I hadn't seen before. Very helpful.
– Steve Benner
Jan 30 at 9:16
Upvoted because www.thegeekstuff.com is simply a fantastic resource, and this was one of the few linux articles I hadn't seen before. Very helpful.
– Steve Benner
Jan 30 at 9:16
add a comment |
A friend of mine emailed me this:
It's part of GNU history library. In bash it is used to re-run
commands in your history. If you want to be hardcore, grep for
history_expansion_char in bash-4.1/lib/readline/histexpand.c for
implementation details.
add a comment |
A friend of mine emailed me this:
It's part of GNU history library. In bash it is used to re-run
commands in your history. If you want to be hardcore, grep for
history_expansion_char in bash-4.1/lib/readline/histexpand.c for
implementation details.
add a comment |
A friend of mine emailed me this:
It's part of GNU history library. In bash it is used to re-run
commands in your history. If you want to be hardcore, grep for
history_expansion_char in bash-4.1/lib/readline/histexpand.c for
implementation details.
A friend of mine emailed me this:
It's part of GNU history library. In bash it is used to re-run
commands in your history. If you want to be hardcore, grep for
history_expansion_char in bash-4.1/lib/readline/histexpand.c for
implementation details.
edited Nov 5 '10 at 2:58
Michael Mrozek♦
61.2k29191211
61.2k29191211
answered Nov 4 '10 at 13:58
VassVass
1,82682539
1,82682539
add a comment |
add a comment |
Of course you can do !!
to reuse the last command in bash shell. And then there is !$
to reuse the last part of your last command.
e.g. view some file
less path/to/your/file.txt
If you now want to edit the same file, you can use !$
to get only the file path from the last command
vim !$
New contributor
add a comment |
Of course you can do !!
to reuse the last command in bash shell. And then there is !$
to reuse the last part of your last command.
e.g. view some file
less path/to/your/file.txt
If you now want to edit the same file, you can use !$
to get only the file path from the last command
vim !$
New contributor
add a comment |
Of course you can do !!
to reuse the last command in bash shell. And then there is !$
to reuse the last part of your last command.
e.g. view some file
less path/to/your/file.txt
If you now want to edit the same file, you can use !$
to get only the file path from the last command
vim !$
New contributor
Of course you can do !!
to reuse the last command in bash shell. And then there is !$
to reuse the last part of your last command.
e.g. view some file
less path/to/your/file.txt
If you now want to edit the same file, you can use !$
to get only the file path from the last command
vim !$
New contributor
New contributor
answered 23 mins ago
Teshan Shanuka JTeshan Shanuka J
1
1
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f3747%2funderstanding-the-exclamation-mark-in-bash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
6
This answer might help
– Michael Mrozek♦
Nov 3 '10 at 21:50
5
Not an answer to your question, but <ctrl>+R will allow you to interactively search your history and then immediately execute if you find what you were looking for.
– kasterma
Nov 3 '10 at 22:25