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
dircommand 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
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.txtto 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/messagesfile 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/messagesfile to the terminal.
more— Prints the file one screen at a time to the terminal.
more /etc/userdomains— Browses through the
userdomainsfile. Press the spacebar to go to the next screen. Enter
qat the command line to quit.
pico— Edits files in a text editor. The
picotext 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
picotext 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
rootin the file
grep -v root /etc/passwd— Searches for and displays all of the lines that do not match
rootin the file
touch— Creates an empty file.
touch /home/user1/public_html/404.html— Creates an empty
404.htmlfile in the
ln— Creates links between files and directories.
ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf— Edits the
/etc/httpd.conffile rather than the original
/usr/local/apache/conf/httpd.conffile. 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.txtfile. The system will prompt you to confirm that you wish to delete the file.
rm -f filename.txt— Deletes the
filename.txtfile. The system will not prompt you to confirm that you wish to delete the file.
rm -rf tmp/— Recursively deletes the
tmpdirectory 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
cp— Copies a file.
cp filename filename.backup— Copies the
filenamefile to the
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.txtfile, and grants the group and world permission to read and execute the
chown— Changes the owner of a file.
chown joe:joe myfile.txt— Sets both user and group ownership for the
myfile.txtfile to the
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:
|This command searches for all of the lines in the |
|This command prints all of the current login history to a |
This command finds the last 10,000 lines from the
The system will treat periods (
|This command shows the number of active connections to Apache (Apache's |
|This command lists the number of MySQL threads. If subselects start new threads, the output of the |
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:
You can use any of the following options to find a program.
- Run the
whereis programcommand to show one or more programs that match your search term.
- If you have more than one copy of a program, run the
which programcommand to find which program the shell will call first.
- If the first two options do not find the desired program, run the
locate programcommand 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,
programis 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:
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:
Locate the following string in the crontab:
Add the following string to that line in the crontab:
- 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:
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:
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:
How can I see which environment variables a process is running?
Run the following command:
How can I see a list of the users who have logged in to the server?
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.