Intro to the Command Line

Who Am I?

Getting Started

OS X

Open /Applications/Utilities/Terminal

Keep in Dock for easy access.

Optionally, download and use iTerm 2

Unix

Search applications for Terminal

Keep in Launcher, if you have one, for easy access

Windows

Download Console 2

Extract Console.exe

Add Console.exe shortcut to Desktop

Open Console.exe, go to Edit->Settings and set the shell to PowerShell (C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe)

Set the Startup dir to your User directory

Restart Console.exe

Getting Help

Manual

man {command}: Opens manual page for command. Move up/down with arrow keys, press q to quit

Manual Command Manual

Looking Around

Listing What's Visible

ls: List all non-hidden files/folders

List Visible

Listing Everything

ls -a: List all files/folders

List All

Listing With Details

ls -l: Details list of available files/folders

Can be combined with -a

List with Details

Moving Around

Current Path

pwd: Displays your current path.

Display Current Path

Changing Directory

cd: Changes directory to entered directory (case sensitive)

Folders with spaces in name need to escape space: foo\ bar

Change Directory

Current Directory

.: Starts at the current directory

Start Here

Moving Backward

..: Steps back a directory

Move Backward

User Directory

~: Start at your user directory

Start at User Directory

Files and Folders

Creating Folders

mkdir {folder-name}: Makes a folder.

Folders with spaces in name need to escape space: foo\ bar

Make Directory

Removing Empty Folders

rmdir {folder-name}: Removes an empty directory

Remove Directory

Creating Files

touch {file-name} (Windows: New-Item {file-name} -type file: Will check to see if a file exists and, if it doesn't, create it

Touch

Reading and Writing To Files

echo "{content}" >: Will write content to a file

cat: Will preview content in a file

Reading/Writing Files

Moving and Renaming Files

mv: Moves a file. Can rename while moving by changing file extension

Move/Rename Files

Removing Files

rm: Deletes file (does not move to trash, cannot undo)

Remove

Removing Full Folders

rm -r: Deletes a not-empty directory (does not move to trash, cannot undo)

Recursively Remove

Opening Files and Folders

  • OS X: open {file-or-folder}
  • Linux: nautilus {file-or-folder}
  • Windows: ii {file-or-folder}

Opens a file or folder. Opening . will open the current directory

Open

Searching

Finding Files and Folders

find {file-name} (Windows: Get-ChildItem {file-name}: Finds files and folders. Use -type for specific types and -name for the name of files on non-Windows systems.

Find

Finding Content

grep "{search-term}" (Windows: select-string .\*.* -pattern "{search-term}": Find content inside of files. Use -n for line numbers, -r to search recursively

clear

Grep

Combining Searches

|: Pipe. Generic way of passing the results from one command to another

Piping

Thank You

Slides available at

http://snugug.github.io/Intro-Command-Line