📂 File and Directory Commands
pwd- Print current working directoryls -l- List files with permissions and sizes, detailed infocd /path/to/dir- Change directorymkdir dirname- Create a new directoryrmdir dirname- Remove empty directoryrm -rf dirname- Remove directory and contents (⚠️ caution!)cp file1 file2- Copy filesmv file1 file2- Move or rename filestouch filename- Create empty file
📑 Viewing and Editing Files
cat filename- Show file contenthead -n 10 filename- Show first 10 linestail -n 10 filename- Show last 10 linesless filename- View file one page at a timenano filename- Simple terminal text editorvi filenameorvim filename- Advanced text editor
🔍 Searching & Filtering
grep "text" filename- Search for text in filegrep -r "text" /path- Recursive search in directoriesfind /path -name "file.txt"- Find files by namefind /path -type f -size +10M- Find large filessort filename- Sort file contentuniq filename- Remove duplicate lines
📊 Disk and System Info
df -h- Disk space usagedu -sh *- Size of each file/folderfree -h- Memory usageuptime- System load and uptimeuname -a- Kernel and system infotoporhtop- Running processeswho/w- Logged-in users
🛠️ Permissions & Ownership
chmod +x script.sh- Make a script executablechown user:group file- Change file ownerchmod 755 file- Set permissions (rwxr-xr-x)umask- View default permissions mask
🌐 Network Commands
ping google.com- Test connectivitycurl -I http://example.com- Fetch HTTP headerswget http://example.com/file- Download filess -tulnornetstat -tuln- Show listening portsip a- Show network interfaces
📦 Package Management
Debian / Ubuntu (APT)
sudo apt update- Refresh package databasesudo apt upgrade- Install available updatessudo apt install pkg- Install a packagesudo apt remove pkg- Remove packagedpkg -l- List all installed packagessudo dpkg -i file.deb- Install a downloaded .deb package
RHEL / CentOS / Fedora (YUM / DNF)
sudo yum update- Update packagessudo yum install pkgorsudo dnf install pkg- Installsudo yum remove pkg- Remove packagesudo rpm -ivh file.rpm- Install a local .rpm filerpm -qa- List installed packagesrpm -ql packagename- Show installed files of a package
⚙️ Process Management
ps aux- List all running processeskill PID- Kill process by PIDkill -9 PID- Force kill a process by PIDjobs/bg/fg- Manage background jobshtop- Interactive process viewer (if installed)
⏲️ Scheduling Jobs
crontab -e- Edit scheduled taskscrontab -l- List user cron jobsat 10:00- Run command at specific time
💡 Tips
- Use
man commandto get help on any command. - Use
--helpwith most commands for quick reference. - Always double-check before using
rm -rforsudo.