home

πŸ’» Terminal Basics: Most Popular Bash/Zsh Commands

Whether you’re using Bash (default in many Linux distros) or Zsh (default on macOS), mastering a few terminal commands can greatly boost your productivity.

This guide covers essential shell commands for file management, navigation, system info, searching, and more.


πŸ“ File and Directory Management

ls – List Directory Contents

ls         # List files and folders
ls -la     # List all, with details (hidden files too)

cd – Change Directory

cd folder-name     # Go into a folder
cd ..              # Go back one level
cd ~               # Go to home directory

pwd – Print Working Directory

pwd        # Shows the current path

mkdir – Make Directory

mkdir my-folder

touch – Create a New File

touch file.txt

cp – Copy Files or Folders

cp file.txt copy.txt          # Copy a file
cp -r dir1 dir2               # Copy a folder recursively

mv – Move or Rename Files

mv old.txt new.txt            # Rename a file
mv file.txt ~/Documents       # Move file to Documents

rm – Remove Files or Folders

rm file.txt                   # Delete a file
rm -r folder-name             # Delete a folder recursively

⚠️ Caution: There’s no trash/recycle bin in the terminal.


πŸ” Searching and Finding

find – Locate Files

find . -name "*.js"           # Find all `.js` files in current directory

grep – Search Inside Files

grep "function" file.js       # Find lines containing "function"
grep -r "TODO" .              # Search recursively

🧭 Navigation and Info

history – Show Command History

history                       # View previous commands

clear – Clear Terminal Screen

clear

man – Manual Pages (Help)

man ls                        # Show manual for `ls`

Press q to quit the manual page.


πŸ“¦ Package Managers (macOS/Linux)

brew (Homebrew for macOS)

brew install node             # Install a package
brew list                     # List installed packages

apt (Debian/Ubuntu)

sudo apt update               # Update package lists
sudo apt install git          # Install a package

βš™οΈ System Commands

top or htop – Process Viewer

top                           # Show system processes (press `q` to quit)

whoami – Show Current User

whoami

uname – Show System Info

uname -a                      # All system info

πŸ“‚ Path Shortcuts

Shortcut Meaning
. Current directory
.. Parent directory
~ Home directory
/ Root directory

🧰 Bonus Tips


πŸ§ͺ Practice Challenge

Try this:

mkdir playground
cd playground
touch hello.txt
echo "Hello World!" > hello.txt
cat hello.txt