Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-26-2003, 12:30 AM   #1
Senior Member
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Rep: Reputation: 58
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.

Last edited by J_Szucs; 02-26-2003 at 12:31 AM.
Old 02-26-2003, 12:38 AM   #2
Senior Member
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Rep: Reputation: 57
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:


A very cool feature I think.

Last edited by Crashed_Again; 02-26-2003 at 12:42 AM.
Old 03-06-2003, 10:43 AM   #3
Registered: Mar 2003
Location: colorado springs. colorado
Distribution: Debian-Sid 2.6.24-rt1
Posts: 290

Rep: Reputation: 30
Right on Crashed_Again - I gotta write that one down somewhere.
Old 03-06-2003, 11:32 AM   #4
LQ Guru
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
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
$ !v
(edit in vi, then exit)
$ !g
(more errors)

Old 03-06-2003, 04:29 PM   #5
Registered: Feb 2003
Location: Dominican Republic
Distribution: Slackware, FreeBSD, RedHat
Posts: 326

Rep: Reputation: 30
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
Old 03-06-2003, 04:32 PM   #6
LQ Guru
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Rep: Reputation: 69
I learn something new everyday... literally. Thanks everyone.

Old 03-06-2003, 11:24 PM   #7
Registered: Feb 2003
Distribution: Debian
Posts: 797

Rep: Reputation: 30
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)


will do.
Old 03-06-2003, 11:39 PM   #8
Registered: Oct 2002
Location: Northern Ontario, Canada
Distribution: Slackware 10.0
Posts: 789

Rep: Reputation: 30
That is too cool. Thanks everyone! With stuff like that, how can you not love Linux?
Old 03-06-2003, 11:40 PM   #9
Senior Member
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Rep: Reputation: 57
How can you not love the BASH shell.
Old 03-07-2003, 01:29 AM   #10
Registered: Mar 2003
Location: Bellevue, WA
Distribution: Arch w/ XFCE
Posts: 834

Rep: Reputation: 30
I use it half the time, I gotta say it's the most useful Linuc prog I use besides Mozilla.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Prompt command to...? Kelphyr Slackware 10 10-03-2004 05:42 PM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 08:14 PM
Getting out of command prompt squirellplaying Linux - Newbie 8 05-05-2004 09:44 PM
Command Prompt? eXdener Linux - Newbie 3 01-05-2004 05:38 PM
im only getting command prompt sniperhf Linux - Software 10 06-16-2003 04:19 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:19 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration