How to recall an old command at the command prompt?
I know how to step through the command history at the command prompt, but is it also possible to search for and recall a command that was issued a long time before (supposed that it is still in the history)?
From time to time I wish there was one, but I could not find the clue in the bash manual. Thanks in advance. |
Yes there is:
history | more This will spit back the last 1000 commands you have issued. Well for bash it is 1000 by default but you can change it. Each command will have a number before it. Heres an example of one of the things you will get back from the history command: 1057 mount -t iso9660 /dev/scd0 /mnt/cdrom Now if you want to run that command again just do: !1057 A very cool feature I think. |
Right on Crashed_Again - I gotta write that one down somewhere.
|
Definitely, I'm a big fan of the shebang-history command. Also, if you have a terminal in which the up-arrow doesn't recall your last command, hitting !! repeats the last command.
Good for compile-edit cycles, too: $ vi prog.c $ gcc prog.c (errors) $ !v (edit in vi, then exit) $ !g (more errors) :D |
Or if your looking for commands that contains exact words your would do this
history |grep mount And all the commands with the word "mount" will show up instead of the whole history. You will get something like this. 370 mount /mnt/cdrom1 371 umount /mnt/cdrom1 372 umount /mnt/cdrom 385 umount /mnt/cdrom1 386 umount /mnt/cdrom 425 umount /mnt/cdrom 516 history |grep mount |
I learn something new everyday... literally. Thanks everyone. :)
Cool |
you could also use the bang command as a search/recall automatically....instead of grepping history, if you know you want the last mount command (which may have been a long time ago)
!mount will do. |
That is too cool. Thanks everyone! :D With stuff like that, how can you not love Linux?
|
How can you not love the BASH shell.
|
I use it half the time, I gotta say it's the most useful Linuc prog I use besides Mozilla.
|
All times are GMT -5. The time now is 05:42 AM. |