You don't need to be a system administrator to get real work done on the command line. This guide covers the basic Linux commands for managing your website over SSH -- moving around, viewing and editing files, copying and deleting safely, finding what's using your disk space, searching for text, handling zip files and fixing permissions -- with examples you can copy straight into your Instant Access Internet Services account.
Where to type these commands
You have two options:
- Terminal in cPanel -- go to Advanced > Terminal. It runs in your browser, so there's nothing to set up.
- SSH from your computer -- run
ssh username@example.comin Terminal (Mac/Linux) or PowerShell (Windows), using your cPanel username.
Either way you start in your home directory, /home/username. Your account runs in its own isolated environment, so you see only your own files. You can't use sudo or install system software, and you don't need to for anything in this guide.
Read this before you type anything
- There is no Recycle Bin. A file deleted with
rmis gone. Our backups (three times a week, last 7 kept) can bring it back, but only as it was at the last backup. - Case matters.
Images,imagesandIMAGESare three different folders. - Look before you act. Before deleting or changing files with a wildcard (
*), run the same pattern withlsfirst to see exactly what it matches. - Make a copy before editing.
cp .htaccess .htaccess.baktakes a second and can save your site.
Time-savers that make the command line easier
| Key or command | What it does |
|---|---|
| Tab | Completes a file or folder name. Type cd pub and press Tab to get cd public_html/. Press it twice to see all matches. |
| Up arrow | Brings back your previous commands. |
| Ctrl + C | Stops the command that's running. Use it whenever something is taking too long or you made a mistake. |
clear | Clears the screen. |
history | Lists the commands you've run recently. |
command --help | Shows the options for most commands, for example ls --help. |
Moving around
| Command | What it does |
|---|---|
pwd | Shows the folder you're in ("print working directory"). |
ls | Lists files in the current folder. |
ls -la | Lists everything, including hidden files like .htaccess, with sizes, dates and permissions. |
ls -lt | head | Shows the most recently changed files first. |
cd public_html | Goes into your website folder. |
cd .. | Goes up one folder. |
cd ~ or just cd | Goes back to your home directory from anywhere. |
Here's what ls -la output looks like, and how to read one line:
-rw-r--r-- 1 username username 523 Sep 12 09:41 .htaccess
drwxr-xr-x 5 username username 4096 Sep 20 14:02 wp-content
The first character is - for a file or d for a directory (folder). Next come the permissions, the owner, the size in bytes, the date last modified and the name.
Looking at files
| Command | What it does |
|---|---|
cat robots.txt | Prints a short file to the screen. |
less error_log | Opens a long file one screen at a time. Use the arrow keys or Space to scroll, /word to search, and q to quit. |
head -n 20 file | Shows the first 20 lines. |
tail -n 50 error_log | Shows the last 50 lines -- the newest errors. |
tail -f error_log | Keeps showing new lines as they're added. Reload your website in another window to watch errors appear live. Press Ctrl + C to stop. |
wc -l file | Counts the lines in a file. |
Editing files
For quick changes, use the nano text editor, which is available on our servers.
- Open a file with
nano .htaccess. Type your changes, press Ctrl + O then Enter to save, and Ctrl + X to exit. The shortcuts are listed at the bottom of the screen.
If you'd rather not edit on the command line, cPanel's File Manager has a full editor under Files > File Manager.
Creating, copying, moving and renaming
| Command | What it does |
|---|---|
mkdir backups | Creates a folder. |
mkdir -p a/b/c | Creates a folder and any missing parent folders. |
cp wp-config.php wp-config.php.bak | Copies a file. |
cp -r public_html ~/site-copy | Copies a whole folder and its contents. |
mv old-name.html new-name.html | Renames a file. |
mv report.pdf public_html/files/ | Moves a file into another folder. |
touch newfile.txt | Creates an empty file (or updates the date on an existing one). |
A practical example -- temporarily disabling all WordPress plugins by renaming their folder, then putting it back:
cd ~/public_html/wp-content
mv plugins plugins.off
# test the site, then:
mv plugins.off plugins
Deleting safely
| Command | What it does |
|---|---|
rm file.txt | Deletes one file. |
rm -i *.log | Deletes matching files, asking you to confirm each one. |
rmdir emptyfolder | Deletes a folder only if it's empty. |
rm -r oldfolder | Deletes a folder and everything inside it. |
Be very careful with rm -r and rm -rf. A stray space turns rm -rf ./old into rm -rf . /old, which deletes the folder you're in. Always run pwd first to check where you are, and never run rm -rf on ~, * or public_html unless you truly mean to wipe it.
Finding what's using your disk space
This is one of the most useful things you can do over SSH. From your home directory:
cd ~
du -sh * .[!.]* 2>/dev/null | sort -h
This lists every file and folder (including hidden ones) with its total size, smallest first, so the biggest are at the bottom. Then drill down into the largest folder and run it again:
cd public_html/wp-content
du -sh * | sort -h
Common space-eaters: old backup zips left in public_html, huge error_log files, cache folders, and the mail folder (email is managed separately -- see the Email Disk Usage guide rather than deleting mail files by hand).
To find individual files over 100 MB anywhere in your account:
find ~ -type f -size +100M -exec ls -lh {} \; 2>/dev/null
Finding files
| Command | What it finds |
|---|---|
find public_html -name "wp-config.php" | Files with an exact name. |
find public_html -iname "*.zip" | All zip files, ignoring upper/lower case. |
find public_html -name error_log | Every PHP error log across your site. |
find public_html -type f -mtime -2 | Files changed in the last 2 days. |
find public_html -type f -name "*.php" -newer public_html/index.php | PHP files changed more recently than your index.php. |
The "changed recently" searches are handy after a site problem: they show exactly which files were touched around the time things went wrong. If you find PHP files you don't recognize in upload folders, don't delete them blindly -- see the hacked-site guides in the related links.
Searching inside files
grep -rn "old-domain.com" public_html --include=*.php
This searches every .php file under public_html for the text and shows the file name and line number of each match. Useful variations:
grep -ril "text" public_html-- list only the names of matching files, ignoring case.grep "Fatal" public_html/error_log | tail -n 20-- the 20 most recent fatal errors.grep -c "PHP Warning" public_html/error_log-- count how many warnings there are.
For WordPress sites, don't use grep and sed to change your domain in the database -- use WP-CLI's wp search-replace, which handles WordPress's data correctly.
Zip and unzip
| Command | What it does |
|---|---|
zip -r site.zip public_html | Compresses a folder into site.zip. |
unzip theme.zip -d public_html/wp-content/themes/ | Extracts a zip into a specific folder. |
unzip -l theme.zip | Lists what's inside a zip without extracting it. |
tar -czf site.tar.gz public_html | Creates a compressed .tar.gz archive. |
tar -xzf site.tar.gz | Extracts a .tar.gz archive into the current folder. |
Always check where a zip will extract with unzip -l first. Some archives contain a top-level folder, some don't, and extracting in the wrong place can overwrite files.
Remember to delete large archives when you're done. Zip files left in public_html can be downloaded by anyone who guesses the name.
Fixing permissions
On our servers, files should normally be 644 and folders 755. To reset a whole site:
find ~/public_html -type d -exec chmod 755 {} \;
find ~/public_html -type f -exec chmod 644 {} \;
Then tighten your WordPress config file:
chmod 600 ~/public_html/wp-config.php
If 600 causes an error on your site, set it back to 644. Never use 777; it doesn't fix problems on our servers and makes your site easier to attack.
Checking what's running
ps ux-- lists your running processes, with a process number (PID) for each.kill 12345-- stops process 12345. Use it on a stuck script or cron job, never on something you don't recognize without checking first.php -v-- shows the PHP version the command line uses, which isn't necessarily the one your website uses (our Composer guide explains how to choose).
Common questions
How do I copy and paste in Terminal?
In cPanel's Terminal and most Windows terminals, right-click or use Ctrl + Shift + V to paste. On a Mac, Command + V works. Ctrl + C on its own stops a command rather than copying.
Can I undo a command?
No. There's no undo on the command line. That's why making a .bak copy first matters. If you delete something by mistake, restore it from JetBackup 5.
Why do I get "Permission denied"?
You're trying to read or change something outside your account, or a file's permissions don't allow it. Check the path, and check permissions with ls -la.
Why does my command say "command not found"?
Check the spelling. Some tools simply aren't installed in hosting accounts. If you need one for your site, open a ticket and tell us what you're trying to do -- there's often another way.
Related guides
- How to Use SSH, SSH Keys and Terminal in cPanel
- File and Folder Permissions Explained (644 and 755)
- How to Check Your Website Error Log and Recent Visitors
- How to Free Up Mailbox Space with Email Disk Usage
- What to Do If Your WordPress Site Is Hacked
- How to Restore a File or Folder with JetBackup 5
Still stuck? Open a support ticket and the Instant Access Internet Services team will help.
