Essential Linux Commands To Get You Started

These essential Linux commands form the basis of your everyday work. It just makes sense to leverage these utilities as much as possible. 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 and Utilities

This is a starting list of essential Linux commands and utilities that I think are the most useful. Consider this as a reference with examples you can refer to. I use this myself whenever I forget something. 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

cd [will take you to the home of the current user you are logged in as]

Or

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

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

history [this will show you the history of successful commands]

Man

This stands for manual. It is easy to use and 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. For this reason its one of the essential Linux commands.

man grep [shows all the information on the grep command]

Then

man mkdir [shows all the information on the mkdir command]

Ls

ls [shows files in current directory]

Or

ls /Music [shows files in the music directory]

Or

ls -i /Music [shows detailed files in the Music directory]

This is one of the basic essential Linux commands because it 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

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

less songs.txt [this command lets you view a large file one page at a time]

Mount

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. Its one of the essential Linux commands because we often have to work with devices and this is one of the ways to do it.

Pwd

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

date [shows current date]

Then

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

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

This is a very useful and quite essential Linux commands. 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

rm error_log [removes a file]

Then

rm -r acdc [removes this directory and all subdirectories]

Then

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 another of the essential Linux commands you will want to use wisely.

Mkdir

This is also one of those essential Linux commands to know. It is used to make directories and has easy to remember syntax which will help. Mkdir is pretty self explanatory and 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]

Then

mkdir kiss acdc pantera soundtracks [makes different directories at the same time]

Cp

cp document1 document2 [copies a file from one location to another]

Then

cp -r folder1 folder2 [copies a directory from one location to another]

This is the copy command. It’s one of the essential Linux commands 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.

File

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

grep “jason” error_log [searches for any mention of the word “jason” in the file error_log]

grep “jason” * [searches for any mention of “jason” in any file under current directory]

Then

grep -r “jason” [searches for any mention of “jason” in any file in the computer]

This is one of the most important essential Linux commands and 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.

Tar

This becomes one of the essential Linux commands for you when you need to extract or pack 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

Monitoring your system is very important and should be done often. That is why this is an essential Linux command.

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.

Reboot

This little command shuts everything down and will restart your system. It is certainly quicker than using a mouse to go through a menu.

Lpr

This is also one of essential Linux commands and 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

Moving and renaming files is a very important task. That is why this is one of essential Linux commands.

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.

Sort

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

tail -f error_log [shows you the last portion of a file]

Then

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 one of the essential Linux commands.

Wc

This utility I wanted to mention is the word count command. It is a great Linux command for it is very useful at outputting information about a file. It does more than just words of course as 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

ps [this command shows us the process id’s that are running for the current user]

Then

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. Its one of the essential Linux commands because you will often have to look at what processes are running on your system.

Kill

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

Another of the essential Linux commands, changing permissions ona file is very important.

chmod +x song [allows any user to execute this file]

Then

chmod +r song [gives read permission to all users]

Then

chmod 755 song.txt [gives you full permissions and everyone else just read/execute]

Then

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

chown jmoore songs.txt [this will change the owner of the file songs.txt to the user jmoore]

Then

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

du [shows disk space in current directory]

Then

du -h [shows disk space in smaller increments]

Then

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

top [shows process id’s and resource utilization]

Then

top -u root [shows process id’s and resource utilization from the root user]

This is another of the most essential Linux commands and it gives you a lot of good information about your system. It is especially handy if you are trying to figure out why your system seems sluggish.

Uname

uname [gives you the operating system you are using. not entirely helpful as you probably knew you were running Linux]

Then

uname -a [gives you the operating system and version you are using. more helpful]

Gzip

gzip zipfile [compresses files to save storage or bandwidth]

Compressing files will be be very important. That is why this is one of the essential Linux commands.

Gunzip

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.

Conclusion

This list of the essential Linux commands 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.

Hi, I'm Jason Moore. I work for a school in it's IT department but in my spare time I love to blog about computer stuff, work on my garden, cook Indian food, and wrestle with my 6 year old(he always wins).