ssh

Getting Started with Linux Commands

Last modified: July 13, 2022


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.

Note:

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

Common Linux commands

Note:
  • 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 filename.txt
cat /dev/vcs1 View the data that currently displays on your server’s console screen.
cat /dev/vcs1
cd LOCATION Navigate between directories. Replace LOCATION with the path to the directory that you wish to navigate to.
cd /usr/local/apache/
chmod permissions FILENAME Change a file’s octal permissions. For more information, read Wikipedia’s chmod command article.
chmod 755 myfile.txt
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.
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.
netstat
pico FILENAME Open the specified file in the pico text editor).
pico filename.txt
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.
ps
rm FILENAME Delete the specified file. After you run this command, the system prompts you to confirm the file’s deletion.
rm trash.txt
tail -## FILENAME Print the last lines of a file to the CLI, where ## represents the number of lines to print.
tail -20 filename.txt
touch FILENAME Create an empty file in the specified location.
touch example.txt
vi FILENAME Open the specified file in the vi text editor.
vi filename.txt
w 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:

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