Radio Telescope Data Center Smithsonian Astrophysical Observatory

Useful shell commands

Basic commands

You can find a separate list of the basic commands here.

Connections

What it doesCommand
Logging onto a CF machine from an RTDC onessh -X user@login.cfa.harvard.edu
ssh -Y user@mars
Run a command (hostname here) on a different machinessh user@host2 hostname
Allow x-windows to be displayed over SSHssh -Y user@host
Append a local file with a remote file over SSHssh user@rtdc7 ''cat myremotefile'' >> mylocalfile
Append a remote file with a local file over SSHcat localfile | ssh user@rtdc8 ''cat >> remotefile''
Keep a process running after you log outscreen [instructions here]

The file system

What it doesCommand
Search the /home/user directory for files ending in .shfind /home/user -name '*sh'
Search the /home/user directory for files bigger than 10GBfind /home/user -size +10G
List all files excluding those ending in .gzls --hide='*gz'
List only items not starting with a numberls -d [^0-9]*
Search for the word 'archive' in all files except those ending in .loggrep archive --exclude="*.log" *

Viewing/manipulating files

What it doesCommand
Find out the format of a file (e.g. ascii/gzip/tar/png)file file1
View two text files side-by-sidediff -y file1 file2
View first 5 lines of a filehead -5 file1
View last 20 lines of a filetail -20 file1
Monitor a file being updated in real time (ctrl-c to exit)tail -f file1.log
Add sequential line numbers to the start of each rownl file1
List contents of a tar or tar.gz filetar -tvf file.tar.gz
Remove adjacent duplicate linessort file1 | uniq
Find lines that dont match between two filesgrep -vFxf file1 file2
Delete any lines that match a pattern. (Use -i.bak to overwrite the original and make a backup)sed -i.bak '/pattern/d' file1
Only keep lines with 29 characterssed -r '/^.{,29}$/d' file1
Sort on column 2 with / as a delimitersort -t/ -k 2 file1
Join multiple pdf files togethergs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=outfile.pdf file1.pdf file2.pdf file3.pdf
Join multiple text files togethercat file1 file2 file3 > newfile