The Wizard's
Command Line Cheat Sheet
Moving Among Directories
cd [folder] Change your current directory to another directorycd ~ or just cd to move to your Home Directory type cd and the symbol that is called tilde
cd / or just / to move to the root directory
cd .. to go to the parent of your current folder
cd - or just - toggles back and forth between your current directory and the last directory you were in
- cd -[tab key]: will display a numbered list of all your recently visited directories and you can then type to go there (zsh only)
- cdh: cd history does the same as the above command in the Fish Shell (fish only)
cd ../.. to move up two levels
cd ../../.. to jump up three levels from your current location
prevd (Alt+left arrow): takes you to the previous directory (fish only) use cd - or just - in zsh
nextd (Alt+right arrow): takes you to the next directory (fish only) use cd - or just - in zsh
dirh: shows a list of the recently visited directories (fish only) in zsh use dirs -v type cd -2 to jump to 2 on the list
cdh: allows you to quickly jump to any recently visited directory using letter or number shortcuts (fish only)
d: to see a quick list of recent directories and choose one by its number (zsh only)
Working With Files
- rm: Remove/delete a file permanently
- rm -r DeadFolder remove/delete a directory/folder and all of its contents (files and sub-directories) permenatly
- mv: Moves a file/Folder from one location to another; also renames files (oldname newname)
- ls: Lists files in current Directory; ls -l long listls -la show dot files
- pwd | pbcopy: pwd prints your current directory path, and the pipe (|) sends that text straight to your clipboard instead of printing it on the screen
- realpath filename.ext | pbcopy: copy the full, absolute path of a file in the current folder to your clipboard
- pbpaste: Echos on the Terminal screen whatever is on your clipboard
- pbpaste > file.txt: Writes whatever is on your clipboard onto the file even creates if it doesn't exist
- pbpaste >> file.txt: Writes whatever is on your clipboard beneath what is already there
- ls -la ~/.Trash: Lists content of your Trash Folder
- find ~ -name "your-file-name.jpg": Finds a file and echos its path
- cat filename.txt: Echos content of specified file
- cal: Echos the current month's calendar
While all of these Commands will work in the Fish Shell some but not all will work in other shells as well
- mkdir Data Makes a new, empty folder/directory named Data
- touch dog.txt Creates a new empty file named dog.txt
- pwd prints the path of the directory you are currently in
- ls lists all files in the current directory/folder
- ls -a list all files including hidden files
- ls -l long listing of all files showing owner, size and time last edited
- ls -R Recursive: Lists everything in the current folder and all subfolders
- ls .. list the contents of the parent directory one level above
- mv oldname.txt newname.txt renames files
- rm filename.txt (remove) permanetly deletes files (caution there be dragons) there is no cmd + Z or undo
- cat AnyFile.txt prints out the entire text of the file
- head AnyFile.txt prints the first 10 lines of specified file
- tail AnyFile.txt prints the last 10 lines of specified file
- echo "Arf! Arf!" > dog.txt replaces any existing text with Arf Arf
- echo "Arf! Arf! Arf!" >> dog.txt adds text below existing text on dog.txt
- cp copies files or folders from one location to another
- say "Everything not forbidden is compulsory" hear your machine speak to you
- say -f filename.txt Reads the contents of a specific text file aloud
- history lists a history of your last 16 (in ZSH/macOS) commands
- history 5 lists your last 5 commands (specify any number you want) and you can use your up arrow to bring them to the command prompt
- open -a "Sublime Text" dog.txt will open the file in Sublime Text (substitute your code editor) if it is installed on your machine
- Command + l Clears the console's screen and maintains your terminal's scrollback history
- Command + k Clears the console's screen and deletes your terminal's scrollback history
- Control + z to pause a process and put it in the background; you can resume it later with the fg command
Aliases Variables and Functions
To create an alias shortcut to your Downloads folder in zsh write this alias down="cd ~/Downloads" in vim ~/.zshrc
To create a variable to the same folder write this export down=~/Downloads in zsh config running vim ~/.zshrc in the Terminal
To create a variable in Fish type this at the prompt set -Ux downloads ~/Downloads
For Fish function type function downloads hit Enter then cd ~/Downloads hit Enter then end Enter and finally type funcsave downloads Enter
- © Scoroncocolo
- Design: ScoroncocoloDesign