Increasing command line productivity in the bash shell PT: I

by Jeff on January 22, 2008

Brace expansions save you lots of typing:

$ ls
file1

$ cp file{1,2}
$ ls
file1  file2

$ mv file{1,1.old}; ls
file1.old file2

You can even use brace expansions in shell scripts:

#!/bin/bash
scp /path/to/{file1,dir2,file2} user@otherserver:/dump/
if [ $? -eq 0 ]; then
rm /path/to/{file1,dir2,file2}
fi

NOTE: In posix land, an exclamation mark is often referred to as a "bang".


!!
- aka "bang bang". Runs the previous command typed into the shell
!vi - Runs the most previous command starting with "vi"
!?passwd - Runs the most previous command that contained "passwd"
!vi:p - Prints the most previous command containing "vi" without running anything.
!vi:s/passwd/shadow/ - Runs the most previous command containing the word "vi" and replaces "passwd" with "shadow"

On to Part II --->

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Next post: