From C4 Wiki
< Tools
Revision as of 22:13, 8 November 2004 by Mario Manno (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Using the BASH History

You can see the history by executing


Add a command to the end of the history like this without executing it

history -s ls -la


!!:p                   # print last command
!-2:$:p                # print last word of second last command
!ls:1:p                # print first parameter of most recent command starting with ls
!?perl?^:p             # print first argument of most recent command line containing 'perl'
!!:gs/la/lha/          # substitute all 'la' by 'lha'
!!:gs/la/lha/:p        # substitute all 'la' by 'lha' and print resulting command

Tuning with shopt

Change the behaviour of your bash with shopt

shopt -s histreedit    # re-edit a failed history substitution
shopt -s cdspell       # correct minor spelling errors on cd
shopt -s nocaseglob    # case insensitive globbing (i.e. ls *.pdf)
shopt -s hostcomplete  # complete hostname if word contains @

Using set

set -b                 # report job status immediately


export GLOBIGNORE=".svn:.cvs"       # glob ignore
export FIGNORE=".svn:.cvs"          # pathname completion ignore

fc -l                  # list history
fc  3 5                # fix command 3 to 5 and execute them
alias r='fc -s'        # re-execute last command 
r ls                   # re-execute last command starting with ls
r la=lh ls