Handy things to know when using bash
A random collection of things that at one time or another caused me misery and despair before I knew them.
- If you somehow manage to create a file whose name starts with a dash, like "
-filename
", it will be interpreted as a command line option. You can delete it withrm -- -filename
- If you want to include an apostrophe in
awk
output, it will be interpreted as the end of the command. Replace it with "\0147
". - If you track things with
git
, and you have files with long lines, thengit diff --word-diff
will be clearer thangit diff
- To get a solar mass symbol in gnuplot, simply set the terminal type to pngcairo and copy this into your plot script: ☉
- If you want to copy multiple files from a remote server using
scp
, enclose the path in quotes, otherwise the local shell tries to interpret the wildcards instead of the remote shell. - Mounting the remote file system in a directory with
sshfs
is way better than usingscp
for that anyway. e.g.:mkdir remotelocation sshfs username@remoteserver: remotelocation mv files remotelocation/directoryonremoteserver/ mv remotelocation/anotherdirectory/anotherfile.dat . fusermount -u -z remotelocation
- If you want to log in to machine
machineB
which is only accessible from machinemachineA
, you can do it in one step withssh -A -t machineA ssh -A -t machineB
- ..and if you wanted to mount
machineB
(in a directory called B):sshfs machineB: B/ -o ssh_command='ssh -A -t machineA ssh -A -t'
- ..and if you want to
rsync
:rsync -arzv -e 'ssh -o "ProxyCommand ssh -A machineA -W %h:%p"' foo/ machineB:./foo/
- To
scp
a file containing colons, give a relative or absolute path to stop the file name being interpreted as a server name.scp awkward:file:name.dat
will not work, butscp ./awkward:file:name.dat
will. - To include a figure with full stops in its filename in a latex document, enclose the file name in curly brackets:
\includegraphics{{filename.with.full.stops}.png}