Unix Command Cheatsheet

  • cd change directory
    • cd <directory> changes to directory
    • cd .. parent directory
    • cd ../.. two directories up
  • ~ alias to home directory
  • touch updates or changes file modification time. Creates file if it doesn’t exist.
    • touch -c <file> prevents creation of file only updates
  • ls – list contents of the current directory
    • ls -la shows hidden files too
    • ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) \
      *2^(8-i));if(k)printf("%0o ",k);print}'
      -lists contents with permissions in octal format
  • pwd show the current (working) directory’s path
  • cp copy
  • scp secure copy
  • cat output file contents
  • gzip – a compression program
  • gunzip – a decompression program
  • find – search for files
  • mysql – connect to a MySQL server
  • mysqldump – “dump” from a MySQL server
  • | “pipe” output to another program
  • > output to a file
  • < input from a file
  • grep regular expressions
  • rm remove / delete (be careful on this one)
  • <command> --help many programs have a built-in “help” to show you basic usage information
  • man <command> “manual” program to show information on how to use a command
  • chmod 755 <file> gives full permissions to a file
  • host myip.opendns.com resolver1.opendns.com – returns your current IP address
  • nano ~/.bash_profile to edit the .bash_profile
  • source ~/.bash_profileto save changes

This is a conglomeration of several online cheatsheets, the origins of which are noted in the resources section below. It also includes my own notes, any of this is open for discussion. Please feel free to correct any wrong information or to include any which are vital but may have been overlooked.

Leave a Reply

Your email address will not be published. Required fields are marked *

Click to view allowed tags

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>