Skip to main content

CLI (Command Line Interface)

A quick reference for essential command line operations on Linux, macOS, and Windows (with Git Bash).


CommandDescription
pwdPrint working directory
lsList files in directory
ls -lList with details
ls -aList all (including . files)
cd folderChange directory
cd ..Up one directory
cd ~Go to home directory
treeDisplay directory tree

File & Folder Manipulation​

CommandDescription
touch file.txtCreate empty file
mkdir folderCreate new folder
rm file.txtRemove file
rm -r folderRemove folder recursively
cp src destCopy file/folder
mv src destMove or rename
cat file.txtView file contents
head file.txtFirst 10 lines of file
tail file.txtLast 10 lines of file
less file.txtScroll file contents
echo "text"Print text

Searching​

CommandDescription
grep "pattern" file.txtSearch for pattern in file
grep -r "pattern" folder/Recursive search in folder
find . -name "*.js"Find files matching name
which commandShow command location
locate filenameFind file by name (uses database)

Permissions​

CommandDescription
chmod 644 file.txtChange file permissions
chmod +x script.shMake file executable
chown user:group fileChange file owner/group

Process Management​

CommandDescription
ps auxList all running processes
topDisplay real-time system stats
htopInteractive process viewer
kill PIDKill process by PID
pkill nameKill process by name

Networking​

CommandDescription
ping example.comTest network connection
curl http://example.comFetch web page (show source)
wget http://example.comDownload file/web page
ssh user@hostConnect to remote host via SSH
scp file user@host:/pathSecure copy file to remote host

Archiving & Compression​

CommandDescription
tar -cvf archive.tar folderCreate tar archive
tar -xvf archive.tarExtract tar archive
tar -czvf archive.tar.gz folderCreate gzip compressed archive
tar -xzvf archive.tar.gzExtract gzip compressed archive
zip archive.zip fileCreate zip archive
unzip archive.zipExtract zip archive

Package Managers​

CommandDescription
apt updateUpdate package list (Debian/Ubuntu)
apt install packagenameInstall package (Debian/Ubuntu)
yum install packagenameInstall package (RHEL/CentOS)
brew install packagenameInstall package (macOS/Homebrew)
npm install packageInstall Node.js package
yarn add packageInstall package with Yarn

Miscellaneous​

CommandDescription
historyShow command history
clearClear terminal screen
man commandShow manual for command
dateDisplay current date/time
whoamiShow current user
df -hShow disk space usage
du -sh folderShow size of folder

Sudo and Superuser​

CommandDescription
sudo commandRun command as superuser
su userSwitch to another user

Tips​

  • Use Tab for autocompletion.
  • Use Ctrl+C to cancel a running command.
  • Use Ctrl+R to search command history.
  • Use Up/Down arrows to browse previous commands.

Note: Some commands may vary or require installation on Windows (use Git Bash, WSL, or PowerShell equivalents).