Terminal commands study guide — Joaquin Jimenez
Shows the full path of your current directory. Think of it as "Where am I right now?"
$ pwd
/home/joaquin/projects
Navigate between directories. The most fundamental navigation command.
cd /home/joaquin # Go to absolute path
cd projects # Go to subdirectory
cd .. # Go up one level
cd ~ # Go to home directory
cd - # Go to previous directory
cd # Also goes to home
Lists files and directories. One of the most frequently used commands.
ls # List current directory
ls -l # Long format with details
ls -la # Include hidden files
ls -lh # Human-readable sizes
ls *.js # List only .js files
Creates a new empty file, or updates the timestamp of an existing file.
touch newfile.txt # Create new file
touch file1.js file2.js # Create multiple
touch existing.txt # Update timestamp
Creates new directories (folders).
mkdir projects # Create directory
mkdir -p parent/child/grandchild # Create nested dirs
mkdir dir1 dir2 dir3 # Create multiple
Copies files or directories from one location to another.
cp file.txt backup.txt # Copy file
cp file.txt /path/to/dir/ # Copy to directory
cp -r folder/ newfolder/ # Copy directory recursively
cp *.js backup/ # Copy all .js files
Moves files to a different location OR renames them. Same command for both!
mv old.txt new.txt # Rename file
mv file.txt /path/to/dir/ # Move to directory
mv folder/ /new/location/ # Move directory
mv *.js src/ # Move multiple files
⚠️ Permanently deletes files and directories. No trash can! Be careful.
rm file.txt # Delete file
rm -r folder/ # Delete directory and contents
rm -i *.txt # Interactive delete
rm -rf node_modules/ # Force delete (careful!)
Removes empty directories only. Safer than rm -r since it won't delete if there's content.
rmdir empty_folder # Remove empty dir
rmdir -p a/b/c # Remove nested empty dirs
Outputs the entire contents of a file. Best for small files. Can also concatenate multiple files.
cat file.txt # Display file
cat file1.txt file2.txt # Display multiple
cat -n file.txt # With line numbers
cat file.txt > new.txt # Copy via redirect
View files one screen at a time. Better than cat for large files. Navigate with arrow keys, search with /.
Space or f # Next page
b # Previous page
/pattern # Search forward
n # Next search result
g # Go to beginning
G # Go to end
q # Quit
Shows the first N lines of a file. Default is 10 lines.
head file.txt # First 10 lines
head -n 20 file.txt # First 20 lines
head -5 file.txt # Shorthand for -n 5
Shows the last N lines of a file. Great for logs! The -f flag watches for changes in real-time.
tail file.txt # Last 10 lines
tail -n 20 file.txt # Last 20 lines
tail -f server.log # Follow log in real-time!
Searches for text patterns in files. Incredibly powerful for finding things. Supports regex.
grep "error" log.txt # Find "error" in file
grep -i "error" log.txt # Case insensitive
grep -r "TODO" . # Recursive search in dir
grep -n "function" *.js # Show line numbers
cat file | grep "pattern" # Pipe from another command
Searches for files and directories by name, type, size, date, and more. Very powerful.
find . -name "*.js" # Find .js files
find . -type d -name "src" # Find directories named src
find . -type f -mtime -7 # Files modified in last 7 days
find . -size +100M # Files larger than 100MB
find . -name "*.log" -delete # Find and delete
Counts lines, words, and characters in files. Great with pipes.
wc file.txt # lines, words, chars
wc -l file.txt # Line count only
ls | wc -l # Count files in directory
cat file.txt | wc -w # Word count
Shows the current logged-in username. Simple but handy.
$ whoami
joaquin
Shows disk space usage for mounted filesystems.
df # All filesystems
df -h # Human-readable (GB, MB)
df -h /home # Specific partition
Shows how much disk space directories and files use.
du -sh * # Size of each item in current dir
du -h --max-depth=1 # One level deep
du -sh node_modules # Size of specific folder
Real-time view of running processes, CPU, and memory usage. htop is a prettier version.
q # Quit
k # Kill process
/ # Search (htop)
F6 # Sort by column (htop)
Shows running processes. Unlike top, it's a snapshot (not live).
ps # Current terminal processes
ps aux # All processes, detailed
ps aux | grep node # Find node processes
Sends signals to processes. Most commonly used to stop/kill them.
kill 1234 # Graceful terminate (SIGTERM)
kill -9 1234 # Force kill (SIGKILL)
killall node # Kill all node processes
Shows previously executed commands. Use !number to re-run a command.
history # All history
history 20 # Last 20 commands
!123 # Re-run command #123
!! # Re-run last command
history | grep git # Find git commands
Clears the terminal screen. Same as Ctrl+L shortcut.
Changes read (r), write (w), execute (x) permissions for owner, group, others.
chmod +x script.sh # Add execute permission
chmod 755 script.sh # rwxr-xr-x
chmod 644 file.txt # rw-r--r--
chmod -R 755 folder/ # Recursive
Changes the owner and/or group of files. Usually requires sudo.
sudo chown joaquin file.txt # Change owner
sudo chown joaquin:staff file.txt # Owner and group
sudo chown -R joaquin folder/ # Recursive
Runs a command with administrator/root privileges. Use carefully!
sudo apt update # System update
sudo rm /etc/config # Delete system file
sudo -i # Interactive root shell
Transfers data to/from servers. Great for APIs, downloading files, testing endpoints.
curl https://api.example.com # GET request
curl -o file.zip URL # Download file
curl -X POST -d '{"key":"val"}' URL # POST JSON
curl -I URL # Headers only
Downloads files from the web. Simpler than curl for basic downloads.
wget https://example.com/file.zip # Download
wget -O custom.zip URL # Custom filename
wget -c URL # Resume interrupted download
Tests if a host is reachable. Shows response time.
ping google.com # Ping until Ctrl+C
ping -c 5 google.com # Ping 5 times
Connects to remote servers securely. Essential for server management.
ssh user@192.168.1.1 # Connect to server
ssh -i key.pem user@host # With key file
ssh -p 2222 user@host # Custom port
Copies files between local and remote machines over SSH.
scp file.txt user@host:/path/ # Upload
scp user@host:/path/file.txt . # Download
scp -r folder/ user@host:/path/ # Copy directory
Installs, updates, and removes software packages on Debian-based systems.
sudo apt update # Update package list
sudo apt upgrade # Upgrade all packages
sudo apt install nginx # Install package
sudo apt remove nginx # Remove package
apt search keyword # Search packages
The missing package manager for macOS. Install almost anything.
brew update # Update Homebrew
brew install node # Install package
brew upgrade # Upgrade all
brew list # List installed
brew search python # Search
Manages JavaScript/Node.js packages and dependencies.
npm init # Initialize new project
npm install express # Install package
npm install # Install from package.json
npm install -g nodemon # Install globally
npm run start # Run script from package.json
npm update # Update packages
Installs Python packages from PyPI.
pip install requests # Install package
pip install -r requirements.txt # From file
pip list # List installed
pip freeze > requirements.txt # Export deps
pip uninstall package # Remove
Creates a new Git repository in the current directory.
Downloads a repository from a URL.
git clone https://github.com/user/repo.git
git clone git@github.com:user/repo.git # SSH
Shows which files are modified, staged, or untracked.
Stages changes for the next commit.
git add file.js # Stage specific file
git add . # Stage all changes
git add -A # Stage all including deletions
Saves staged changes with a message.
git commit -m "Add login feature"
git commit -am "Quick fix" # Add + commit tracked files
Uploads local commits to a remote repository.
git push origin main
git push -u origin main # Set upstream
git push # If upstream is set
Downloads and merges changes from remote.
git pull origin main
git pull # From tracked branch
Lists, creates, or deletes branches.
git branch # List branches
git branch feature # Create branch
git branch -d feature # Delete branch
git branch -a # List all (incl. remote)
Switches between branches. git switch is the newer command.
git checkout main # Switch to main
git checkout -b feature # Create and switch
git switch main # Modern syntax
git switch -c feature # Create and switch
Merges another branch into your current branch.
git checkout main
git merge feature # Merge feature into main
Shows commit history.
git log # Full history
git log --oneline # Compact view
git log -5 # Last 5 commits
git log --graph # Visual branches
Saves uncommitted changes to a stack. Great for switching branches without committing.
git stash # Save changes
git stash pop # Restore and remove from stash
git stash list # List stashes
git stash drop # Delete top stash
Sends the output of one command as input to another. Chain commands together!
ls -la | grep ".js" # Filter ls output
cat file.txt | wc -l # Count lines
ps aux | grep node # Find node processes
history | tail -20 # Last 20 commands
> overwrites file, >> appends to file.
echo "Hello" > file.txt # Overwrite
echo "World" >> file.txt # Append
ls -la > listing.txt # Save ls output
cat file.txt >> backup.txt # Append file
Uses a file as input for a command instead of typing.
wc -l < file.txt # Count lines from file
sort < unsorted.txt > sorted.txt # Sort file
2> redirects errors only. &> redirects both output and errors.
command 2> errors.log # Errors to file
command &> all.log # All output to file
command 2>/dev/null # Discard errors
Outputs text to the terminal. Also used to display environment variables.
echo "Hello World"
echo $HOME # Print home directory
echo $PATH # Print PATH variable
echo "Value: $VAR" # Variable in string
Sets environment variables for the current session and child processes.
export API_KEY="abc123"
export PATH="$PATH:/new/path" # Add to PATH
export NODE_ENV=production
Lists all environment variables.
env # List all
env | grep PATH # Find PATH
printenv HOME # Print specific variable
Runs a script in the current shell (not a subshell). Changes persist.
source ~/.bashrc # Reload bash config
source .env # Load environment file
. ~/.zshrc # Shorthand for source
Creates shortcuts for commands. Add to ~/.bashrc or ~/.zshrc to persist.
alias ll='ls -la'
alias gs='git status'
alias ..='cd ..'
alias python=python3