Unix Commands Cheat Sheet 2017

Unix (often confused with Linux) is one of the most popular operating systems in the world. There are thousands of computers running some shape or form of Unix.

According to the Unix Philosophy, originated by Ken Thompson, documented by Doug McIlroy, and later summarized by Peter H. Salus, a developer should:

  1. Write programs that do one thing and do it well.

  2. Expect the output of every program to become the input to another. Programs should work well with other programs.

  3. Prototype new software before polishing it.

  4. Utilize tools rather than unskilled help to lighten a programming task, even if it means having to detour to build the tools and expect to throw some of them out when finished.

Top 21 frequently used commands in Unix

  1. ls [options] [filename]
    • Lists the files in a directory
    • -l: Use a long listing format
    • -a: Include entries starting with dot “.”
    • -t: Sort by modification time
    • -S: Sort by file size
  2. cd dirname
    • Changes into specified directory
  3. cp path/to/filename new/path/to/filename
    • Copies a file or directory from its current path to its destination path
  4. mv ~/Downloads/foo.md ~/Desktop/bar.md
    • Moves (and / or renames) a file or directory
  5. cat filename
    • Takes a file a prints it to the terminal
  6. rm filename
    • Removes a file
  7. rm -rf dirname
    • Removes a directory recursively
  8. which filename
    • Returns file path to the executable (or alias or shell function) that gets called when the command is executed when entered in the shell prompt
  9. touch filename
    • Updates the access date and / or modification date of a file or directory. In its default usage, it is the equivalent of creating or opening a file and saving it without any change to the file contents
  10. echo args
    • Writes its arguments to standard output
  11. tar -xvf filename.tar
    • Verbosely extracts tar archive filename.tar
  12. tar -xzf filename.tar.gz
    • Extracts a gzipped tar archive with the name filename.tar.gz
  13. tar -cjf filename.tar.bz2 dirname/
    • Creates a bzipped tar archive of the directory dirname and calls it filename.tar.bz2
  14. tar -xjf filename.tar.bz2 -C dirname/
    • Extracts bzipped tar archive filename.tar.bz2 after changing directory to dirname
  15. tar -xzf filename.tar.gz foo.txt
    • Extracts text file foo.txt from gzipped tar archive filename.tar.gz
  16. chmod +x
    • Changes file access permissions and makes it executable for all users
  17. chmod 600 filename
    • Changes file access permissions and makes it writable or readable only for its owner
  18. chmod 700 dirname
    • Changes directory access permissions and makes it so that only the file owner can read, write, or open it
  19. vim filename
    • Opens filename in a text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text. It is especially useful for editing programs.
    • Features multi level undo, multi windows and buffers, syntax highlighting, command line editing, filename completion, on-line help, visual selection, etc.
  20. nslookup domainname
    • Allows user to query Internet name servers interactively
    • Displays the “A Record” (IP Address) of the domain
  21. curl [optionsurl
    • Transfers data from or to a server, using one of the
      supported protocols (HTTP, HTTPS, FTP, FTPS, GOPHER, DICT, TELNET, LDAP
      or FILE)
    • -i: Includes the HTTP-header in the output (server-name, date of the document, HTTP-version, etc)
    • -k: Explicitly allows curl to perform “insecure” SSL connections and transfers
    • -v: Makes the output verbose (mainly for debugging)

There are many more commands to go, make sure to checkout the Linux Man Pages and Wikipedia to learn the others.

If you enjoyed this blog post or found it helpful in any way, make sure to follow me on Twitter to find out when a new one is available.

Twitter: @giovanni0918
Github: giovanni0918
Website: giovanni-orlando.com


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s