Show Menu
Cheatography

Z Shell Basics Cheat Sheet by

The Z Shell Basics cheatsheet is a quick reference for common Unix commands in the Zsh shell. Unix commands are core utilities, while a shell (like Zsh) is an interpreter that runs these commands. Zsh is a popular shell with enhancements over the traditional Bourne Shell (sh) and Bash.

Directory Commands

pwd
Print working directory
mkdir <di­rec­tor­y>
Create a new directory
rmdir <di­rec­tor­y>
Remove an empty directory
cd <di­rec­tor­y>
Change directory
↳ Use < .. > to go up one level, < ~ > for home directory, or < - > for the previous directory.
ls <fl­ag>
List files and direct­ories
 ­ ­ ­ -l
Long format
 ­ ­ ­ -a
All entries
 ­ ­ ­ -h
Human-­rea­dable sizes
 ­ ­ ­ -t
Sort by modifi­cation time
 ­ ­ ­ -r
Reverse order
 ­ ­ ­ -d
List directory (meta)

Finding Files

grep <pa­tte­rn> <fi­le>
Search pattern in a file
find <pa­th> <ex­pre­­ss­ion>
↳ Search for files and direct­ories within a directory hierar­chy:*
 ­ ­ ­ ­-name
(by name)
 ­ ­ ­ ­-type d
(by direct­ories)
 ­ ­ ­ ­-type f
(by files)
locate <fi­len­ame>
Quickly find files by name

Command Help

man <co­mma­nd>
Display the manual page. Press { q } to exit.
<co­mma­nd> --help
Brief help message.
 

File Operations

touch <fi­le>
Create an empty file or update a file’s timestamp
cp <sr­c> <de­st>
Copy files and dirs
↳ Add { -r } to copy direct­ories recurs­ively.
mv <sr­c> <de­st>
Move or rename files/dirs
rm <fi­le>
Remove files
Use with caution! Add < -r > to remove direct­ories and their contents, < -f > to force removal without prompting.
cat <fi­le>
Print file contents to screen
less <fi­le>
View file content page-b­y-page
head <fi­le>
Display the first few lines of a file (default 10)
tail <fi­le>
Display the last few lines of a file (default 10)
Add < -f > to follow the file as it grows.

zsh shortcuts: Navigation

⌃ A
Beginning of line
⌃ E
End of line
⌃ F
Forward one character
⌃ B
Back one character

zsh shortcuts: Deletion

⌃ U
Delete the current line
⌃ K
Delete from cursor to EOL
⎋ + ⌦
Delete one word (backward)
⌃ W
Delete one word (backward)
⌃ D
Delete one char (forward)
FN + ⌦
Delete one char (forward)
⌃ L
Clear the screen
⌘ K
Clear history
⌃ _
Undo the last change

zsh shortcuts: Process and shell

⌃ C
Terminate the running foreground process
⌃ Z
Suspend the running foreground process
⌃ D
Exit current shell (when line is empty)

zsh shortcuts: History

Recall the previous command in history
Recall the next command in history
⌃ R
Search the command history
⌃ G
Escape from command search mode
!!
Execute the last typed command
!pw
Run last command that begins with <pw> (e.g., !cd)
           
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Linux Every Day Commands Cheat Sheet