LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 10-12-2005, 04:44 PM   #1
funkynesh
LQ Newbie
 
Registered: Oct 2005
Posts: 13

Rep: Reputation: 1
The ! bash command. How do I use it?


I was wondering what is the purpose of the ! command in bash? How do I use it?

Thank you
 
Old 10-12-2005, 05:11 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
If you type !<command> it repeats the last time you used said command (with the same arguements you used before).

So, for instance, if I type ps a followed by a !ps I will get the ps a output twice. This is useful if you want to re-issue a command you've used recently but don't want to have to type out a million arguements again.

Example:
Code:
johnshaw@Quaqmire-OSX ~ $ ps a
  PID  TT  STAT      TIME COMMAND
 9664  p1  Ss     0:00.02 login -pf johnshaw
 9665  p1  S      0:00.19 -bash
 9935  p1  R+     0:00.01 ps a
 9861  p2  Ss     0:00.03 login -pf johnshaw
 9862  p2  S      0:00.02 -bash
 9863  p2  S+     0:00.22 man pthread_join
 9864  p2  S+     0:00.01 sh -c (cd /usr/share/man && /usr/bin/tbl /usr/share/man/man3/pthread_join.3 | /u
 9865  p2  S+     0:00.01 sh -c (cd /usr/share/man && /usr/bin/tbl /usr/share/man/man3/pthread_join.3 | /u
 9868  p2  S+     0:00.01 /usr/bin/less -is
johnshaw@Quaqmire-OSX ~ $ !ps 
ps a
  PID  TT  STAT      TIME COMMAND
 9664  p1  Ss     0:00.02 login -pf johnshaw
 9665  p1  S      0:00.19 -bash
 9936  p1  R+     0:00.01 ps a
 9861  p2  Ss     0:00.03 login -pf johnshaw
 9862  p2  S      0:00.02 -bash
 9863  p2  S+     0:00.22 man pthread_join
 9864  p2  S+     0:00.01 sh -c (cd /usr/share/man && /usr/bin/tbl /usr/share/man/man3/pthread_join.3 | /u
 9865  p2  S+     0:00.01 sh -c (cd /usr/share/man && /usr/bin/tbl /usr/share/man/man3/pthread_join.3 | /u
 9868  p2  S+     0:00.01 /usr/bin/less -is
johnshaw@Quaqmire-OSX ~ $

Last edited by jtshaw; 10-12-2005 at 05:13 PM.
 
Old 10-12-2005, 08:36 PM   #3
funkynesh
LQ Newbie
 
Registered: Oct 2005
Posts: 13

Original Poster
Rep: Reputation: 1
Thanks!

But I saw combination of command like this one: !?<word>.

Why the ?, I understand that it tells bash to launch the last command that had <word> in it. A more in-depth explanation of the different combination you can use would be appreciate or a link to a document explaining it.
 
  


Reply



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
bash: command not found hamish Linux - Newbie 7 02-23-2011 04:28 PM
To undo a given bash-command HULLU Linux - Newbie 6 02-21-2010 10:06 PM
bash: <command name> command not found smash Programming 5 03-13-2006 08:48 AM
Bash command scripting otisthegbs Linux - General 6 07-06-2004 12:06 AM
bash command help bobdinkel Linux - Newbie 20 07-17-2003 02:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:22 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration