Skip to content

Instantly share code, notes, and snippets.

@conleec
Last active June 7, 2016 04:18
Show Gist options
  • Save conleec/4a7d03f408d876407af1338733544892 to your computer and use it in GitHub Desktop.
Save conleec/4a7d03f408d876407af1338733544892 to your computer and use it in GitHub Desktop.
Misc Notes on Mac Command Line Usage
@conleec
Copy link
Author

conleec commented Jun 3, 2016

Navigating in the Terminal

  • Up / Down arrows will step back thru previous commands
  • Cmnd A: Start of the line
  • Cmnd E: End of line
  • Option click: moves to point where you clicked
  • Tab: auto completes what you're typing
  • Tab/Tab: shows a list of possible auto corrections

Command Structure

command options arguments

Command is ALWAYS a single word

Options usually a single dash followed by a letter
or two dashes followed by a keyword

  • ruby -v
  • ruby --version

Multiple options can be specified seperately or smashed together like so:

  • ls -l -h -a
  • ls -lha

You can have multiple commands on a line, separated by a semi-colon.

Unix Manual Pages

Lynda Tutorial Link

man command will jump to the manual page.
spacebar will go to the next page
f/b will go forward or backward
q will quit, once the end of the document (or manual) is reached

Unix Filesystem

cd ~ will take us to our home director
cd .. will step us out to our parent directory
cd - toggles between current and most recent directory

unixfilesystem

macfilesystem

## Unix File Naming - maximum 255 characters - use A-Z, a-z, 0-9, period, underscore, hyphen - case sensitive (Mac OS differs) - if you use spaces - \ escape before spaces, when referencing **or** - quotes around name with spaces - better to use underscore than spaces - best practice is to use filename extensions ## Creating Files

touch <filename> will update access time if file exists, otherwise it will create the file.

nano is a built-in Unix text editor.

Reading Files

cat <filename> concatenates files, but will display a single file

  • problem is, it displays entire file at once

more <filename> displays page at a time, but can't go back

less <filename> displays page by page and allows user to page forward and backward.

  • f/b page forward and backward
  • g goes to START of document
  • G goes to END of document
  • -M option provides better promp with % remaining

head displays from head of a file
tail displays from end of file

Making Directories

mkdir <dir_name>

Moving and Renaming Files

mv used to move and rename files

MV Options

  • -n No Overwriting
  • -f Force Overwriting
    • Turned ON by default!! VERY IMPORTANT!
  • -i Interactive Overwriting or "ask me"
  • -v Verbose mode

Copying Files

cp is COPY

  • -R is a recursive copy (ie, will copy down into a directory)
  • like mv forced overwrite is the DEFAULT. BEWARE

Removing Files

rm and rmdir are the two options for removing files and directories respectively

  • rm removes files only
  • rm -R removes recursively. WARNING!!
  • rmdir only removes empty directories

Searching for Files and Folders

find path expression

Wildcard expressions

  • * Zero or more characters (glob)
  • ? Any one character
  • [] Any character in the brackets

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