Essential SSH – 19 Linux SSH Commands You Simply Cannot Live Without

More and more web hosting providers are offering SSH(Secure Shell) access to their customers now, if you are one of them, put this advantage to good use will make your online life a lot easier. Don’t worry, we are just going to deal with just a few more than 15 shell commands, pretty much those used most frequently, with the most favored switch options by most people.

We have assumed that you are normally computer- and internet- literate, at least aware of directories and files that facilitate the organization of data on computers, knowing what it is like to travel within a file system tree structure.

First off, you are to log in to the host with your SSH privilege by means of a SSH client, like Putty. Download and launch it on your local machine. The interface should look like this:

SSH client

Enter the host name or IP address supplied by your hosting provider in the Host Name box and click Open.

Supply your SSH account username and password so as to be logged in. Once acknowledged by the remote system, it is ready to accept your commands, and you should be in your home directory which can be referred to as ‘~’ or ‘/home/username’ (username here is a placeholder for your own SSH username) in SSH commands. Now let’s see in detail what you can do in this tiny terminal window.

  1. ls -o : List files and directories in the current directory. 
    ls -ao : List files and directories in the current directory, including hidden ones.
  2. cd [dir-path] : Change to, or change current directory to the directory indicated by [dir-path].
    cd ~ : Change to your home directory, which in most cases would be /home/yourusername.
    cd .. : Change to the parent directory of the current one.
    cd – : Change to the last directory you are in.
  3. pwd : Show the full path to the current directory.
  4. mkdir [dir-path] : Create an empty directory in the specified directory indicated by [dir-path].
  5. rmdir [dir-path] : Delete an empty directory in the specified directory indicated by [dir-path].
  6. rm [file-path] : Delete a file indicated by [file-path]. 
    rm -f [file-path] : Forcibly delete a file indicated by [file-path], that is, without having to confirm before deletion.
    rm -r [dir-path] : Delete a directory indicated by [dir-path] and everything underneath it.
    rm -rf [dir-path] : Delete a directory indicated by [dir-path] and everything underneath it, without having to confirm before deletion.
  7. mv [file-path]/[dir-path] [dir-path] : Move a file or directory indicated by [file-path] or [dir-path] to the directory indicated by the latter [dir-path]. 
    mv [file-path] [file-path] : Rename the file indicated by the first [file-path] to another indicated by [file-path]. Or. Move the first file to a different location and rename it as specified in the second [file-path].
  8. cp [file-path] [dir-path] : Copy the file indicated by [file-path] to the directory indicated by [dir-path]. 
    cp [file-path] [file-path] : Duplicate the same file indicated by [file-path] with another name indicated by the second [file-path]. Or. Copy the first file to another location and rename it as specified in the second [file-path].
    cp -r [dir-path] [dir-path] : Copy a whole directory including everything underneath it indicated by the first [dir-path] to another directory indicated by the second [dir-path].
  9. tar -zxf [file-path] : Extract all things in an archive extensioned with .tar.gz indicated by [file-path] to the current directory. 
    tar -xf [file-path] : Extract all things in an archive extensioned with .tar indicated by [file-path] to the current directory.
    tar -cf [file-path] ([file-path]/[dir-path], … ) : Create an archive indicated by the first [file-path] of the files indicated by [file-path]s or/and directories indicated by [dir-path]s.
  10. gunzip [file-path] : Decompress a zipped file extensioned with .gz to the current directory.
    unzip [file-path] : Decompress a zipped file extensioned with .zip to the current directory.
  11. chmod [xxx] [file-path]/[dir-path] : Change the privileges of a given file or directory indicated respectively by [file-path] and [dir-path] to xxx. 
    chmod -r [xxx] [dir-path] : Change the privileges of a given directory indicated by [dir-path] to xxx.
  12. more [file-path] : Display the content of the given file indicated by [file-path], one screen at a time.
  13. ln -s [file-path] [file-path] : Create a symbol link for the first file, so that everything you do to the symbol link, a.k.a the second fake file, is reflected to the real file, except for when you delete the symbol link, the real file remains intact.
  14. touch [file-path] : Create an empty file indicated by [file-path].
  15. du -sh : Show disk usage of the current directory. 
    du -sh * : Show disk usage of the current directory plus the statistics of all the files and directories underneath it.
  16. grep [text] [file-path] : Search the file indicated by [file-path] with the text in [text].
  17. mysqldump -h [hostname] -u [username] -p [password] [database] > [databasefile.sql] : Dump or backup the selected database on the selected host privileged by selected user identified by corresponding password to a SQL file. 
    mysql -h [hostname] -u [username] -p [password] [database] < [databasefile.sql] : Restore the data in a SQL file to the selected database on the selected host privileged by selected user identified by corresponding password.
  18. clear : Clear the screen so that you feel neat.
  19. exit : Terminate the SSH dialogue and close the Putty window.

Note: When something is specified in brackets, such as [file-path] or [dir-path], it is used to indicate that you must input your desired information here, which, in this case, are the path to a file or a path to a directory respectively. NO brackets in your command.

8 thoughts on “Essential SSH – 19 Linux SSH Commands You Simply Cannot Live Without”

  1. This is a great list that will make unsavvy *nix users’ life much easier.

    Maybe you could elaborate on zipping and unzipping things – I’m personally sick of those tangling switches.

    1. I usually use ‘tar cf tarred.tar files’ to tar files and ‘tar zcf tarred.tar.gz files’ to zip tar them.

      To untar, just use ‘tar xf tarred.tar’ or ‘tar zxf tarred.tar.gz’ to extract the files. Not quite familiar with zip / unzip.

  2. Great list! Perhaps you could include a warning for the ‘rm’ command? I’ve seen people ruin their installations with this one – I’ve nearly done it myself a few times…

  3. Pingback: Screw all those unusable proxy server lists - Build your own stable socks5 proxy server in minutes!

  4. Pingback: Linux wget Command to Download and Mirror a Website in Static Local Copy

  5. Pingback: How to know if your hosting provider is overselling on your server?

  6. Pingback: How to execute PHP scripts in the background?

Comments are closed.

Scroll to Top