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
awkoutput, 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-diffwill 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
sshfsis way better than usingscpfor 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
machineBwhich 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
scpa file containing colons, give a relative or absolute path to stop the file name being interpreted as a server name.scp awkward:file:name.datwill not work, butscp ./awkward:file:name.datwill. - 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}