Frequently Used Commands

Below is a list of a few commonly used commands. The highlighted arguments should be replaced with the actual arguments.

ls - Displays everything in the current directory
ls -a - Displays all files, including hidden
ls -l - Displays all files, along with the size and timestamp
tar -zxpf archive.tar.gz - Uncompresses tar.gz files
tar -xpf archive.tar - Uncompresses .tar files
gunzip archive.gz - Uncompresses .gz files
cp source target - Copies a file
mv source target - Moves a file to a new file, or rename
mkdir directory-name - Creates a directory
rmdir directory-name - Deletes a directory
rm file-name - Deletes a file
rm -rfv directory-name - Deletes a directory
cd location - Moves to a directory
cd .. - Moves to a lower directory
cd ~ - Moves to your home directory
cd - - Moves to the previous directory
pwd - Displays the current directory
pico - Opens the text editor
ftp - Connect to an FTP server
lynx - View a webpage
df -h - Displays the hard drive stats in human-readable format
quota - Displays your disk quota
uptime - Displays the uptime of the server
uname -a - Displays the operating system stats
whoami - Displays your current account information
who - Displays others connected to the server
last - Displays the last login
whereis - Shows where a file is located
mail - Checks your email
ps -x - Displays processes your running
ps -a - Displays all processes running
ps -ux - Displays running processes, with CPU/Memory usage
kill process - Kills a process
kill -9 process - Kills an eggdrop process
killall process - Kills all running process of the same type
whatis - Description of commands
man - Displays help on the command
nano - Opens the editor
top - Gives an overall view of what is going on with the server including memory usage, server load and running processes. Press q to exit top.
sar -q - Gives a report of the process list, 1-minute and 5-minute average load every 10 minutes since midnight (server time)
tar -zcf filename.tar.gz filename - Archives the file or directory of your choice, replace filename.tar.gz with the name you want your tar file to have (including tar.gz extension at the end) and replace filename with the file or directory you want to pack into the archive. You can also use a path/to/file for both of these arguments.
updatedb - Updates the locate/search database

netstat -n -p - Useful to see who is connected to your server. This also resolves hostnames to IP addresses and the -p flag shows what each connected user is doing, providing a PID for it (if available).

find / -user username - Replace username with a username of one of your accounts to find all the files that belong to them. Also useful to add the |more switch so you can scroll one screen at a time. Ever have a client who seems to show a lot more files than are actually in their home directory? This is how you find those files and fix them. Common problem on cPanel servers is cpmove files that don't get properly deleted and get added to a user's account.

The --help flag - For example tar --help, similar to man, it shows information about any given command.

tail -10 filename - Gives you the last 10 lines of a file. Can change the # to whatever you want.

cp -R fileordirectory path/to/destination - The -R flag runs the command recursively and allows you to copy an entire directory.

kill -9 process - Not just for eggdrops. Known as "hard kill" and is handy for terminating any stubborn process that refuses to end. Please use with caution, as ending a system process can sometimes cause severe issues.

killall process - Terminate all processes being run by a user. Useful if you have an abuser eating up system resources. Please use with caution, as ending a system process can sometimes cause severe issues.

Manage Services

Restart a service:

systemctl restart service-name

Stop a service:

systemctl stop service-name

Start a service:

systemctl start service-name

Check current status:

systemctl status service-name

Replace service-name with the name of the actual service.

On a RHEL-based cPanel server, here are the most common services:

bandmin
chkservd
cpanel
crond
exim
httpd
mysql
named
proftpd

Editing Cron Jobs

To edit the cron jobs of the current account:

crontab -e

To edit a user's cron jobs:

crontab -u username -e

Replace username with the actual username of the user you want to edit.

cPanel / WHM Scripts

If your server has cPanel installed, it will add many useful and important scripts under the /scripts directory. You can find a current list of these scripts here: WHM Scripts | cPanel & WHM Documentation

DISCLAIMER: The scripts and commands provided in our knowledgebase are for informational purposes only. We do not provide any warranty or support. It is essential to review and modify the scripts/commands to fit your site's specific needs. There may be unforeseen outcomes when adding new script code to an existing website. You should discuss it with your website manager and seek advice from an experienced website developer if you are unsure.

Updated by SP on 23/11/2022

Was this answer helpful? 376 Users Found This Useful (865 Votes)