Basic Linux Commands for Managing Your Website over SSH

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.com in 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 rm is 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, images and IMAGES are three different folders.
  • Look before you act. Before deleting or changing files with a wildcard (*), run the same pattern with ls first to see exactly what it matches.
  • Make a copy before editing. cp .htaccess .htaccess.bak takes a second and can save your site.

Time-savers that make the command line easier

Key or commandWhat it does
TabCompletes a file or folder name. Type cd pub and press Tab to get cd public_html/. Press it twice to see all matches.
Up arrowBrings back your previous commands.
Ctrl + CStops the command that's running. Use it whenever something is taking too long or you made a mistake.
clearClears the screen.
historyLists the commands you've run recently.
command --helpShows the options for most commands, for example ls --help.

Moving around

CommandWhat it does
pwdShows the folder you're in ("print working directory").
lsLists files in the current folder.
ls -laLists everything, including hidden files like .htaccess, with sizes, dates and permissions.
ls -lt | headShows the most recently changed files first.
cd public_htmlGoes into your website folder.
cd ..Goes up one folder.
cd ~ or just cdGoes 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

CommandWhat it does
cat robots.txtPrints a short file to the screen.
less error_logOpens 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 fileShows the first 20 lines.
tail -n 50 error_logShows the last 50 lines -- the newest errors.
tail -f error_logKeeps 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 fileCounts 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

CommandWhat it does
mkdir backupsCreates a folder.
mkdir -p a/b/cCreates a folder and any missing parent folders.
cp wp-config.php wp-config.php.bakCopies a file.
cp -r public_html ~/site-copyCopies a whole folder and its contents.
mv old-name.html new-name.htmlRenames a file.
mv report.pdf public_html/files/Moves a file into another folder.
touch newfile.txtCreates 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

CommandWhat it does
rm file.txtDeletes one file.
rm -i *.logDeletes matching files, asking you to confirm each one.
rmdir emptyfolderDeletes a folder only if it's empty.
rm -r oldfolderDeletes 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

CommandWhat 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_logEvery PHP error log across your site.
find public_html -type f -mtime -2Files changed in the last 2 days.
find public_html -type f -name "*.php" -newer public_html/index.phpPHP 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

CommandWhat it does
zip -r site.zip public_htmlCompresses a folder into site.zip.
unzip theme.zip -d public_html/wp-content/themes/Extracts a zip into a specific folder.
unzip -l theme.zipLists what's inside a zip without extracting it.
tar -czf site.tar.gz public_htmlCreates a compressed .tar.gz archive.
tar -xzf site.tar.gzExtracts 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

Still stuck? Open a support ticket and the Instant Access Internet Services team will help.

Ultrafast LiteSpeed hosting from InstantAccess.net: free SSL, free backups, cPanel included, no contracts. Check out our $10/month hosting.
  • basic linux commands ssh, cpanel terminal commands, find large files ssh, du disk usage command, grep search files website, unzip file ssh, chmod 644 755 command, linux commands for web hosting
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Connecting to SSH

SSH gives you a secure command-line connection to your hosting account, for tasks like running...

How to use SSH

SSH lets you work on your hosting account from a command line -- faster than clicking through...

How to Create an SSH Key on Windows, Mac and Linux and Add It to cPanel

An SSH key lets you log in to your hosting account's command line without typing your cPanel...

How to Fix "Permission Denied (publickey)" and Other SSH Connection Errors

SSH error messages are short and cryptic, but each one points to a specific cause. This guide...

How to Transfer Files Securely with SFTP and SCP

SFTP and SCP move files between your computer and your hosting account over an encrypted SSH...