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.
ls
β List Directory Contentsls # List files and folders
ls -la # List all, with details (hidden files too)
cd
β Change Directorycd folder-name # Go into a folder
cd .. # Go back one level
cd ~ # Go to home directory
pwd
β Print Working Directorypwd # Shows the current path
mkdir
β Make Directorymkdir my-folder
touch
β Create a New Filetouch file.txt
cp
β Copy Files or Folderscp file.txt copy.txt # Copy a file
cp -r dir1 dir2 # Copy a folder recursively
mv
β Move or Rename Filesmv old.txt new.txt # Rename a file
mv file.txt ~/Documents # Move file to Documents
rm
β Remove Files or Foldersrm file.txt # Delete a file
rm -r folder-name # Delete a folder recursively
β οΈ Caution: Thereβs no trash/recycle bin in the terminal.
find
β Locate Filesfind . -name "*.js" # Find all `.js` files in current directory
grep
β Search Inside Filesgrep "function" file.js # Find lines containing "function"
grep -r "TODO" . # Search recursively
history
β Show Command Historyhistory # View previous commands
clear
β Clear Terminal Screenclear
man
β Manual Pages (Help)man ls # Show manual for `ls`
Press
q
to quit the manual page.
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
top
or htop
β Process Viewertop # Show system processes (press `q` to quit)
whoami
β Show Current Userwhoami
uname
β Show System Infouname -a # All system info
Shortcut | Meaning |
---|---|
. |
Current directory |
.. |
Parent directory |
~ |
Home directory |
/ |
Root directory |
Tab
to autocomplete file or folder names.β
and β
arrows to navigate command history.Ctrl + C
to stop a running process.Use &&
to chain commands:
mkdir test && cd test
Try this:
mkdir playground
cd playground
touch hello.txt
echo "Hello World!" > hello.txt
cat hello.txt