Skip to content

Instantly share code, notes, and snippets.

@tdyer
Created January 1, 2014 05:35
Show Gist options
  • Save tdyer/8205372 to your computer and use it in GitHub Desktop.
Save tdyer/8205372 to your computer and use it in GitHub Desktop.
Linux and Bash notes.

BASH

(aka Shell, Terminal, Command Line Prompt, Bash Prompt, Bash Shell):

What are the bash commands?

All commands are Unix programs ex: pwd is a program (whose definition lives in a bin directory) see also: Unix philosophy (http://en.wikipedia.org/wiki/Unix_philosophy)

Unix file structure is like a tree.
/ is the root

     / {
         volumes [file 1 ,file 2]
         bin     [cd, ls, man] (the bin is like the dictionary that the terminal looks 
                        in to find out what things mean)
         etc     [passwords, apache, ...]
         user    [me]
        }
Types of files: binary, text

Terminal HotKeys:

  • command-k clears the screen
  • command T = opens new tab in terminal

Useful bash commands:

  • pwd (print working directory)
  • cd (change directory)
    • cd .. (go up one level)
      • NOTE: cd ../../.. means go up 3 levels
    • cd . (current directory)
    • cd / (go directly to root directory)
    • cd (goes to your current logged-in user's home directory)
  • ls (list all the files and folders in the current directory)
    • ls -a (list even the hidden files and folders)
    • ls -al (lists all files in long form.)
      • permissions - # of files - owner - group owner - size in bits - date last
      • modified - name of file
    • ls .. (references one level up)
  • echo (print some arguments or the value of a variable)
    • echo $PATH (show your path variable)
  • history: type history to see entire list or use arrow key up,
    • use !## to execute from history list
  • man (finds the manual page for a command (e.g. "man ls"))
    • type "q" to quit the manual
  • ~ (references home directory (e.g. cd ~, ls ~, ls ~/Code))
  • less (viewing the content of a file from the command line)
  • cat (concatenating. output content, can't scroll through)
    • (works like "print" in ruby)
    • cat blue green > colors (pipes output from first into second as input)
  • subl (open a file in sublime text)
  • nano filename (in-terminal text editor, "hackers-style".)
    • ctrl-o-enter to save
    • ctrl-x to exit
  • mkdir (make a new directory)
    • TRY: mkdir code in the home directory look what you've DUN
  • touch (make a new file)
  • rm (delete file)
    • rm -r (delete directories with files in them. -r means recursively)
    • rm -rf (remove recursively forcefully delete all the things (chainsaw))
  • cp (copy file)
  • mv (move or rename file)
    • (e.g. mv file folder/ (the slash after the directory name says "into this directory"))
  • sudo (do a command as root user)
  • open . (open the current directory in finder)
  • killall finder (closes all open finder windows)
  • wc filename (word count)
  • | (pipe takes the output of the command on the left and puts it as input to the command on the right.)
    • ls -l | wc -l (takes the long-form list of contents and performs word count on it)

Notes:

  • Easily browse through commands you've already typed using the up and down keys
  • permission: read, write, or execute a file
  • tab completion
  • DS.Store file stores the position for your graphic system & where things visually live. (typically hidden)
  • if file begins with a ".", the file is hidden.
  • ./filename.txt (reference a file in the current directory)
  • . = reference self
  • .. = reference parent

Things to come back to:

  • Bash Profile customization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment