Top Most Common Used SSH Commands

For a newbies there are many questions when starting work on SSH common problem is you dont know how to connect what software etc etc. In this article i have put together Top Most Common Used SSH Commands used on linux shell, and organized them by name so you can easily find a command, their description and how to use it. This guide will continue to be updated and should not be considered a complete list of linux shell commands, but commands, I found, often used. If you would like to add to this guide, please post in comment below and i will add them in this post.

If you are really a newbie, then you should bookmark this page otherwise simply skip this post.

Requirements To SSH

  • A working SSH client like Putty (Windows) or Terminal (Mac and Linux)
  • A working Linux-based server with SSH enabled
  • A cup of coffee if you wish
  • A computer with stable Internet connection

Some Conventions

  1. Hit Enter or Return key on your keyboard after every each command / line
  2. Each line is a single raw of command unless specified otherwise
  3. Replace domain.com with your own domain name and TLD
  4. Replace xxx.xxx.xxx.xxx with IP address of your own server
  5. Replace example paths and file names according to your server information
  6. If a path ends with slash “/” then its a directory
  7. A directory: “/path/to/directory/” will always end with slash “/”
  8. A file: “/path/to/file” won’t have slash “/” in the end
  9. A file is not always having extension in the end of the file name

OK, so lets start with the most common commands to SSH you should know..

Navigating

1. How to move into another directory

Use command below to change directory

cd [another directory]

example: move to directory “download”

cd download

2. How to go to home directory

cd ~

3. How go to the last directory you were in

cd -

4. How to go up a directory level

cd ..

5. How to show the full path of the current directory

Use this command to find out where are you currently in.

pwd

6. How to list files and/or directories in a directory

ls (just type ls and hit enter)

7. How to list all files and information

ls -al

8. How to list all files ending with certain extension

ls *.ext

example:

ls *.php

9. How to list all files and folders with detailed information including file size

ls -alh

OutPut

drwxr-xr-x  3 example.com example.com 15 Oct 21 10:01 .
drwxr-xr-x  6 example.com example.com 6 Oct 21 09:13 ..
-rw-r--r--  1 example.com example.com  137 Oct 21 10:01 .htaccess
drwxr-xr-x  2 example.com example.com 4 Jun  8 17:24 errors
-rwxr-xr-x  1 example.com example.com  379 Jan 28  2010 hello.pl
-rw-r--r--  1 example.com example.com 45 Oct 30  2009 home.html
-rw-r--r--  1 example.com example.com 83 Oct 21 09:47 index.php
-rw-r--r--  1 example.com example.com 68 Jul 20 15:53 phpinfo.php

10. How to quit and exit SSH client

exit

File Management

11. How to copy and rename file

Use this command to copy and rename a file

cp [filename] [new filename]

example: we’ll rename banner.jpg to banner728px.jpg

cp banner.jpg banner728px.jpg

example: we’ll cope banner.jpg to a folder called “ads”

cp banner.jpg ads/banner.jpg

example: copying and renaming at once

cp banner.jpg ads/banner728px.jpg

ps: original file will remain, it is just copied.

12. How to move and rename file

Use this command to move and rename file

mv [old filename] [new filename]

example: moving a file to another directory

mv image1.jpg newlocation/image1.jpg

example: moving a file to another directory and renaming it at once

mv image1.jpg newlocation/image_new.jpg

ps: original file will be deleted as it was moved to another location

pps: you can also move a folder

example: moving “images” folder to “media” folder

mv images/ media

example: moving “images” folder to upper directory

mv images/ ..

13. How to delete / remove a file

rm [file name]

example:

rm image1.jpg

14. How to delete / remove all files in current directory

rm *

15. How to delete files with certain extension

rm *.extension

example: remove all files with .jpg extension

rm *.jpg

16. How to copy a folder with all files and folders in it

cp -r [directory] [new directory]

17. How to create new folder

mkdir [folder name]

example:

mkdir images

18. How to search for a file starting within current directory

find . -name [filename] -print

example: find a file called “image1.jpg” in current folder

find . -name image1.jpg -print

19. How to search for text within a file

grep [text] [filename]

example: find the word “include_once” in file index.php

grep include_once index.php

20. CHMOD – how to change file permission

chmod [permission type] [file/folder name]

example:

chmod 777 config.php

Available permission type: (below is not command)

First number is for the owner, second for the group, and third for everyone.
7 = Read + Write + Execute
6 = Read + Write
5 = Read + Execute
4 = Read
3 = Write + Execute
2 = Write
1 = Execute
0 = All access denied

21. SCP – how to to copy one or more local files up to a remote server

scp local_file(s) [email protected]:destination_directory

example of moving :

scp image1.jpg image2.jpg [email protected]:.
[email protected]'s password: <i>password</i>
image1.jpg 100%  122 0.1KB/s 0.1KB/s 00:00
image2.jpg 100% 14 0.0KB/s 0.1KB/s 00:00

example of moving directory:

scp -r images [email protected]:.
[email protected]'s password: password
bork.c 100%  388 0.4KB/s  22.0KB/s 00:00 swap2.c 100%  199 0.2KB/s  22.0KB/s 00:00 list.c 100% 1029 1.0KB/s  22.0KB/s 00:00 array.c 100%  536 0.5KB/s  22.0KB/s 00:00 foo.c 100%  122 0.1KB/s  22.0KB/s 00:00 acid.c 100%  446 0.4KB/s  22.0KB/s 00:00 blah.c 100%  112 0.1KB/s  22.0KB/s 00:00

 

Tags: