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 filename.txt
cat /dev/vcs1 Views the data currently displayed on your server’s console screen.
cat /dev/vcs1
cd LOCATION Navigates between directories. Replace LOCATION with the path to the desired directory.
cd /usr/local/apache/
chmod permissions FILENAME Changes a file’s octal permissions. For more information, read Wikipedia’s chmod command article.
chmod 755 myfile.txt
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.
chown user:usersgroup usersfile.txt
cp FILE1 FILE2 Copies a file (FILE1) to a new file (FILE2).
cp original.txt /copies/duplicate.txt
du Shows the system’s current disk usage for each directory and subdirectory.
du
file FILENAME Guesses a file’s type based on its contents.
file filename
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 ('').
grep 'thisis anexample' filename.txt
last Lists recently logged-in users and the timestamp for each login.
last
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.
ln -s /pointtome/file1.txt symlink-file2.txt
ls Lists files and directories within your current directory. This command is similar to the dir command in Windows®.
ls
ls -al Views dotfiles (filenames that begin with a period) and additional file and directory details.
ls -al
more FILENAME Prints the contents of a file to the CLI, one screen at a time.
more filename.txt
netstat Lists all current network connections on the server.
netstat
pico FILENAME Opens the specified file in the pico text editor.
pico filename.txt
ps Returns information about the server’s current processes.

Note: To view all running processes, add the -auxww or -cef option to this command.
ps
rm FILENAME Deletes the specified file. After running this command, the system prompts for confirmation of deletion.
rm trash.txt
tail -## FILENAME Prints the last lines of a file to the CLI, where ## represents the number of lines to print.
tail -20 filename.txt
touch FILENAME Creates an empty file in the specified location.
touch example.txt
vi FILENAME Opens the specified file in the vi text editor.
vi filename.txt
w Lists currently logged-in users and their login locations.
w
wc FILENAME Displays the word count for a specific file.
wc example.txt
whereis NAME Queries applications that match the NAME value. Common applications can be found in the following locations:
  • /usr/sbin/sendmail
  • /usr/bin/perl
  • /bin/mail
  • /usr/bin/php
whereis perl

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
grep User /usr/local/apache/conf/httpd.conf | more
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.
last -a > /root/lastlogins.tmp
This command prints all 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 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
  • /etc/exim.conf
  • /var/log/exim_mainlog
  • /var/log/exim_rejectlog
  • /etc/valiases/
  • /etc/vfilters/
  • /home/username/.forward
MySQL
  • /root/.my.cnf
  • /etc/my.cnf
  • /var/lib/mysql/
ProFTPD
  • /etc/proftpd.conf
  • /var/log/xferlog
  • /etc/proftpd/
SSH /etc/ssh/sshd_config
System
  • /var/log/messages
  • /var/log/dmesg

Additional Documentation

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