While cPanel & WHM automates many server administration tasks, familiarity with the Linux® command line interface (CLI) can prove useful for both WHM and cPanel users. This documentation gives a brief overview of some basic Linux commands that you may wish to use as you manage your website or server.
Change a file’s user and group ownership. Replace USER with the user to whom you wish to grant ownership of the file, GROUP with the group name, and FILENAME with the relative path to the file.
chown user:usersgroup usersfile.txt
cp FILE1 FILE2
Copy a file (FILE1) into a new file (FILE2).
cp original.txt /copies/duplicate.txt
du
Show the system’s current disk usage for each directory and subdirectory.
du
file FILENAME
Guess a file’s type, based on the file’s contents.
file filename
grep string FILENAME
Search for a string in a specified file and print each line that contains a match to the CLI. Replace string with a single word, or multiple words within single quotes ('').
grep 'thisis anexample' filename.txt
last
List which users recently logged in and the timestamp for each login.
last
ln -s file1 file2
Create a symbolic link between the two specified files. Replace file1 with the relative path to the existing file, and file2 with the relative path to the new symbolic link file.
ln -s /pointtome/file1.txt symlink-file2.txt
ls
List files and directories that exist within your current directory. This command resembles the dir command in Windows®.
ls
ls -al
View dotfiles (filenames that begin with a period) and additional file and directory details.
ls -al
more FILENAME
Print the contents of a file to the CLI, one screen at a time.
more filename.txt
netstat
List all of the server’s current network connections.
List currently logged-in users and the location from which they logged in.
w
wc FILENAME
Display the word count for a specific file.
wc example.txt
whereis NAME
Query applications that match the NAME value. You can find the most common applications in the following locations:
/usr/sbin/sendmail
/usr/bin/perl
/bin/mail
/usr/bin/php
whereis perl
Run multiple commands on the same line
Various command-line tasks may require that you use different commands on the same line. Linux includes easy methods to perform these tasks:
Use the pipe character (|) to retrieve data from one program and “pipe” it to another program.
Use a single greater-than bracket (>) to create a new file if the file does not already exist, or to overwrite any existing content if the file does exist.
Use a double greater-than bracket (>>) to create a new file if the file does not already exist, or to append the new data to the file if the file does exist.
Use a single less-than bracket (<) to send input from a file to a command.
The following are examples of how to combine tasks into a single command:
Command
Description
grep User /usr/local/apache/conf/httpd.conf | more
This command searches for all of the lines in the httpd.conf file that match the User search term, and then prints the results to your terminal one screen at a time.
last -a > /root/lastlogins.tmp
This command prints all of the current login history to the /root/lastlogins.tmp file.
mysql --skip-column-names --batch -e 'show processlist' | wc -l
This command lists the number of MySQL® threads. If subselect expressions start new threads, the output of the show processlist command includes them.
netstat -an | grep :80 | wc -l
This command shows the number of active connections to Apache®. Apache’s httpd daemon runs on port 80.
tail -10000 /var/log/exim_mainlog | grep 'example\.com' | more
This command finds the last 10,000 lines from the /var/log/exim_mainlog file, searches those lines for all occurrences of the string example.com, and then prints the search results to your terminal one screen at a time.
Note:
The system treats periods (.) in a command as wildcard characters. Precede each period with a backslash (\) to instruct grep to interpret the period literally.
Common configuration files and directories
You can find common configuration files and directories in the following locations on your server: