The whole advantage you could say with Linux is the power and freedom it gives you. With its software repositories and command line environment you can make your computer behave the exact way that you want. You do not have to rely on any other company to allow your computer to run right. This is the importance of Linux and it is why we learn the commands and the way it works.
Linux utilities are the heart and soul of the operating system. They do more than anything in a graphical environment can. For any utility you can see all of its options by using the man command with any utility. So just open a terminal and try them out. Feel free to experiment too.
Essential Linux Commands
This is a starting list of essential Linux commands that I think are the most useful. Consider this as a reference with example you can refer to. There are a lot of commands so is almost impossible to remember them all and how to use them. I hope this article helps and keeps your work moving!
- cd [will take you to the home of the current user you are logged in as]
- cd /Music [will take you to the Music directory]
This is a great essential Linux command. It has a lot of versatility. More importantly, though, it helps you move around in the file system. Here I did [ls] to start with so you could see where I started. Then I decided I wanted to go to my [Documents] directory. All I do then is enter the path there separated by slashes. Then I wanted to go up one folder. The way to do that is [cd ..]. That will take you up 1 directory level. I then used [ls] to see where I was. Lastly I wanted to take a look at my [Music] directory to see if I had uploaded any music yet. I had not alas.
- clear [clears the screen completely]
This is a simple but useful utility. It lets you clear your current window of activity. Sometimes you might have a need to only show certain things in your terminal. This will reset you quickly. I used it several times when writing this post because I did not want my terminal to be cluttered.
There are so many commands in Linux that sometimes it is hard to keep track of what you have done. This is not a huge issue but it comes up from time to time. If you have had a very long terminal session going then you will have a screen full of commands and output from those commands. So occasionally you might just want to clean things up. That is what this command is for.
- history [this will show you the history of successful commands]
This stands for manual. It is quick and easy to use. It is also the help system for Linux. It not only helps you but will give you more information that you could imagine. Any time you question how to use any utility or feature just use it with the [man] utility.
- man grep [shows all the information on the grep command]
- man mkdir [shows all the information on the mkdir command]
- ls [shows files in current directory]
- ls /Music [shows files in the music directory]
- ls -i /Music [shows detailed files in the Music directory]
This essential Linux command displays information about files. It will work on a single file or multiples if used as an argument. There are a variety of ways to using it. It is one of the basic Linux utilities that everyone uses. Check what directory your in or what files and sub directories are available. Ls has a couple options, -a and -d . The -a option lists everything in the directory. The -d option displays the sub directories.
My favorite option is the -R. It outputs hierarchies of everything there. This is especially useful. The last option I wanted to mention is the -s one. It stands for size. It is always useful knowing the size of a file you are working with for a variety of reasons. Of course you can also combine these options using 2 or more. The files in white are data and the files in blue are directories.
- cat error_log [shows the contents of a file]
This utility displays a file and its contents. It is the simplest of the utilities. Its arguments are any files you want it to join or view. There are options available depending on your needs. One of the most useful is numbering the lines.
- less songs.txt [this command lets you view a large file one page at a time]
- mount /dev/usb /mnt/usb [this will make the file system of the usb device available in the folder /mnt/usb]
This command will allow you to see the contents of the usb device that is plugged into your system.
This describes your present working directory. While there is not a lot to this utility, it can still be helpful.
- pwd [shows you the current working directory]
- date [shows current date]
- date 03081114 [sets the current date to March 8 11:14 am 2018]
This command displays the current time and date on your system. It will label the current timezone too so you know what you are getting. There are a couple options you can use but the main one is [utc]. It is used like this, date -u.
- cal [shows a mini calendar in the terminal]
This is a handy little Linux utility. It shows the month in day form while highlighting the current day. Not much more to be said for this but when your in a hurry and do not want to close window or switch to another one this can give you the information quickly that you need. It is just a 3 letter command so it is quick.
- sudo nano [gives yourself superuser privileges to run the nano editor]
This is a very useful and quite essential Linux command. It allows one to have superuser privileges on a case by case basis. This is important because you will generally have to think about what you are doing while using this. If you run as root all of the time then you will forget the ramifications of your actions at some point and make some drastic mistakes.
- rm error_log [removes a file]
- rm -r acdc [removes this directory and all subdirectories]
- rm -f error_log [removes a file forcefully]
This command is what is used to remove files. You should be especially careful of this and double check. As always do not be in root to work with your system unless you have to. A single command done wrongly can wipe out multitudes of files. There are options with this Linux utility also. The -f option will force the files to be deleted even if you do not have sufficient privileges. Please be careful if you ever use it. The -r option will recursively delete directories and everything in them. This is an essential Linux command you will want to use wisely.
This is also an essential command to know. It is used to make directories. It has easy to remember syntax too which will help some. It is pretty self explanatory. It has a bunch of options so look at the manual page for them if you are curious or have a need.
- mkdir downloaded_music [this makes a directory with the name given]
- mkdir kiss acdc pantera soundtracks [makes different directories at the same time]
- cp document1 document2 [copies a file from one location to another]
- cp -r folder1 folder2 [copies a directory from one location to another]
This is the copy command. It’s an essential Linux command that you will use often. It will copy files or directories to whatever location you designate. There are many options available. For a full list just use [man cp] in a terminal. I will go over the ones I think are most important. The -a option is for archiving and tries to preserve permissions. The -r option is again for recursively copying directory contents over to another directory.
As you can see I did a [ls] command to show the current contents. Then I used [cp] with the -ra options to make a new file with a new name. Then I did another [ls] command to show that it did work.
This is a quite useful utility. When working in a command line environment it is sometimes harder to know what a certain file is. This command will give you details of the file argument without having to resort to using a gui. It gives important details of whatever it is. The arguments will be the file you want information of. As you can see it says whether it is text or a directory. I also showed that you can have multiple options per line. It gives a nice output in the order that you asked.
- grep “jason” error_log [searches for any mention of the word “jason” in the file error_log]
- grep -i “jason” error_log [same search but ignores the case of “jason”]
- grep “jason” * [searches for any mention of “jason” in any file under current directory]
- grep -r “jason” [searches for any mention of “jason” in any file in the computer]
This essential Linux command is the foundational search command. It is the most useful one in my opinion so it pays to know it well in how to use it. It can search in 1 or multiple files at once. You use it to look for strings of text that will identify something you are looking for. Its first argument is the pattern you are looking for. The you direct it where to look for that pattern at. There are various options for using this.
The -c option lists all the files it finds a match in and then displays how many matches are in that file. This is useful for relevancy. The -color option will output any matches in color on your screen to make it easier to see what has been found. The -w option will look for any word that you use as an argument. This is also very useful.
This essential Linux command is used for extracting or packing files. Many times when you download something off the internet it will be in a version like this. Just use this utility to unpack it.
- df -h [this shows your disk space]
This is a very useful Linux utility. It will give you the amount of free disk space on your system. Quite useful for monitoring how fast your hard drive is filling up. it gives some very nice information. It is always a good idea to watch this.
This little command shuts everything down and will restart your system. It is certainly quicker than using a mouse to go through a menu.
This command is how you print from the command line. It works by sending the file to be printed to the print queue. It is done this way so other users on the system can print as well. The queue then just prints in the order it gets the requests from. The arguments are the path names or just a file to be printed if it is from the current directory. Various options are available. The -r option will remove a file to be printed. The -#n option will print however many copies that you designate.
- mv file1 file2 [renames file1 to file2]
The move command does what it says. It will move a file to another location. Be careful as this can delete files and you will lose their contents if done wrong. The arguments of this Linux utility are the path and filenames to be moved and location to where they are to moved to. The most useful option here is the -i option because it will ask you to confirm when overwriting a file.
The sort utility is very useful when looking at a list of directories or files. You can use it to sort and merge files. Its arguments are the file or files to sorted or merged. There are options, of course, but if used without any options then it will sort alphabetically. To merge, just use the 2 things to merge as arguments and their contents will be merged and sorted. The -n option will sort in numeric order if you have a list of numbers somewhere.
Another useful option is the -o option with an argument of a filename to be created and the information stored into. It will not send to your screen then but to a file that you designate. The -r option will sort in reverse. It works with either non-numeric or numeric characters. This is a very useful command if you have any data that needs to be sorted. It is a very useful Linux utility.
- tail -f error_log [shows you the last portion of a file]
- tail -30 error_log [shows you the last 30 lines of the error_log file]
The tail Linux utility will output the last 10 lines of a file to your screen. This is useful when you need to quickly know the contents of a configuration file. The best option it has is for adjusting how many lines you want it to count. The default is 10 but if you use -8 and then your filename then it will output the last 8 lines of your file. In this example I was curious about what this log file was about.
If you have ever opened up a big log file before then you will know what I mean. It can take forever to get to the end or even the middle of the file. That is where this essential linux command comes in handy. As you can see I just asked for the last 20 lines. It saved me a bunch of time. It is truly an essential Linux command.
This utility I wanted to mention is the word count command. It is a great Linux command. It is very useful for outputting information about a file. It does more than just words of course. It can count lines and size as well. This is all very interesting too. Without any options it will put on screen the number of lines, words, and bytes in a file. Its arguments are the file or files to be analyzed.
It can do multiple at once and then analyze both at once. Its options are ways of controlling its output. The -l option will only show the number of lines in a file. The -m option will show only the bytes. Lastly, the -w option will show only the number of words in that particular file. As you can see I analyzed [alpha] and [small_file]. It then gave me a total between the 2 files.
- ps [this command shows us the process id’s that are running for the current user]
- ps -al [shows us the process id’s that are running for all users]
The Linux file system has many processes running at once. It is these processes that allow you to do things useful on your computer. You can see i do not have a lot running right now. Most of you will be using more at once than I am now. Pay attention to that [PID] number. That is how you identify any process.
- kill -9 1012 [this command will kill the process ID 1012]
This is a very useful Linux utility. It goes well with the above mentioned [Ps] command. If you ever get a process that is not responding or that you just need to get rid of then use the [Kill (PID number)]. As you can see above everything has a PID number. If something is not working correctly then you can use this command to end it.
- chmod +x song [allows any user to execute this file]
- chmod +r song [gives read permission to all users]
- chmod 755 song.txt [gives you full permissions and everyone else just read/execute]
- chmod 777 song.txt [gives everyone full permissions on the file]
This is how you change permissions. Linux has a very flexible permission system. It is good to understand what is happening even if you are just a user. This command deserves its own article soon. That is how in depth and valuable it is. I will get an updated version up soon.
- chown jmoore songs.txt [this will change the owner of the file songs.txt to the user jmoore]
- chown -R jmoore downloaded_music [this changes the owner of the folder downloaded_music and all subdirectories to the user jmoore]
This goes right with [Chmod] as it is used to change the ownership of a file.
- du [shows disk space in current directory]
- du -h [shows disk space in smaller increments]
- du -h pantera [shows disk space used by the directory pantera]
This is handy because it will show you what is using your disk space. It can give information about either files or directories. You can also choose whether you want detailed information or not.
- top [shows process id’s and resource utilization]
- top -u root [shows process id’s and resource utilization from the root user]
This command gives you a lot of essential information. It is especially handy if you are trying to figure out why your system seems sluggish.
- uname [gives you the operating system you are using. not entirely helpful as you probably knew you were running Linux]
- uname -a [gives you the operating system and version you are using. more helpful]
- gzip zipfile [compresses files to save storage or bandwidth]
This utility will compress a file or group of files.
- gunzip file1 [extracts the files after they have been previously compressed]
This is a good utility to have. You will see many files that have been compressed. Use this to see the information.
- sftp [email protected]_server
This command uses the sftp protocol for transferring files. It is secure by nature and much better to use than the older ftp protocol.
- more error_log [shows the contents but allows you to go through the contents slowly]
This is very useful if you have a large file. It will allow you to navigate through the file slowly.
- scp file.html [email protected]:/path to folder [this will upload a file to a folder on your server.]
If you have a website, for example, this command will let you put a new page or some customizations up to your server.
- passwd [this is how you change your password. you will then be prompted twice to enter in the new one]
- exit [this command will end your shell session that you are in]
- logout [this will log you out of the computer you are on]
This is a list of the utilities that I find the most useful. There are many other ones of course and soon I will try to cover more of them. If you know these though they will give you a great start in learning how to navigate and control the various processes that you do on a daily basis in any Linux system. For more information on any particular command you can use the man page for that utility.