11
Oct
2010

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.

  1. Connect
  2. Change Directory
  3. List Files and Subdirectories
  4. Start,Stop and Restart Services
  5. Plesk
  6. Processes
  7. File System Commands
  8. Delete, Remove and Move Files
  9. File Permissions and Ownership
  10. Log Files
  11. Text Editors

Connect

General:
ssh user@server-ip

Change Directory

General:
cd /path/to/directory

Run as root user:
sudo cd /path/to/directory

Go one level up:
cd ..

List Files and Subdirectories

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 */

Start,Stop and Restart Services

General:
sudo etc/init.d/<service> start|stop|restart|status

For Apache:
sudo apachectl restart
or
sudo etc/init.d/httpd restart

Plesk

Retrive admin password:
cat /etc/psa/.psa.shadow

Processes

Process Viewer (ctrl + C to exit):
ps -a top -c

Process List:
ps -auxf

File System Commands

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

Delete, Remove and Move Files

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

File Permissions and Ownership

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

Log Files

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

Text Editors

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
Blog External Programming

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>