Skip to content

Instantly share code, notes, and snippets.

Last active May 18, 2019
What would you like to do?
Unix Cheetsheet! These cheat sheets are the most command and practises I need to work more on them to remember them. There isn't everything here included because I know most of the simple ones.


  • ctrl+a — move cursor to beginning of line
  • ctrl+e — move cursor to end of line
  • ctrl+u — clear to beginning of line
  • ctrl+k — clear to end of line


  • cp -r dir1 dir - copy directory dir1 to dir2
  • ln -s file link — create soft symbolic link to file (soft)
  • ln file link — create hard symbolic link to file (hard)
  • less file — view file with page navigation
  • head file — output the first 10 lines of file
  • tail file — output the last 10 lines of file
  • tail -f file — output the contents of file as it grows


  • shutdown — shut down machine
  • reboot — restart machine
  • df — show disk usage
  • du — show directory space usage


  • grep pattern files — search for pattern in files
  • grep -r pattern dir — search recursively for pattern in dir
  • grep -rn pattern dir — search recursively for pattern in dir and show the line number found
  • grep -r pattern dir --include='*.ext — search recursively for pattern in dir and only search in files with .ext extension
  • grep -E pattern files — search for pattern using Extended regexp in files
  • command | grep pattern — search for pattern in the output of command
  • find file* — find all instances of file in real system
  • find . -iname 'string*' - find file case insensitive with a pattern
  • find -L . -iname '*.js' -exec chmod 744 {} \; - find js files and change mode to 644 within this directory
  • find /var/log/ -iname '*.tmp' -delete - find .tmp files within that directory and delete them
  • locate file — find all instances of file using indexed database built from the updatedb command. Much faster than find
  • sed -i 's/day/night/g' file — find all occurrences of day in a file and replace them with night - s means substitude and g means global - sed also supports regular expressions
  • sed -i -- 's/old/new/g' */**(.D) find and replace old string with new string withing this folder and all its subfolder


  • ps — display your currently active processes
  • top — display all running processes
  • kill pid — kill process id pid
  • kill -9 pid — force kill process id pid


  • scp user@host:file dir — secure copy a file from remote server to the dir directory on your machine
  • scp file user@host:dir — secure copy a file from your machine to the dir directory on a remote server
  • scp -r user@host:dir dir — secure copy the directory dir from remote server to the directory dir on your machine
  • ssh -p port user@host — connect to host on port as user
  • ssh-copy-id user@host — add your key to host for user to enable a keyed or passwordless login
  • ping host — ping host and output results
  • whois domain — get information for domain
  • dig domain — get DNS information for domain
  • dig -x host — reverse lookup host
  • lsof -i tcp:1337 — list all processes running on port 1337


  • tar cvzf file.tar.gz files — create a tar with Gzip compression
  • tar cafxz file.tar.gz — extract a tar using Gzip


  • chmod ugo file — change permissions of file to ugo - u is the user's permissions, g is the group's permissions, and o is everyone else's permissions. The values of u, g, and o can be any number between 0 and 7.
  • x = 1
  • w = 2
  • r = 4
  • u = user
  • g = group
  • o = other


  • u+rwx
  • g=r
  • 0-rwx
  • 777 = a+rwx


  • sudo adduser username - will add user and then you'll need to enter password
  • su username - switch user
  • passwd - updates the password
  • chsh - changes the shell
  • chfn - update user information
  • usermod - update user settings like their username and home directory
  • deluser - deletes users


  • YOUR COMMAND & - start the task in the background
  • bg %1 - send job to the background
  • fg %1 - bring job to the forground
  • CTRL + z - in vim suspends the text editor and jumps out, you then have to type fg %1 to get back to it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment