Bash and Linux command line
BASH (or Bourne against Shell) is the basic command line interpteter for the UNIX-based operation systems (Like MacOS, or Linux). Most of the apps and scripts used in the lab are based on Bash.
The University of Toronto Coders have a great tutorial lesson where they cover basic aspects of interacting with computer and file system using BASH.
Shell-command cheat sheet
Here you can find the most frequently used BASH commands.
Shell command | action |
---|---|
pwd | present working directory |
ls [dir] | list the directory contents |
mkdir dir | create a directory |
cd [dir] | change directory |
man cmd | command’s man page |
echo arg | echo the argument |
source file | run the cmds in file |
cp file1 file2 | copy a file |
mv file1 file2 | move/rename a file |
rm file | delete a file |
wc file | word count data of file |
grep arg file | search for arg in file |
rmdir dir | delete a directory |
history [num] | print the shell history |
file file | type of file |
more file | scroll through file |
less file | scroll through file |
cat file | print the file contents |
cmd > file | redirect output to file |
cmd » file | append output to file |
cmd < file | use file as input to cmd |
head file | print first 10 lines of file |
tail file | print last 10 lines of file |
curl url | downloads the url |
tar file | handles tar files |
sort file | sorts the lines of file |
cut flags output | cut part of output |
for..do..done | for loop in bash |
if..then..fi | if statement in bash |
tail -f filename | tail the log file (useful for the sbatch cluster jobs) |
logout | close the terminal session |