This view lists all the slides from the talk in a continuous format. There is a PDF version available, suitable for printing on A4 paper.
The slides are also designed to be viewed as a slideshow from this
file with Mozilla or a compatible browser. JavaScript is used to make
pressing N
progress to the next slide. The slides fit on
a 1024 × 768 pixel display. To toggle full-screen mode
in Mozilla press F11
.
Ctrl+W
, Meta+BkSpc
, Meta+D
,
Ctrl+K
, Ctrl+U
,
Meta+F
, Meta+B
,
Shift+Ins
,
Ctrl+T
,
Ctrl+]
, Ctrl+Meta+]
For example a long compilation, or an FTP or SSH session, and you need to do something else local too.
The history on disk still has just the original 400 lines, so that’s what gets loaded into the 2nd window.
.bashrc
shopt -s histappend
PROMPT_COMMAND='history -a'
If you’ve configured your terminal windows to run log-in shells then you
might need to use .bash_profile
instead of
.bashrc
. But on many systems
.bash_profile
sources .bashrc
anyway. This also applies to other mentions of .bashrc
in this presentation.
Up
lots (and lots)
Ctrl+R
searches previous lines
Ctrl+R zip Esc
doesn’t find the last
zip
command — it also matches any line that copied,
deleted, unzipped, or did anything else with a zip file!
and a command name
!gv
opens gvim
instead
of gv
Up
Up
so many times
zip Up
goes to the most recent zip
command.
Further presses of Up
cycle through previous zip
commands.
gv Up
goes to the most recent command starting with those
letters. Suppose that found a gvim
command and you were looking for
a gv
command: pressing Space Up
would then go to
the most recent line starting gv␣
.
Up
and Down
Up
and Down
is
configured in .inputrc
"\e[A": history-search-backward "\e[B": history-search-forward
Ctrl+P
and
Ctrl+N
Left
and Right
from
working, fix them like this:
"\e[C": forward-char "\e[D": backward-char
Meta+.
types this
Suppose these commands have been executed:
$ mount /mnt/cdrom $ ls /var/tmp
It is then possible to type the start of the next command line (such as
ls -l
) and simply press Meta+.
to have
/var/tmp
be ‘typed’ for you. Pressing Meta+.
again (without an intervening keystroke) will ‘untype’
/var/tmp
and replace it with /mnt/cdrom
.
Note that on PCs Alt
typically functions as
Meta
, so Alt+.
is what would be pressed. This
applies to all mentions of Meta
in this talk.
!
!:0
is the previous command name!^
, !:2
, !:3
, …,
!$
are the arguments!*
is all the arguments!-2
, !-3
, … are earlier commands
!-2^
, !-2:2
, !-2$
,
!-2*
$ !-2:0 -R !^ !-3:2
Enter
Space
before Enter
if
necessarySuppose you squeeze a png image to use maximum compression:
$ pngcrush pineapple.png crushed_pineapple.png
You can then list the files’ sizes without having to type their names again:
$ ls -lh !*
Then you can rename the new file to the original name (deleting the
uncrushed file in the process). The new name can be ‘typed’ with
Meta+.
, and the original name picked out of a previous
command:
$ mv Meta+. !-2^
Before committing a file to CVS you check over which changes you’ve made. Vim conveniently uses colour to highlight the changes, and using a separate window means that they can be kept on-screen while typing the commit message:
$ cvs diff GBdirect/DocTools/Util.pm | gview -
Then the file can be committed, picking its name out of the previous command line:
$ cvs com !:2
.inputrc
Space
does$if Bash Space: magic-space $endif
For example the MySQL client and the Perl debugger can also use the readline library.
If you (attempt to) view a directory’s contents:
$ ls -l /var/spool/exim/ ls: /var/spool/exim: Permission denied
then to see the permissions of the directory itself, add the
-d
flag:
$ ls -d -l /var/spool/exim/
grep
can search through all files in a directory:
$ grep RewriteCond /usr/share/doc/apache/manual/ grep: /usr/share/doc/apache/manual: Is a directory
But only if you remember the -r
flag:
$ grep -r RewriteCond /usr/share/doc/apache/manual/
Sometimes processes refuse to die:
$ killall xmms
The -9
flag leaves them with little choice:
$ killall -9 xmms
Other places where flags can be added include
ls -tr
, rm -r
, and
chmod -R
.
Meta+O
can be made to load the previous command and
position the cursor for typing an option.inputrc
:
"\M-o": "\C-p\C-a\M-f "
Ctrl+P
: previous lineCtrl+A
: start of lineMeta+F
: forward a word, past the command␣
: insert a spaceCtrl
or Meta
modifiersThe 2 unused keystrokes with Ctrl
are the rather awkward
Ctrl+\
and Ctrl+^
.
But there are 15 letters available for use with Meta
, namely:
Meta+A
, Meta+E
, Meta+G
,
Meta+H
, Meta+I
, Meta+J
,
Meta+K
, Meta+M
, Meta+O
,
Meta+Q
, Meta+S
, Meta+V
,
Meta+W
, Meta+X
, and Meta+Z
.
ls
can be made always to include the -F
flag,
to add symbols marking directory and command names among the list of
filenames.
mkdir
can have the -p
flag so that it is is
possible to create nested subdirectories in one go.
grep
can have the -r
flag so that it will work
on directories. This won’t cause any harm when grep
ing
ordinary files.
Other default flags to consider include scp -pr
,
dirs -v
and jobs -l
.
.bashrc
function ls { command ls -F "$@" }
command
runs the real command"$@"
inserts the user argumentsrm
to include -i
by default
This ll
function produces a long-format directory
listing:
function ll { command ls -Flh "$@" } export -f ll
doc
can be made to change to the specified package’s
documentation directory and display the files therein:
function doc { pushd "/usr/share/doc/$1" && ls } export -f doc
Functions can be created for performing file conversions. For example
this function takes a single XFig file, such as
network.fig
, and produces a PostScript file with the
same basename, such as network.ps
:
function fig2ps { fig2dev -L ps "$1" "${1%.fig}.ps" } export -f fig2ps
function gimp { command gimp "$@" & }
&
every timeThis is useful for pretty much any command which opens a window, including
gv
, mozilla
, acroread
,
xfig
, and ooffice
.
cd -
changes back to the previous directory
pushd
~-
is the previous directory
If you have a tarball in the current directory but you wish to extract it
in a different directory, you can change directory then use ~-
to refer to the directory containing the tarball:
~/downloads/Mozilla/ $ cd /var/tmp /var/tmp $ tar xzf ~-/moz Tab Meta+S Meta+S
Afterwards you can change back to where you were:
/var/tmp $ cd - ~/downloads/Mozilla/ $
.bashrc
:
shopt -s cdspell
Bash will cope with each component of the typed path having one missing character, one extra character, or a pair of characters transposed:
$ cd /vr/lgo/apaache /var/log/apache
$CDPATH
Suppose $CDPATH
contains ~/pending
and
/home/www-data
; you would then be able to change to their
subdirectories from anywhere on the system without typing a full path:
$ cd conference /home/simon/pending/conference $ cd intranet/logs /home/www-data/intranet/logs
If ..
is also in $CDPATH
then you can easily
change to sibling directories. For example, following on from above you
could do:
$ cd docs /home/www-data/intranet/docs
$CDPATH
$CDPATH
in .bashrc
:
CDPATH='.:..:../..:~/links:~:~/projects:/var/www/virtual_hosts'
.
first so can still change directory normally..
for sibling directories../..
for aunties and unclesTab
can be customized in .inputrc
cp ~/ Tab
:
set match-hidden-files off
cp ~/. Tab
will match hidden filesset completion-ignore-case on
/
after
directory names and *
after programs:
set visible-stats on
For example, suppose you want to edit your .bashrc
.
You could start by typing:
$ xemacs ~/.b
Then pressing Tab
yields a list of matching files, and
completes the name as far as possible:
.bash_history .bash_profile .bashrc $ xemacs ~/.bash
Meta+S
will cycle through the completions, so pressing it
once gives:
$ xemacs ~/.bash_history
Tapping it another couple of times completes to the required filename.
.inputrc
Tab
is pressed:
set show-all-if-ambiguous on
Meta+S
cycle through the list:
"\M-s": menu-complete
.bashrc
:
source /etc/bash_completion
When writing a document you often end up with several files with similar names but different extensions:
$ ls Bash_tips.aux Bash_tips.log Bash_tips.pdf Bash_tips.tex
But with programmable completion, Bash will pick the filetype that matches the command and ignore all the others:
$ acroread ba
Pressing Tab
converts the above to:
$ acroread Bash_tips.pdf
If that was the only PDF file in the directory you don’t need to type
any of the filename: just type the command name then press
Tab
and the filename will be inserted. And even if there are a
few PDF files, it still may be quicker not to type any of their names and
just use Meta+S
to cycle through them.
This is useful for any application which only works with a limited group of filetypes. It can also be used to exclude filetypes from commands. For example image and sound files can be excluded from filename completions for text editors.
complete -r cd
Ctrl+D
conveniently exits Bashexport IGNOREEOF=1
$ Ctrl+D $ Use "exit" to leave the shell. $ Ctrl+D $ exit
Up
, and cycling completions with Meta+S