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!
Dnf -y upgrade –refresh
Dnf -y install dnf-plugin-system-upgrade
Dnf -y system-upgrade download –refresh –releasever=29
Dnf -y system-upgrade reboot
Developing in C++
This is useful when you want to develop in C++ from your workstation.
Install —- Dnf -y install gcc-c++
Build —- g++your_source.cpp -o your_binary
Build example —-g++ test.cpp -o test
Running your build—- ./your_binary
Running example —-./test
Manual —- man g++
Dnf grouplist [to look at desktops available]
Then you use one of the desktops available for your distribution.
Dnf groupinstall “Mate Desktop”
Dnf groupinstall “Xfce Desktop”
(can’t use swapfile on btrfs)
Swapon -s [to see your current swap space]
Fdisk -l/dev/sda1 [to check that the partition is marked for swap]
Fdisk -t/dev/sda1 [alter the partition to make it swappable. You will lose any data on this partition if you do this]
Mkswap/dev/sda1 [prepare the partition]
Swapon/dev/sda1 [activates this swap space]
Dd if=/dev/zeroof=/swapfile bs=1024 count=1048576 [This will create a swapfile of 1gb, specify in kb. For modern systems use swap size double your memory]
Mkswap/swapfile [prepares the swap file just like you would a partition]
Swapon/swapfile [mount it ]
dd this line to your /etc/fstab file using a text editor. /swapfile none swap sw 0 0
Swapoff/dev/sda1 [turns off your swap partition]
In your /etc/fstabfile comment out the line that has swap sw in it. Use a # in front to comment out
Chmod 600/swapfile [You should set your swap file permission to 600]
dnf install stratis-cli stratisd [install]
Stratis pool createmypool /dev/vdg [create your pool]
Stratis fs createmypool myfs1 [create filesystem]
Stratis fs snapshotmypool myfs1 myfs1-experiment [create filesystem as snapshot of an existing system]
Umount myfs1 [unmount the myfs1 pool]
Stratis fs destroymypool myfs1 [destroy themyfs1 pool]
Stratis poollist [listing pools on the system]
Stratis fs listmypool [listing filesystems within a pool]
Stratis blockdevlist mypool [list the blockdevs that make up a pool]
dnf install-y dnf-automatic
Now you need to edit the /etc/dnf/automatic.conf file to do what you want.
Generally I change the following fields from their default values to this.
apply_updates = yes
emit_via = email
email_from = [email protected]
email_to = [email protected]
email_host = your.smtp.server
Optionally, edit the timer frequency. I leave it at the default of 1 day.
Then Enable the timer.
systemctl enable dnf-automatic-install.timer
Then you can list the time to see the status
systemctl list-timers –all
Rsync -avzP /source-directory /destination-directory [copies entire directory to another directory]
This is one of the very essential Linux commands as it is used for backups and in bash scripts a lot.
Crontab -e [edit crontab entries]
Crontab -l [List or manage the task with crontab command with the -l option for current user]Crontab -u jason -l [list scheduled cron jobs for user jason
Crontab -r [remove crontab entry]
Crontab -I -r [prompt before deleting a crontab]
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 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]
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 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 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. 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.
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 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 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 another of the essential Linux commands you will want to use wisely.
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]
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 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.
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 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.
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.
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.
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 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.
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.
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 one of the essential Linux commands.
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 [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. Its one of the essential Linux commands because you will often have to look at what processes are running on your system.
- 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.
Another of the essential Linux commands, changing permissions ona file is very important.
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 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 [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]
Compressing files will be be very important. That is why this is one of the essential Linux commands.
- 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 is another of our essential Linux commands that uses the sftp protocol for transferring files over a network. 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 is one of those essential Linux commands that 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]
Working with disks is a common occurance. So Fdisk is also one of those essential Linux commands you will want to be familiar with.
At [Command :] use the [p] option to get the overview of the hard disk at any time.
At [Command:] use the [d] to delete existing partitions.
At [Command:] use the [F] to list free space.
At Command: use the [n] option to create a new partition.
Partition type p is for primary and e is for extended. Use default for sectors unless you have reason to change them.
Use [w] option to write changes to each device.
If you are going to use raid on Linux then MDADM is one of the essential Linux commands you will want to work with.
mdadm -D /dev/md0 [check status of raid device]
mdadm -r /dev/md0 /dev/sdb2 [remove selected raid device on selected disk]
mdadm -a /dev/md0 /dev/sdb2 [add new raid device to selected disk]
mdadm /dev/md0 –stop [stops the raid device]
mdadm /dev/md0 –assemble [starts the raid device again]
umount -l /dev/mdX [to dismantle a raid array]
mdadm –stop /dev/mdX
sudo mdadm –zero-superblock /dev/sdX
sudo mdadm –zero-superblock /dev/sdY
dnf install @virtualization
systemctl start libvirtd
systemctl enable libvirtd
lsmod | grep kvm [To verify that kvm properly loaded. You are looking for either kvm_intel or kvm_amd]
firewall-cmd --permanent --add-port=9090/tcp
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.