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
machineBwhich is only accessible from machine
machineA, you can do it in one step with
ssh -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 -arzv -e 'ssh -o "ProxyCommand ssh -A machineA -W %h:%p"' foo/ machineB:./foo/
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, but