LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 02-25-2003, 11:30 PM   #1
J_Szucs
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-25-2003 at 11:31 PM.
 
Old 02-25-2003, 11:38 PM   #2
Crashed_Again
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:

!1057

A very cool feature I think.

Last edited by Crashed_Again; 02-25-2003 at 11:42 PM.
 
Old 03-06-2003, 09:43 AM   #3
rickenbacherus
Member
 
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, 10:32 AM   #4
wapcaplet
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
(errors)
$ !v
(edit in vi, then exit)
$ !g
(more errors)

 
Old 03-06-2003, 03:29 PM   #5
boreo
Member
 
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, 03:32 PM   #6
MasterC
Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

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

Cool
 
Old 03-06-2003, 10:24 PM   #7
cuckoopint
Member
 
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)

!mount

will do.
 
Old 03-06-2003, 10:39 PM   #8
Texicle
Member
 
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, 10:40 PM   #9
Crashed_Again
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, 12:29 AM   #10
orange400
Member
 
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.
 
  


Reply


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 04:42 PM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 07:14 PM
Getting out of command prompt squirellplaying Linux - Newbie 8 05-05-2004 08:44 PM
Command Prompt? eXdener Linux - Newbie 3 01-05-2004 04:38 PM
im only getting command prompt sniperhf Linux - Software 10 06-16-2003 03:19 PM


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

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