SSH access provides direct control over your hosting account through the command line. Below is a collection of useful Linux commands commonly used for website management, troubleshooting, backups, and server administration.
Table of Contents
wget
The wget command is used to download files directly to the server from a remote location.
Example:
wget https://example.com/file.zip
This is useful when downloading application packages, backups, or updates without first downloading them to your local computer.
uname
The uname command displays information about the operating system and kernel.
Example:
uname -a
This may include details such as the Linux kernel version, architecture, and operating system type.
touch
The touch command creates a new empty file.
Example:
touch page.html
You can also use it to update the modification timestamp of an existing file.
tar
The tar utility is used to create and extract archive files.
Create a compressed archive:
tar -czf backup.tar.gz public_html/
Extract an archive:
tar -xzf backup.tar.gz
Useful options:
| Option | Description |
|---|---|
-c | Create archive |
-x | Extract archive |
-t | Display archive contents |
-z | Use gzip compression |
-r | Append files to archive |
-f | Specify archive file |
tail
Displays the last lines of a file.
Example:
tail error_log
Display the last 20 lines:
tail -n 20 error_log
Monitor a log file in real time:
tail -f error_log
rmdir
Removes an empty directory.
Example:
rmdir old_directory
The directory must be completely empty.
rm
Removes files and directories.
Delete a file:
rm file.txt
Delete a directory and all its contents:
rm -rf directory_name
Be extremely careful when using this command, as deleted files cannot be recovered easily.
pwd
Displays your current directory path.
Example:
pwd
Output example:
/home/username/public_html
mv
Moves or renames files and directories.
Move a file:
mv file.txt backup/
Rename a file:
mv oldname.txt newname.txt
passwd
Changes the password of the current user or another user if permitted.
Example:
passwd
mkdir
Creates a new directory.
Example:
mkdir new_directory
Create nested directories:
mkdir -p backups/2026/june
ls
Lists files and directories.
Basic usage:
ls
Useful options:
ls -a
Shows hidden files.
ls -al
Displays detailed information including permissions, ownership, and file sizes.
ls -R
Lists files recursively through subdirectories.
man
Displays the manual page for a command.
Example:
man tar
This provides detailed documentation and usage examples.
history
Displays previously executed commands.
Example:
history
This can be useful when trying to repeat or troubleshoot previous actions.
head
Displays the first lines of a file.
Example:
head error_log
Display the first 5 lines:
head -n 5 error_log
find
Searches for files and directories.
Find a file by name:
find . -name "config.php"
Find directories:
find . -type d -name "cache"
Find files modified within the last 7 days:
find . -type f -mtime -7
grep
Searches for text within files.
Example:
grep "error" error_log
Search recursively:
grep -R "database" .
This command is particularly useful when troubleshooting websites or reviewing logs.
diff
Compares the contents of two files.
Example:
diff file1.txt file2.txt
The command displays the differences between the two files line by line.
cd
The cd command is used to change directories.
Move into a directory:
cd public_html
Move to a specific path:
cd /home/username/public_html
Useful shortcuts:
cd ..
Move up one directory.
cd ~
Go directly to your home directory.
cd -
Return to the previous directory.
Linux paths are case-sensitive, so directory names must be entered exactly as they appear.
cp
Copies files and directories.
Copy a file:
cp file.txt backup/
Copy a directory recursively:
cp -r public_html backup/
cat
Displays the contents of a file.
Example:
cat file.txt
Create a new file:
cat > file.txt
Combine two files into a new file:
cat file1.txt file2.txt > combined.txt
Convert text to uppercase:
cat file.txt | tr a-z A-Z > uppercase.txt
Summary
SSH provides powerful tools for managing files, monitoring logs, creating backups, troubleshooting applications, and maintaining websites directly from the command line. Familiarity with these commands can significantly improve efficiency when managing hosting services and web applications.