I’ve always wanted to put those nifty shell commands I’ve been collecting over the years all together in one place.
So finally here it comes…
Please note some of these may not run on all hosting solutions.
- Connect
- Change Directory
- List Files and Subdirectories
- Start,Stop and Restart Services
- Plesk
- Processes
- File System Commands
- Delete, Remove and Move Files
- File Permissions and Ownership
- Log Files
- Text Editors
General:
ssh user@server-ip
General:
cd /path/to/directory
Run as root user:
sudo cd /path/to/directory
Go one level up:
cd ..
General:
ls /path/to/directory
List with permissions in human-readable sizes:
ls -alh /path/to/directory
List the contents of your home directory:
ls ~
List the contents of your root directory:
ls /
List the contents of the parent directory:
ls ../
List the contents of all sub directories:
ls */
Only list the directories in the current directory:
ls -d */
General:
sudo etc/init.d/<service> start|stop|restart|status
For Apache:
sudo apachectl restart
or
sudo etc/init.d/httpd restart
Retrive admin password:
cat /etc/psa/.psa.shadow
Process Viewer (ctrl + C to exit):
ps -a top -c
Process List:
ps -auxf
Check total disk usage:
df
Check free disk space:
df -h
List folder sizes:
du -hs
List folder sizes greater than 1GB:
du -hs | grep G
List all subfolders/sizes:
du -sh
Force delete:
rm -vf
Force delete folder, subfolders and files:
rm -vrf
Remove directory:
rmdir
Move files:
mv filename.abc /newpath/filename.abc
Create empty file:
touch filename.abc
Change permission of files:
chmod 000 filename.abc
Permission digits meaning:
The 3 digits stand for Owner, Group, Public
Permission codes meaning:
7 = Read + Write + Execute
6 = Read + Write
5 = Read + Execute
4 = Read
3 = Write + Execute
2 = Write
1 = Execute
0 = All access denied
Change ownership:
chown user:group filename.abc
List 100 last entries in Main error log:
tail -n 100 /var/log/messages
Apache error log:
/var/log/httpd/error_log
Apache per domain error log:
/home/httpd/vhosts/mt-example.com/statistics/logs/error_log
MySQL logs:
/var/log/MySQLd.log
Mail logs:
/usr/local/psa/var/log/maillog
My favourite text editor is Nano:
sudo nano /path/to/filename.abc
Installing Nano:
sudo apt-get install nano
Vi:
sudo vi /path/to/filename.abc
Useful SSH Commands
I’ve always wanted to put those nifty shell commands I’ve been collecting over the years all together in one place.
So finally here it comes…
Please note some of these may not run on all hosting solutions.
Connect
Change Directory
List Files and Subdirectories
Start,Stop and Restart Services
Plesk
Processes
File System Commands
Delete, Remove and Move Files
File Permissions and Ownership
Log Files
Text Editors