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:
pwdcd (change directory) – move from one folder to another:
cd directory_name-
cd directory_name– go to this subfolder of the current folder -
cd ..– 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_whereNOTE
- To copy to a higher directory, insert the full path, starting from
homesee How to Copy Files or Folders Using SSH
mv (move) – same as cp, you may move both files and folders:
mv move_what move_wheremkdir (make directory) – create a new empty directory:
mkdir folder_nametouch – create a new empty file:
touch file_namermdir (remove a directory) – delete the folder:
rmdir folder_namerm (remove) – delete a file; you can mention several files at a time:
rm file_nameNOTE
rm -r– deletes folders, their subfolders, and their content. See How to Delete Files or Folders Using SSH
grep – find a specific text inside files:
grep -inrl 'text'find – find files with a specific name:
find . -type f -name 'name*.php'Check file and folder ownership
See how to check the files and folders ownership using SSH.
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
See how to create archives with SSH for more detail.
Manage databases
Import database file.sql to the database_username database:
mysql -u database_username -p database_name < file.sqlNOTE
- For this command, you should be in the folder where the
file.sqlis located. See How to Import a Database Over SSH
Export of database_username database to the file.sql file:
mysqldump -u database_username -p database_name > file.sqlNOTES
- For this command, you don’t need to create a file beforehand. See How to Export a Database Over SSH
-
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 "%hn" | cut -d/ -f-2 | sort | uniq -c | sort -rnShow the disk usage per each subdirectory and file of the current folder:
du -shc * | sort -rhNOTE
-
It can also be done in the file manager
Access your website’s root directory
See how to open the website’s root directory via SSH.
Manage WordPress websites
Purge WordPress cache
wp cache flush
wp litespeed-purge allReplace WordPress core files
rm -rf wp-includes
rm -rf wp-admin
wp core download --skip-content --forceOr:
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 .Troubleshooting
If you run into errors while using SSH, see how to solve the most common errors in SSH at Hostinger.
Additional resource