Getting Started with Linux Commands
Overview
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.
For steps to access the command line, read our How to Access the Command Line documentation.
Common Linux commands
- To execute a command, enter the command with any required options and press Enter.
- In the following examples, replace
FILENAME
with the relative path to the file.
The following lists some basic Linux commands and their functions:
Command
|
Description | Example |
---|---|---|
cat FILENAME |
Print the contents of the specified file to the CLI. |
|
cat /dev/vcs1 |
View the data that currently displays on your server’s console screen. |
|
cd LOCATION |
Navigate between directories. Replace LOCATION with the path to the directory that you wish to navigate to. |
|
chmod permissions FILENAME |
Change a file’s octal permissions. For more information, read Wikipedia’s chmod command article. |
|
chown USER:GROUP FILENAME |
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. |
|
cp FILE1 FILE2 |
Copy a file (FILE1 ) into a new file (FILE2 ). |
|
du |
Show the system’s current disk usage for each directory and subdirectory. |
|
file FILENAME |
Guess a file’s type, based on the file’s contents. |
|
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 ('' ). |
|
last |
List which users recently logged in and the timestamp for each login. |
|
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. |
|
ls |
List files and directories that exist within your current directory. This command resembles the dir command in Windows®. |
|
ls -al |
View dotfiles (filenames that begin with a period) and additional file and directory details. |
|
more FILENAME |
Print the contents of a file to the CLI, one screen at a time. |
|
netstat |
List all of the server’s current network connections. |
|
pico FILENAME |
Open the specified file in the pico text editor. |
|
ps |
Return information about the server’s current processes.
Note:
To view all of the running processes add the
-auxww or -cef option to this command.
|
|
rm FILENAME |
Delete the specified file. After you run this command, the system prompts you to confirm the file’s deletion. |
|
tail -## FILENAME |
Print the last lines of a file to the CLI, where ## represents the number of lines to print. |
|
touch FILENAME |
Create an empty file in the specified location. |
|
vi FILENAME |
Open the specified file in the vi text editor. |
|
w |
List currently logged-in users and the location from which they logged in. |
|
wc FILENAME |
Display the word count for a specific file. |
|
whereis NAME |
Query applications that match the NAME value. You can find the most common applications in the following locations:
|
|
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 |
---|---|
|
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. |
|
This command prints all of the 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 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:
Service | Locations |
---|---|
Exim |
|
MySQL |
|
ProFTPD |
|
SSH | /etc/ssh/sshd_config |
System |
|