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 with
rm -- -filename
- If you want to include an apostrophe in
awkoutput, it will be interpreted as the end of the command. Replace it with "
- If you track things with
git, and you have files with long lines, then
git diff --word-diffwill be clearer than
- 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 using
scpfor 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 B which is only accessible from machine A, you can do it in one step with
ssh -A -t A ssh -A -t B
- And if you wanted to mount B (in a directory called B):
sshfs B: B/ -o ssh_command='ssh -A -t A ssh -A -t'
- and if you want to
rsync -arzv -e 'ssh -o "ProxyCommand ssh -A A -W %h:%p"' foo/ B:./foo/