Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents
stylenone

Overview

While cPanel & WHM automates many server administration tasks, familiarity with the Linux® command line 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.

Note
titleNote:

For steps to access the command line, read our How to Access the Command Line documentation. 

Common Linux commands

Note
titleNote:

To execute a command, enter the command with any options or arguments that it requires and press Enter. 

The following table lists some basic Linux commands and their functions:

CommandDescription
ls

List files and directories that exist within your current directory. This command resembles the dir command in Windows®.

To view dotfiles (filenames that begin with a period) and additional file and directory details, add the -al options to the command:

Code Block
languagebash
ls -al


cd location

Navigate between directories.

Replace location with the path to the directory that you wish to navigate to. For example, to navigate to the /usr/local/apache/ directory, run the following command:

Code Block
languagebash
cd /usr/local/apache/ 


cat filename

Print the contents of the specified file to the CLI.

Replace filename with the relative path to the file that you wish to view. For example, to print the contents of the filename.txt file, run the following command:

Code Block
languagebash
cat filename.txt


Note
titleNote:

To view the data that currently displays on your server's console screen, run the following command:

Code Block
languagebash
cat /dev/vcs1



tail filename

Print the last 20 lines of a file to the command line interface (CLI).

Replace filename with the relative path to the file that you wish to view. For example, to print the last 20 lines of the filename.txt file, run the following command:

Code Block
languagebash
tail filename.txt

You can add an argument to change the number of lines that this command prints. For example, to print the last 100 lines of the filename.txt file, run the following command:

Code Block
languagebash
tail -100 filename.txt


more filename

Print the contents of a file to the CLI, one screen at a time.

Replace filename with the relative path to the file that you wish to view. For example, to print the contents of the filename.txt file one screen at a time, run the following command:

Code Block
languagebash
more filename.txt


pico filename

Open the specified file in the pico text editor.

Replace filename with the relative path to the file that you wish to edit. For example, to open the filename.txt file in the pico editor, run the following command:

Code Block
languagebash
pico filename.txt 


vi filename

Open the specified file in the vi text editor.

Replace filename with the relative path to the file that you wish to edit. For example, to open the filename.txt file in the vi editor, run the following command:

Code Block
languagebash
vi filename.txt


grep string filename

Search for a string in a specified file, and prints each line that contains a match to the CLI.

Replace string with a single word, or multiple words within single quotes (''). Replace filename with the relative path to the file that you wish to search. For example, to search for the string coffee filters in the grocerylist.txt file, run the following command:

Code Block
languagebash
grep 'coffee filters' grocerylist.txt 


touch filename

Create an empty file in the specified location.

Replace filename with the relative path to the file that you wish to create. For example, to create an empty example.txt file, run the following command:

Code Block
languagebash
touch example.txt 


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. For example, to create the symlink-file.txt file and point it to the /pointtome/file.txt file, run the following command:

Code Block
languagebash
ln -s /pointtome/file.txt symlink-file.txt


rm filename

Delete the specified file. After you run this command, the system prompts you to confirm the file's deletion.

Replace filename with the relative path to the file that you wish to delete. For example, to delete the trash.txt file, run the following command:

Code Block
languagebash
rm trash.txt 


lastList which users recently logged in and the timestamp for each login.
wList currently logged-in users and the location from which they logged in.
netstatList all of the server's current network connections.
file filename

Guess a file's type, based on the file's contents.

Replace filename with the relative path to the file for which you want the system to guess the type. For example, to cause the system to guess the type for the example.txt file, run the following command:

Code Block
languagebash
file filename 


duShow the system's current disk usage for each directory and subdirectory.
wc filename

Display the word count for a specific file.

Replace filename with the relative path to the file for which you wish to view a word count. For example, to display a word count for the example.txt file, run the following command:

Code Block
languagebash
wc example.txt 


cp file1 file2

Copy a file into a new file.

Replace file1 with the relative path to the existing file, and file2 with the relative path to the new copy file that you wish to create. For example, to copy the contents of the original.txt file to the /copies/duplicate.txt file, run the following command:

Code Block
languagebash
cp original.txt /copies/duplicate.txt 


chmod permissions filename

Change a file's octal permissions.

Replace permissions with the three-digit octal permissions that you wish to grant to the file, and replace filename with the relative path to the file for which you wish to alter the permissions. For example, to change the permissions of the myfile.txt file to 755, run the following command:

Code Block
languagebash
chmod 755 myfile.txt 

 For more information, read the Wikipedia article about the  chmod  command. 

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. For example, to grant the user joe in the group joesgroup ownership of the joesfile.txt file, run the following command:

Code Block
languagebash
chown joe:joesgroup joesfile.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
ps

Return information about the server's current processes.

To view all of the running processes, run one of the following commands:

Code Block
languagebash
linenumberstrue
ps -auxww
ps -cef 


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 table below lists examples of how to combine tasks into a single line:

CommandDescription


Code Block
languagebash
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.


Code Block
languagebash
last -a > /root/lastlogins.tmp


This command prints all of the current login history to the /root/lastlogins.tmp file.


Code Block
languagebash
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
titleNote:

The system treats periods (.) in a command as wildcard characters. Precede each period with a backslash (\) to instruct grep to interpret the period literally.



Code Block
languagebash
netstat -an | grep :80 | wc -l


This command shows the number of active connections to Apache (Apache's httpd daemon runs on port 80).


Code Block
languagebash
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.

Common configuration files and directories

You can find common configuration files and directories in the following locations on your server:

ServiceLocations
Exim


Code Block
languagebash
linenumberstrue
/etc/exim.conf
/var/log/exim_mainlog
/var/log/exim_rejectlog
/etc/valiases/
/etc/vfilters/
home/username/.forward 


MySQL®


Code Block
languagebash
linenumberstrue
/root/.my.cnf
/etc/my.cnf
/var/lib/mysql/


Apache


Code Block
languagebash
linenumberstrue
/usr/local/apache/conf/httpd.conf
/usr/local/apache/domlogs/


System


Code Block
languagebash
linenumberstrue
/var/log/messages
/var/log/dmesg


ProFTPD


Code Block
languagebash
linenumberstrue
/etc/proftpd.conf
/var/log/xferlog
/etc/proftpd/


SSH


Code Block
languagebash
/etc/ssh/sshd_config


 

Additional documentation

Localtab Group


Localtab
activetrue
titleSuggested documentation


Localtab
titleFor cPanel users

Content by Label
showLabelsfalse
max5
showSpacefalse
cqllabel = "cpanel" and label = "ssh" and space = currentSpace()


Localtab
titleFor WHM users

Content by Label
showLabelsfalse
max5
showSpacefalse
cqllabel = "ssh" and label = "whm" and space in (currentSpace(),"ALD")


Localtab
titleFor developers

Content by Label
showLabelsfalse
max5
showSpacefalse
cqllabel = "ssh" and space = "DD"