Linux Cheat Sheet

HPC2N,  Umeå University,  Linux Cheat Sheet, 29.10.2015

written by P. Ojeda.

Download as PDF

ls List files in current directory less file See the content of file
ls -lah List files in human readable format vim file Edit file with vim
cd /dir Change to the directory “dir” whereis data Prints out the location of “data”
pwd Your current PATH tar -cvzf file.tgz file Pack an compress “file”
rm file Delete file gunzip file.tgz Uncompress “file.tgz”
rm -rf dir Delete directory tar -xvf file.tar Unpack “file.tar”
* Means zero or any number of characters. Ex. File* could be File, File2, Fileuiwie, ...
? Means only one character. Ex. File? could be File1, Filex, Fileh, but not File22
[] Means a range of characters. Ex. File[1-3] could be File1, File2, File3
grep 'word' file Search for the pattern 'word' in file
grep -rine 'word' home Search for the pattern 'word' recursively in the directory /home
find /home -name '*.dat' Find the files in the directory home ending in '.dat'
find /home -mtime +60 Find every file in /home that was modified more than 60 days ago
| Take the output of one command as the input of another. Ex. ls | grep 'word'
Secure copy protocol
scp file Copy “file” to the home directory of the user “login”
Bash shortcuts vim
ctrl+r Make a reverse search :w file.txt Save file.txt
ctrl+a Go to the beginning of the line :q! Exit without saving
ctrl+e Go to the end of the line :%s/pat1/pat2/g Replace pattern “pat1” by “pat2”
ctrl+w Delete the previous word ctrl+v Start selection
ctrl+k Delete words after cursor dd Delete line
ctrl+u Delete current line x Delete character
ctrl+l Clean terminal r Replace character
awk '/gold/ {print $1}' coins.txt Search for pattern “gold” in the file coins.txt and print first column
Batch jobs
sbatch job.pbs Launch “job.pbs” to the queue
squeue -u login Check the jobs from the user “login"
scancel Remove the job with id “” from the queue
squeue -f Check the details about the job id “”
sshfs /dir1/ /local/dir2 Mount /dir1 (on Quarry) into your /local/dir2
fusermount -u /local/dir2 Unmount the /local/dir2
Updated: 2017-02-24, 23:23