Linux/SSH Command Line Quick Reference


File and Directory Management

  • ls – List contents of current directory

  • ls -a – List all files including hidden

  • ls -la – List all with details (permissions, size, timestamp)

  • cp source dest – Copy file

  • cp -R dir1 dir2 – Copy directory recursively

  • mv oldname newname – Move or rename file or directory

  • mkdir dirname – Create directory

  • rmdir dirname – Delete empty directory

  • rm filename – Delete file

  • rm -rf dirname – Delete directory recursively



Navigating the Filesystem

  • cd /path – Change to directory

  • cd .. – Move to parent directory

  • cd ~ – Move to home directory

  • cd - – Switch to previous directory

  • pwd – Show current directory

 

 

File Editing

  • nano filename – Edit file using nano

  • pico filename – Edit file using pico (older systems)

 

 

 

Archive and Compression

  • tar -zcf archive.tar.gz file_or_dir – Create compressed tarball

  • tar -zxpf file.tar.gz – Extract .tar.gz

  • tar -xpf file.tar – Extract .tar

  • gunzip file.gz – Uncompress .gz

 

 

 

File Search

  • find / -user username – Find files owned by user

  • whereis command – Locate binary/source/man page

  • updatedb – Update file locate database

  • locate filename – Fast file lookup

 

 

 

System Information

  • df -c – Disk usage

  • quota – Show disk quota

  • uptime – Show system uptime

  • uname -a – Show OS info

  • whoami – Show current user

  • who – List logged-in users

  • last – Show last logins

  • ps – Show running processes

  • ps -x – Show current user processes

  • ps aux – Show all processes

  • top – Live process monitor (press q to quit)

  • sar -q – System load averages every 10 mins

  • netstat -np – Show active connections

 

 

 

Process Management

  • kill PID – Kill process by PID

  • kill -9 PID – Force kill process

  • killall name – Kill all processes by name or user

 

 

 

Networking

  • ftp server.com – Connect to FTP

  • lynx url – View webpage in terminal

 

 

 

Package and Service Management (RedHat-based)

  • service servicename start|stop|restart|status – CentOS 6

  • systemctl start|stop|restart|status servicename – CentOS 7+

Common services:

  • httpd, mysql, named, exim, cpanel, proftpd, crond, chkservd, bandmin

 

 

 

Cron Jobs

  • crontab -e – Edit root/user’s cron jobs

  • crontab -u username -e – Edit another user’s cron jobs

 

 

 

Mail

  • mail – Check local mail

 

 

 

WHM/cPanel Scripts (run as root)

  • /scripts/pkgacct2 username – Manual backup

  • /scripts/restorepkg username – Restore backup

  • /scripts/killacct username – Terminate account

  • /scripts/suspendacct username – Suspend account

  • /scripts/unsuspendacct username – Unsuspend account

  • /scripts/editquota username – Edit disk quota

  • /scripts/fixinterchange – Fix Interchange issues

  • /scripts/fixwebalizer – Fix stats

  • /scripts/restartsrv servicename – Restart service

  • /scripts/mailperm – Fix mail permissions

  • /scripts/mysqlpasswd – Change MySQL password

  • /scripts/findtrojans – Scan for trojans

  • /scripts/fixtrojans – Remove trojans

 

 

 

File Viewing & Logs

  • tail -n filename – View last n lines of file

 

 

 

Miscellaneous

  • --help – View help for most commands (e.g., tar --help)

  • reboot – Reboot server

  • mv – Also used to rename directories

 

 

 

Maintenance

  • Delete MRTG:

    rpm -e --nodeps \ $(rpm -q | grep mrtg)

  • Clear /tmp folder:

 

rm -Rf /tmp/c*
rm -Rf /tmp/s*
rm -Rf /tmp/p*
rm -Rf /tmp/*_*
rm -Rf /tmp/*-*

Comments

  Add Comment

Confirm Submission

Please enter the text from the image in the box provided; this helps us to prevent spam.