Overview
While many server administration tasks are automated by cPanel & WHM, proficiency with the Linux® command line interface (CLI) can be highly beneficial for both WHM and cPanel users. This documentation provides a concise overview of fundamental Linux commands that can assist in managing your website or server.
Common Linux Commands
Note: To execute a command, input the command along with any necessary options, then press Enter. In the examples provided, substitute FILENAME
with the file's relative path.
Command | Description | Example |
---|---|---|
cat FILENAME |
Prints the contents of the specified file to the CLI. |
|
cat /dev/vcs1 |
Views the data currently displayed on your server’s console screen. |
|
cd LOCATION |
Navigates between directories. Replace LOCATION with the path to the desired directory. |
|
chmod permissions FILENAME |
Changes a file’s octal permissions. For more information, read Wikipedia’s chmod command article. |
|
chown USER:GROUP FILENAME |
Changes a file’s user and group ownership. Replace USER with the user to whom you wish to grant ownership, GROUP with the group name, and FILENAME with the file's relative path. |
|
cp FILE1 FILE2 |
Copies a file (FILE1 ) to a new file (FILE2 ). |
|
du |
Shows the system’s current disk usage for each directory and subdirectory. |
|
file FILENAME |
Guesses a file’s type based on its contents. |
|
grep string FILENAME |
Searches for a string in a specified file and prints each matching line to the CLI. Replace string with a single word, or multiple words enclosed in single quotes ('' ). |
|
last |
Lists recently logged-in users and the timestamp for each login. |
|
ln -s file1 file2 |
Creates 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. |
|
ls |
Lists files and directories within your current directory. This command is similar to the dir command in Windows®. |
|
ls -al |
Views dotfiles (filenames that begin with a period) and additional file and directory details. |
|
more FILENAME |
Prints the contents of a file to the CLI, one screen at a time. |
|
netstat |
Lists all current network connections on the server. |
|
pico FILENAME |
Opens the specified file in the pico text editor. |
|
ps |
Returns information about the server’s current processes. Note: To view all running processes, add the -auxww or -cef option to this command. |
|
rm FILENAME |
Deletes the specified file. After running this command, the system prompts for confirmation of deletion. |
|
tail -## FILENAME |
Prints the last lines of a file to the CLI, where ## represents the number of lines to print. |
|
touch FILENAME |
Creates an empty file in the specified location. |
|
vi FILENAME |
Opens the specified file in the vi text editor. |
|
w |
Lists currently logged-in users and their login locations. |
|
wc FILENAME |
Displays the word count for a specific file. |
|
whereis NAME |
Queries applications that match the NAME value. Common applications can be found in the following locations:
|
|
Run Multiple Commands on the Same Line
Certain command-line operations may necessitate the execution of multiple commands on a single line. Linux offers straightforward methods to achieve this:
- The pipe character (
|
) allows you to take the output of one program and direct it as input to another. - A single greater-than bracket (
>
) is used to create a new file, or to overwrite an existing file's content. - A double greater-than bracket (
>>
) creates a new file if it doesn't exist, or appends new data to an existing file. - A single less-than bracket (
<
) directs input from a file to a command.
The following examples demonstrate how to combine tasks into a single command:
Command | Description |
---|---|
|
This command searches for all lines in the httpd.conf file that match the User search term, then prints the results to your terminal one screen at a time. |
|
This command prints all current login history to the /root/lastlogins.tmp file. |
|
This command lists the number of MySQL® threads. If subselect expressions start new threads, the output of the show processlist command includes them. |
|
This command shows the number of active connections to Apache®. Apache’s httpd daemon runs on port 80 . |
|
This command retrieves 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.Important: The system interprets periods ( . ) in a command as wildcard characters. To ensure grep interprets a period literally, precede it with a backslash (\ ). |
Common Configuration Files and Directories
Key configuration files and directories are typically located in the following paths on your server:
Service | Locations |
---|---|
Exim |
|
MySQL |
|
ProFTPD |
|
SSH | /etc/ssh/sshd_config |
System |
|