0% found this document useful (0 votes)
79 views17 pages

ZSH Terminal Language Notes/Cheat Sheet

The ZSH Command Guide provides a comprehensive overview of various ZSH commands, organized into sections such as navigation, file operations, process management, and customization. Each command includes its purpose, common options, and examples for practical use. Additionally, it covers ZSH-specific features like globbing, history expansion, and autocompletion.

Uploaded by

devagya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views17 pages

ZSH Terminal Language Notes/Cheat Sheet

The ZSH Command Guide provides a comprehensive overview of various ZSH commands, organized into sections such as navigation, file operations, process management, and customization. Each command includes its purpose, common options, and examples for practical use. Additionally, it covers ZSH-specific features like globbing, history expansion, and autocompletion.

Uploaded by

devagya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

ZSH Command Guide

Table of Contents
1. Basic Navigation and File Operations

2. File Viewing and Editing

3. File Manipulation

4. Permissions and Ownership

5. Process Management

6. System Information

7. Network Commands

8. Package and Software Management

9. Text Processing

10. ZSH-Specific Features

11. Customization and Configuration

Basic Navigation and File Operations


cd - Change Directory
Purpose: Navigate between directories

Common Options:

cd directory_name - Change to specified directory

cd .. - Move up one directory

cd ~ - Go to home directory

cd - - Go to previous directory

Example:

cd ~/Documents/Projects

ZSH Command Guide 1


ls - List Directory Contents
Purpose: Display files and directories

Common Options:

l - Long format with details

a - Show all files (including hidden)

h - Human-readable file sizes

t - Sort by modification time

S - Sort by file size

r - Reverse order

Example:

ls -lah ~/Documents

pwd - Print Working Directory


Purpose: Show current directory location

Example:

pwd

mkdir - Make Directory


Purpose: Create new directories

Common Options:

p - Create parent directories as needed

m - Set file mode/permissions

Example:

mkdir -p Projects/webapp/src

rmdir - Remove Directory

ZSH Command Guide 2


Purpose: Delete empty directories

Example:

rmdir old_project

File Viewing and Editing


cat - Concatenate and Display Files
Purpose: Display file contents

Common Options:

n - Number all output lines

b - Number non-blank output lines

Example:

cat -n ~/.zshrc

less - View File Contents Page by Page


Purpose: View files with pagination

Common Options:

N - Show line numbers

i - Case-insensitive search

S - Chop long lines

Example:

less -N /var/log/system.log

head - Display Beginning of File


Purpose: Show first part of files

Common Options:

ZSH Command Guide 3


nN - Display first N lines

Example:

head -n 20 document.txt

tail - Display End of File


Purpose: Show last part of files

Common Options:

nN - Display last N lines

f - Follow file as it grows

Example:

tail -f -n 50 /var/log/system.log

nano , vim , emacs - Text Editors


Purpose: Edit text files

Example:

nano ~/.zshrc
vim script.sh

File Manipulation
cp - Copy Files and Directories
Purpose: Copy files/directories

Common Options:

r - Copy directories recursively

i - Interactive (prompt before overwrite)

v - Verbose output

ZSH Command Guide 4


p - Preserve file attributes

Example:

cp -rv ~/Documents/Project ~/Backup/

mv - Move or Rename Files/Directories


Purpose: Move or rename files/directories

Common Options:

i - Interactive mode

v - Verbose output

f - Force move

Example:

mv -v oldname.txt newname.txt
mv project_files/ ~/Documents/

rm - Remove Files or Directories


Purpose: Delete files/directories

Common Options:

r - Remove directories and contents recursively

f - Force removal without prompting

i - Interactive mode

Example:

rm -i unnecessary_file.txt
rm -rf old_directory/

touch - Create Empty File or Update Timestamp


Purpose: Create new files or update modification time

ZSH Command Guide 5


Example:

touch newfile.txt
touch -a fileToUpdateAccessTime.log

ln - Create Links Between Files


Purpose: Create hard or symbolic links

Common Options:

s - Create symbolic link

Example:

ln -s /path/to/original/file linkname

Permissions and Ownership


chmod - Change File Permissions
Purpose: Modify file access permissions

Common Options:

+x - Add execute permission

w - Remove write permission

u=rwx - Set user permissions

R - Recursive

Example:

chmod +x script.sh
chmod -R 755 directory/

chown - Change File Owner and Group


Purpose: Change file ownership

Common Options:

ZSH Command Guide 6


R - Recursive

Example:

chown username:groupname file.txt


chown -R username directory/

Process Management
ps - Process Status
Purpose: Display running processes

Common Options:

e - Show all processes

f - Full format listing

u username - User's processes

Example:

ps -ef | grep Chrome

top - Monitor Processes


Purpose: Display and update sorted process information

Example:

top

kill - Terminate Processes


Purpose: Send signals to processes

Common Options:

9 - SIGKILL (force terminate)

15 - SIGTERM (graceful terminate)

ZSH Command Guide 7


Example:

kill -9 1234

jobs , fg , bg - Job Control


Purpose: Manage background and foreground processes

Example:

jobs
fg %1
bg %2

System Information
uname - Print System Information
Purpose: Display system information

Common Options:

a - All information

s - Kernel name

n - Network node hostname

Example:

uname -a

df - Disk Free Space


Purpose: Display free disk space

Common Options:

h - Human-readable sizes

T - Display filesystem type

Example:

ZSH Command Guide 8


df -h

du - Disk Usage
Purpose: Display file/directory space usage

Common Options:

h - Human-readable

s - Summary

c - Grand total

Example:

du -sh ~/Documents/*

free - Memory Usage


Purpose: Display memory usage

Common Options:

h - Human-readable

Example:

free -h

Network Commands
ping - Network Connectivity Test
Purpose: Check network connectivity

Common Options:

c count - Number of packets to send

Example:

ZSH Command Guide 9


ping -c 5 google.com

ifconfig / ip - Network Interface Configuration


Purpose: Display or configure network interfaces

Example:

ifconfig en0

netstat - Network Statistics


Purpose: Display network connections and statistics

Common Options:

a - All connections

n - Numeric addresses

p - Program/PID

Example:

netstat -an | grep LISTEN

ssh - Secure Shell


Purpose: Connect to remote servers

Common Options:

p port - Port number

i identity_file - Identity file

Example:

ssh user@hostname -p 2222

scp - Secure Copy

ZSH Command Guide 10


Purpose: Copy files between hosts

Common Options:

r - Recursive copy

P port - Port number

Example:

scp -r localdir user@remote:/path

Package and Software Management


brew - Homebrew Package Manager
Purpose: Install and manage software packages

Common Options:

install - Install a package

update - Update Homebrew

upgrade - Upgrade packages

list - List installed packages

search - Search for packages

Example:

brew install wget


brew update && brew upgrade

Text Processing
grep - Search Text Patterns
Purpose: Search for patterns in text

Common Options:

i - Case-insensitive

ZSH Command Guide 11


r - Recursive

n - Line numbers

v - Invert match

E - Extended regex

Example:

grep -i "error" logfile.txt


grep -r "function" --include="*.js" ./src

awk - Pattern Scanning and Processing


Purpose: Text processing tool

Example:

awk '{print $1, $3}' data.txt

sed - Stream Editor


Purpose: Edit text in a stream

Common Options:

i - Edit files in-place

Example:

sed 's/old/new/g' file.txt


sed -i '' 's/old/new/g' file.txt # macOS specific

wc - Word Count
Purpose: Count lines, words, characters

Common Options:

l - Lines

w - Words

ZSH Command Guide 12


c - Bytes/characters

Example:

wc -l file.txt

sort - Sort Lines


Purpose: Sort text files

Common Options:

n - Numeric sort

r - Reverse order

k - Sort by field

Example:

sort -n -k2 data.txt

uniq - Report or Filter Repeated Lines


Purpose: Filter duplicate lines

Common Options:

c - Count occurrences

d - Only duplicated lines

u - Only unique lines

Example:

sort file.txt | uniq -c

ZSH-Specific Features
Globbing (Pattern Matching)
Purpose: Advanced file pattern matching

ZSH Command Guide 13


Examples:

# All .txt files


ls *.txt

# All .txt or .log files


ls *.(txt|log)

# Files with numeric names


ls [0-9]*.txt

# All directories
ls -d */

# Case-insensitive glob
ls (#i)*.txt

# Recursive globbing
ls **/*.txt

History Expansion
Purpose: Reuse commands from history

Examples:

# Last command
!!

# Last argument of previous command


!$

# All arguments of previous command


!*

# Command beginning with 'git'


!git

ZSH Command Guide 14


# 10th command in history
!10

# Replace 'foo' with 'bar' in previous command


^foo^bar

Aliases and Functions


Purpose: Create shortcuts for commands

Examples:

# Define alias
alias ll='ls -la'

# Define function
mcd() {
mkdir -p "$1" && cd "$1"
}

Directory Stack
Purpose: Navigate through directory history

Commands:

pushd - Push directory to stack

popd - Pop directory from stack

dirs - Display directory stack

Example:

pushd /var/log
pushd ~/Documents
dirs -v # View stack
popd # Go back to previous directory

Command Substitution

ZSH Command Guide 15


Purpose: Use command output in another command

Examples:

echo "Today is $(date)"


files=$(ls)

Process Substitution
Purpose: Feed command output as file

Example:

diff <(ls dir1) <(ls dir2)

Autocompletion
Purpose: Tab completion for commands and arguments

Example:

# Press Tab after typing partial command/file


git check<TAB> # Complete to 'git checkout'
cd ~/Doc<TAB> # Complete to 'cd ~/Documents/'

Customization and Configuration


Configuration Files
~/.zshrc - Main user configuration file

~/.zshenv - Environment variables

~/.zprofile - Login shell configuration

~/.zlogin - Login shell after .zprofile

~/.zlogout - Logout configuration

Oh My Zsh

ZSH Command Guide 16


Purpose: ZSH customization framework

Installation:

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/


install.sh)"

Theme Configuration:

# Edit ~/.zshrc to set theme


ZSH_THEME="robbyrussell"

Plugin Management:

# Edit ~/.zshrc to add plugins


plugins=(git macos docker)

Useful Environment Variables


Purpose: Configure shell behavior

Examples:

# Set path
export PATH=$HOME/bin:/usr/local/bin:$PATH

# History settings
export HISTSIZE=10000
export HISTFILESIZE=10000
export HISTCONTROL=ignoreboth

# Default editor
export EDITOR='nano'

ZSH Command Guide 17

You might also like