Amber Wang
2 min readFeb 9, 2017

Command Line Cheat Sheet

Navigating

1.pwd-print working directory, check which directory I am working on.

2.ls-list of files in this directory

3.man ls-command guidance.

4.q- leave the manual page.

5.”ls *.txt” — check TXT files, *command is a wildcard stands for anything. = anything.txt

6.If I have multiple texts, then ex. “ls *-Canadian.txt” would display them all exclude other files.

7.ls -l, combine with –h, then could use as ls –lh (ls -1, list in finder, ls –h, lists and information)

8.cd- change directory command, ex. “cd desktop”, then commands to apply all documents on desktop.

9.cd .. — moves up one directory.

10. cd — moves back to the home directory

11. Navigating ex. “ cd /users/name/documents” to locate, then type “open” file name to open it.

Interacting with files

1. Ex. Navigate at the file, then use “mkdir ProgHist-Text”, to create a new directory.

2. Ex. “cd prog” then hit tab to autofill entire name

3. “Open” last few words.txt, within the terminal, use “cat” last few words.txt, “head” first ten lines “tail” last ten lines. “head -20” first 20 lines.

4. Ex. “mv pg2600.txt tolstoy.txt” change file name

5. Duplication ex. “cp tolstoy.txt tolstoy2.txt”

6. Combination, ex. “cat tolstoy.txt tolstoy2.txt”, then “cat tolstoy.txt tolstoy2.txt > tolstoy-twice.txt”, more, “cat *.txt > everything-together.txt”

Editing text file

1. “vim tolstoy.txt”

2. Control B move up a pg, control F down

3. “a” to insert, “esc” to read.

4. “: w” write the file, “:q” quit “:wq”, w/out saving“:q!”

Moving, copying, deleting files

1. Backup first “cp”

2. Copy to another file ex. “cp /users/ianmilligan1/desktop/proghist-text/tolstoy.txt /users/ianmilligan1/desktop/proghist-dest/”

3. Move, “mv”, copy all text “cp, *.txt”

4. To different directory ex. “cp *.txt /users/ianmilligan1/desktop/proghist-dest/”

5. copy to current directory ex. “cp /users/ianmilligan1/desktop/proghist-text/*.txt ./” “./”= current directory.

6. Delete, “rm”, delete an entire empty directory, “rmdir”, delete w/ files, ex. “rm –r proghist-text”, no recycle bin.

7. “exit”