Page tree
Skip to end of metadata
Go to start of metadata

Is there a cheat sheet for shell commands?

The following is a breakdown of the most commonly used commands and the most commonly used arguments for them. 

  • ls — Lists files and directories in a directory. This command is comparable to the dir command in Windows®.
    • ls -al — Shows all of the files (which includes filenames that start with a period), directories, and details for each file.
  • cd — Navigates between directories.
    • cd /usr/local/apache — Navigates to the /usr/local/apache/ directory.
    • cd ~ — Navigates to your home directory.
    • cd - — Navigates to the previous directory.
    • cd .. — Navigates to the directory that contains your current directory.
  • cat — Prints file contents to the terminal.
    • cat filename.txt — Prints the contents of filename.txt to the terminal.
  • tail — Prints the end of the file to the terminal.
    • tail /var/log/messages — Prints the last 20 lines of the /var/log/messages file to the terminal.
    • tail -f /var/log/messages — Watches the file continuously as you update it.
    • tail -200 /var/log/messages — Prints the last 200 lines of the /var/log/messages file to the terminal.
  • more — Prints the file one screen at a time to the terminal.
    • more /etc/userdomains — Browses through the userdomains file. Press the spacebar to go to the next screen. Enter q at the command line to quit.
  • pico — Edits files in a text editor. The pico text editor is easy to use.
    • pico /home/user1/public_html/index.html — Opens the index page of the user's website in the text editor.
  • vi — Edits files in a text editor that is more difficult to use than the pico text editor, but that is also more powerful.
    • vi /home/user1/public_html/index.html — Open the index page of the user's website in the text editor.
  • grep — Searches for patterns in files and displays the results.
    • grep root /etc/passwd — Searches for and displays all of the matches for root in the file /etc/passwd.
    • grep -v root /etc/passwd — Searches for and displays all of the lines that do not match root in the file /etc/passwd.
  • touch — Creates an empty file.
    • touch /home/user1/public_html/404.html — Creates an empty 404.html file in the /home/user1/public_html/ directory.
  • ln — Creates links between files and directories.
    • ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf — Edits the /etc/httpd.conf file rather than the original /usr/local/apache/conf/httpd.conf file. Changes will affect the orginal. However, you can delete the link but not the original.
  • rm — Deletes a file.
    • rm filename.txt — Deletes the filename.txt file. The system will prompt you to confirm that you wish to delete the file.
    • rm -f filename.txt — Deletes the filename.txt file. The system will not prompt you to confirm that you wish to delete the file.
    • rm -rf tmp/ — Recursively deletes the tmp directory and all of its files and subdirectories.


      You cannot recover the directory after you run this command.

  • last — Lists which users have logged in and when.
    • last -20 — Lists only the previous 20 logins.
    • last -20 -a — Lists the previous 20 logins, with the hostname in the last field.
  • w — Lists the users that are currently logged in and where they logged in from.
  • netstat — Lists all of the current network connections.
    • netstat -an — Lists all of the connections to the server. This includes the source and destination IP addresses and ports.
    • netstat -rn — Lists a routing table for all IP addresses that are bound to the server.
  • file — Attempts to guess the file type by its content.
    • file * : — Prints out a list of all of the files and directories within the current directory.
  • du — Shows disk usage.
    • du -sh — Shows a summary, in human-readable form, of total disk space in the current directory and its subdirectories.
    • du -sh * — Shows a summary for each file and directory. This is helpful when you need to find large files that take up space.
  • wc — Displays the word count for a file.
    • wc -l filename.txt — Displays the number of lines in the filename.txt file.
  • cp — Copies a file.
    • cp filename filename.backup — Copies the filename file to the filename.backup file.
    • cp -a /home/user1/new_design/* home/burst/public_html/ — Copies all of the files in one directory to another directory, and retains the files' permissions.
  • chmod — Changes a file's permissions. For more information, read the Wikipedia article about the chmod command. 
    • chmod 755 myfile.txt — Grants the user permission to read, write, and execute the myfile.txt file, and grants the group and world permission to read and execute the myfile.txt file.
  • chown — Changes the owner of a file.
    • chown joe:joe myfile.txt — Sets both user and group ownership for the myfile.txt file to the joe user.


How can I 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:

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 a /root/lastlogins.tmp file.
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 "", and then prints the search results to your terminal one screen at a time.


The system will treat periods (.) in a command as wildcard characters. Preceed each period with a backslash (\) to instruct Linux to interpret the period literally.

netstat -an | grep :80 | wc -l
This command shows the number of active connections to Apache (Apache's httpd daemon runs on port 80).
mysql --skip-column-names --batch -e 'show processlist' | wc -l
This command lists the number of MySQL threads. If subselects start new threads, the output of the show processlist command will include them.


For more information on Linux and the command line, visit the following links. cPanel, Inc. is not responsible for content on other sites:


Where can I find programs?

You can find the most common programs in the following locations:

  • /usr/sbin/sendmail
  • /usr/bin/perl
  • /bin/mail
  • /usr/bin/php

You can use any of the following options to find a program.

  • Run the whereis program command to show one or more programs that match your search term.
  • If you have more than one copy of a program, run the which program command to find which program the shell will call first.
  • If the first two options do not find the desired program, run the locate program command to display every file that matches your search term.


  • Before you use these options, use SSH to log in to the shell.
  • In the command for each option, program is the program that you wish to find. 

Default locations for common configuration files and directories




















Which ports should I open if my cPanel server is behind a firewall?

For a list of the ports that cPanel & WHM services use, read our How to Configure Your Firewall for cPanel & WHM's Services article.

How do I find all of the SETUID root files on my server?

The following command will show all of the SETUID and SETGID files on the server:

find / -type f \( -perm -04000 -o -perm -02000 \) \-exec ls -lg {} \; 

Can I use Linux on any computer?

While Linux is a general term for many operating systems, most distributions of these operating systems support most hardware. You can find more information at your specific operating system's website.


How do I prevent a single job in my crontab from sending an email every time it runs?

To ensure that a single job in your crontab does not send an email every time that it runs, perform the following steps:

  1. Locate the following string in the crontab:

    0 * * * * /home/uesr/
  2. Add the following string to that line in the crontab:

    /dev/null 2>&1
  3. Save your changes.

How do I prevent my crontab from sending any emails?

To ensure that crontab cannot send emails, remove the contact email address from the crontab.

How do I see what is on the console screen of my Linux server?

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

cat /dev/vcs1

I use Windows. How can I log in to my server?

You must first download an SSH client. We recommend that you use PuTTY. You can download this free client from the PuTTY website .


How can I view all of the running processes from the shell?

Run one of the following commands:

ps -auxww
ps -cef

For more information use about the ps command, run the man ps command.


How can I see all of the users with the UID of 0 on the shell?

Run the following command:

grep :x:0: /etc/passwd

How can I see which environment variables a process is running?

Run the following command:

ps auxwwe | grep processname

How can I see a list of the users who have logged in to the server?

Use the last command (for example, last -30). This command displays the last 30 users who logged in to the server.

Can I change root’s default shell?

cPanel requires the root user to use the bash shell by default. Other users can use shells other than bash if the systems administrator wishes to make this an option.