After connecting to your account via SSH, you will require to use commands to perform all the desired actions. Check the topics below for the most commonly used ones - you can also bookmark this page to have an SSH cheat-sheet at hand 😉
Manage Location
pwd (print working directory) – show the full path of the directory in which you currently are:
pwd
cd (change directory) – move from one folder to another:
cd directory_name
cd directory_name
– go to this subfolder of the current foldercd ..
– go one directory up
ls (list) – show the list of all files and folders in the current directory:
ls
ls -a
– include hidden files (which begin with a dot)
Manage Files and Folders
cp (copy) – you can copy both files and folders:
cp copy_what copy_where
To copy to a higher directory, insert the full path, starting from
home
mv (move) – same as cp, you may move both files and folders:
mv move_what move_where
mkdir (make directory) – create a new empty directory:
mkdir folder_name
touch – create a new empty file:
touch file_name
rmdir (remove a directory) – delete the folder:
rmdir folder_name
rm (remove) – delete a file; you can mention several files at a time:
rm file_name
rm -r
– deletes folders, their subfolders, and their content
grep – find a specific text inside files:
grep -inrl 'text'
find – find files with a specific name:
find . -type f -name 'name*.php'
Manage Archives
Create an Archive
Create an archive of specific files:
ZIP: zip new-archive-name.zip filename1.php filename2.php filename3.php
TAR: tar -cvf new-archive-name.tar filename1.php filename2.php filename3.php
TAR.GZ: tar -zcf new-archive-name.tar.gz filename1.php filename2.php filename3.php
Instead of new-archive-name
, type the name of the future archive and, after that, specify the exact files that should be included.
Create an archive of the whole folder:
ZIP: zip -r archive.zip DirectoryName
TAR: tar -cvf archive.tar DirectoryName
TAR.GZ: tar -zcf archive.tar.gz DirectoryName
Unpack an Archive
ZIP: unzip archive.zip
TAR: tar -xvf archive.tar
TAR.GZ: tar -zxvf archive.tar.gz
Manage databases
Import database file.sql to the database_username database:
mysql -u database_username -p database_name < file.sql
For this command, you should be in the folder where the
file.sql
is located
Export of database_username database to the file.sql file:
mysqldump -u database_username -p database_name > file.sql
For this command, you don't need to create a file beforehand
For both commands, in the next step, you should insert the database password
Check Inodes and Disk Usage per Directory
Show the inodes number for every subdirectory of the current folder:
find . -printf "%h\n" | cut -d/ -f-2 | sort | uniq -c | sort -rn
Show the disk usage per each subdirectory and file of the current folder:
du -shc * | sort -rh
It can also be done in the file manager
Manage WordPress Websites
Purge WordPress Cache
wp cache flush
wp litespeed-purge all
Replace WordPress Core Files
rm -rf wp-includes
rm -rf wp-admin
wp core download --skip-content --force
Or:
backup=WP_`date +%s` && mkdir $backup && mv wp-admin $backup && mv wp-includes $backup && mv *.php $backup && wget https://wordpress.org/latest.zip && unzip latest.zip && rm -rf wordpress/wp-content && mv wordpress/* . && cp -rv $backup/wp-config.php .
Additional Resources