Top 10 Linux Commands You Should Know About

As Linux is used by majority of webmasters for hosting service as well as people who are trying to learn Linux, I will try to narrow down the vast list to top 10 commands in Linux that are most useful and are widely used. Linux is pretty simple to use and there are literally millions of posts, articles, blogs, forums and other relevant materials out there which can guide you to get started with Linux as well as solve problems in later stage. It is surely not as user friendly as XP/Vista/7 but it is definitely more secure and efficient than them. If you have not yet tried your hands on Linux yet then I would suggest you to go download (YES! Its FREE) and install a Linux copy and try it.

So getting back on to the topic, the top 10 list goes as follows:

Top #1 – top

If you are a professional webmaster you already know what I am talking about. If you are new to this field or do not know about how it works then continue reading.

Top command is basically used to check the server load and memory usage. It also specifies which application (service in Linux) is using how much memory. If your server (system) is lagging or running slow then you can stop that particular service or restart it for better performance.

The syntax for using this command is:

$ top

Just enter the command and hit enter, you will see output as follows (obviously your interface might be different but the output remains the same for further examples as well):

Top #2 –  cd

As the name of the command suggests, cd stands for change directory. You can enter the command in the terminal followed by the relative path or the absolute path of the directory. You can then get the access to that particular directory as per your command. For e.g. to access the /home/admin directory, you must use the command as follows:

$ cd /home/admin/

if you are already in the /home directory then you can also use the relative path as follows:

[root@vps home] # cd admin/

Both the commands will take you to the same location. But when using relative path do make sure that you are in the correct directory and executing a proper command.

Top #3 – vi

If you do not have a user interface (as in case of VPS) or if you are unaware of other editors such as nano, then “vi” is the command to go about. vi command is used to edit files in Linux. vi followed by the filename (relative path) or the exact path to the file (absolute path) will open the editor where you can edit the file in Linux. There are various commands you can use once you start editing the file. To quit without saving the file Press Esc followed by :q and hit enter. To quit with saving changes made to the file Press Esc followed by :wq. To start typing or editing the file press i. To find some text in the editor, Press Esc followed by / searchtexthere and press enter. If there are multiple occurrences of text then you can keep pressing N to find the next occurrence. It comes with Linux by default and if you plan to work on Linux for most of the time then you must get the hang of it as soon as possible since you may not find your favorite text editors everywhere.

Usage example:

$ vi file.txt

OR

$ vi /home/admin/file.txt

Top #4 – mkdir

The command mkdir stands for “Make Directory”. You can create a directory with this command. Just enter the command mkdir  followed by the directory name to create the directory in the current location. You can also mention the absolute path to the directory to create one from any location in the terminal.

Usage example:

$ mkdir nimishprabhu

OR

$ mkdir /home/admin/nimishprabhu

Top #5 – chmod

Logged in as an user other than root? Getting an error like “Permission Denied”? Most likely it is a permission issue. For servers you get errors such as “Forbidden Access” when the permissions are not set properly. Just use the chmod command to edit the permissions of file or directory.

Usage Example:

$ chmod 777 mydirectory

OR

$ chmod 777 /home/admin/file.txt

Make sure you have the permission to change permissions at first! If you do not know what I am talking about, just login as root and execute the commands.

Top #6 – wget

How often we need to download things from the internet. wget is the best thing happened to Linux users to download files on Linux. If you are unaware about this command here is how it works:

$ wget http://www.nimishprabhu.com/top-10-linux-commands-you-should-know-about.html

This will download the html file of this page on your hard disk. But wait, this is not it. wget provides you with many features which you research on the internet. You can rename the file after download. You can download bulk links together by providing a file (text) containing links etc. You should definitely read more about wget if you believe that it is just used to download files. There’s more than that in wget!

Top #7 –  ls

The command actually stands for “list” which means “list the files in  the directory”. But you can additionally provide certain parameters to enhance the output of the command. For example, ls command just shows you the names of the files in the current directory but if you use the command ls -l then it also displays the permissions, size, date (last modified) and owner of the file along with the names.

Top #8 – rm

Remove is the what is meant by the rm command. It is used to delete files in Linux. The command works in a similar fashion as most of the others. You must specify the file name or the folder name to the command and it will remove it.

Simple usage:

$ rm file.txt

OR

$ rm /home/admin/file.txt

But this will ask you to confirm delete the file or not? You need to Press Y to confirm.

If you want to “forcefully” remove files without having being asked for confirmation, you can use the parameter.

Usage example:

$ rm -f file.txt

This will delete the file without asking for confirmation. But make sure you are deleting the correct file as this action cannot be undone.

The best part of rm command is that it supports wildcards as well. So you can choose to delete the entire files in the given folder

E.g.  First browse to that particular directory and then execute:

$ rm *.*

OR

$ rm /home/admin/mydirectory/*.*

To recursively delete all files and folders in a particular folder use the command:

(Relative Path, use with caution)

$ rm -rf mydirectory/

OR

(Absolute path)

$ rm -rf /home/admin/mydirectory/

This will delete all the files and folders along with the folder “mydirectory” located at “/home/admin”.  stands for recursively deleting files and folders in sub folders.

Top #9 – zip/unzip

There are certain times such as taking backups or sharing your files with friends when you desire to zip the entire folder or certain files. Correspondingly at the other end, you might need to extract them to use it or store conveniently. You can use the zip and unzip commands for compressing and decompressing the files respectively.

Zip command works as follows:

$ zip filesbackup.zip 1.txt

OR (to zip all files)

$ zip filesbackup.zip *

To recursively zip all the files and folders in a particular folder you can use the command:

$ zip -9 -r folderbackup.zip mydirectory

Here “folderbackup.zip” is the relative path of the zip file where you want it to be created and “mydirectory” is the relative path of the folder to zip recursively. 9 and r parameters work to zip recursively. You can also mention the absolute paths as usual:

$ zip -9 -r /home/desktop/folderbackup.zip /home/admin/mydirectory

This will zip the entire folder “mydirectory” and store it on “desktop” as “folderbackup.zip”.

Top #10 – man

This is actually not the most widely used command, but this is certainly the command you must know when working on Linux. “man” stands for “manual” that is the help page for particular command. The command is used by typing man followed by the command name you want to know about. You can especially use this command to know more about the 9 commands mentioned above this. You will then realize how I learnt everything and how to use the man page. If you are a good reader and you don’t mind reading lots of not so useful text to find something that would suit you then man is the command to go. It specifies everything about a particular command. You can just read over the top man pages for various commands and then you will get a fair idea of how it works. Here’s a quick look at “top” command’s man page, which I got by executing the command:

$ man top

Hope this article was helpful and you learnt new things from it. If you need any kind of help with any of the above commands or any of other Linux commands, post a comment below and I will get back to you with the solution.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.