Top 20 Commands Every Linux User MUST KNOW

Top 20 Commands Every Linux User MUST KNOW
17 min read
4 years ago

Today, I'll be sharing with You 20 commands that will allow you to get a power-packed experience out of Linux.

Linux desktops come with evolved desktop environments now and there's less need than ever to use the terminal, but the terminal is still the most powerful interface for Linux. Cybersecurity, hacking, forensics, and other forms of advanced computing require that you have a sound knowledge of Linux commands. Terminal opens up a whole new world of infinite possibilities. During my earlier days, I always refrained from using the terminal. I loved the GUI. But later on as I started using the terminal more often, my knowledge grew and I started enjoying Linux in a way I never did before. The terminal is where you see the real power of Linux. The terminal allows you to do things that are not even possible with a graphical interface. In this article, we'll be going through 20 commands that every Linux user must know and... How to use these commands in real-life situations.

This is a beginner-friendly article so it will also help you get started with the terminal if Your new to all this.

Command ls

Starting off, we have list on number 20. ls or list is a simple but a very useful command that displays the content of a particular folder or directory, but that's not all, ls can be used to get advanced info such as to check if your friend changed anything in your personal folders.

Open up a terminal and type in ls and hit enter. you can see that the contents of your home directory are displayed here. You can open a terminal in some other location and try out the same command. You can see hidden files and folders, that are not visible in the file explorer by typing in  ls -a  And  ls -c will sort and displays folders in an order in which they were modified, particularly useful when you lend your laptop. If you play around with Linux, knowing how to use this command will be very useful in case you break something and the graphical interface fails to start.

Command cd

We need a way to navigate around different folders just like we are doing here in the file manager. For this, we will be using the cd command which of course stands for change directory.

Right into it, type cd and type in the name of the folder you want to open. Type in the first few letters and press the tab button to autofill the entire name. Hit enter.

To move out of a folder back to a level up, type in cd .. and hit enter.

There are two ways of using the cd command, You can either use the relative addressing, which is the above method where you type in where you want to go, from where you are. Or You can type in the full address of a location directly from root. This kind of addressing begins with a / (slash) and then you type in where exactly a particular folder is. This is known as absolute addressing. It's like the postal address whereas the first one is where you're helping someone get to point from where you are. Make sure to use the tab button to autofill the file or folder names.

Command mkdir

Next up, we'll be creating a directory or a folder. Browse to the location where you want to create a folder. Then open up a terminal and type in mkdir space and the name of the folder you want. Hit enter. You can see that a new folder or directory is created here.

Command rmdir and rm

To delete a folder, we are using rmdir followed by the folder name. This command is rather limited and it deletes only completely empty directories. To delete directories with all their subdirectories and files use rm -rf space and the directory name you want to delete. So yeah, normally, to delete stuff, you can use rm -rf. Just be careful with this command though.

Command pwd

Absolute address is like the postal address of a directory, it's unique and you can get to it from anywhere. It also tells you where exactly the terminal is open in the file system. To see the absolute address of the working directory or the folder, type in pwd, which stands for print working directory. It's a simple and informative command. Everything comes with a manual. So do Linux commands. Linux commands are extremely malleable. What I mean by that is, you can use these commands in many ways, and this allows you to customize commands to suit the need at hand.

Command man

man command opens up these manuals. Type in man and then the command name. You have a brief description, what the command does, how to use the command and various options that the particular command supports.

Command clear

When You run some commands in the terminal, the screen real estate starts filling up with data and it can all get jam-packed with text here. So to clear all the mess away, you can use the clear command. Type in clear. Hit enter. That's easy to remember.

Command cp

Next up, we'll be seeing how to copy a file from one directory to another. This is very important because when dealing with operating system files, you need to use this command itself as copy-pasting protected files using the file manager will not be permitted. The cp command copies and pastes files and folders. To copy a file, open a terminal in the folder where the file that you want to copy is, then type cp, space and put in the name of the file you want to copy. You can even use absolute addressing, then leave a space and type in the location you want to the file to be copied to. Hit enter. To copy a folder, you follow the same structure, but you add -avr after cp and before the folder name you want to copy.

cp command is of great use when you're repairing or configuring your Linux computer.

Command mv

To move files, we use mv command. It encompasses both cut and paste. Its usage is as follows, type mv in a terminal, leave a space and type in the name of the file you want to move. Then leave a space and put in the destination of the file. You can see the file being moved here, as soon as you hit enter. You can use either absolute addressing or just the relative addressing. You can even move all the contents of a directory using this command.

Command cat

cat command displays the content of a text file, right then and there, in the terminal itself. It's a much faster and safer way of opening text files for read-only purposes. Not many days ago, I was trying to repair my server configuration file by comparing it side by side with the original backup, both opened in the Gedit text editor. And I edited the original backup by mistake and saved it. That was 3 hours of headache I pulled on myself. So using the cat command, you can quickly peek into text files without accidentally altering them. Just type in cat followed by the file you want to open. Cat command can also create, edit and do so much more with text files. Using cat command, if you open a small text file, that's ok.

Command less

But if you open a large file, with more text, everything is going to be dumped on the terminal in one go. This is not ok for humans. Humans need larger text data to be presented in smaller chunks, in a scrollable fashion. So we use the less command. Type in the cat command, after the command put in a pipeline, which is used to combine two commands together and type in less and hit enter. Use the arrow keys to scroll, then you can press Q to exit the reader mode. The terminal too remains clean and organized by using the less command. Less is not limited to be used with just cat, but it can be used with any command where you expect to get a large amount of data back on your terminal.

Command grep

grep is a very powerful pattern searcher command available in Linux. So it's basic function is to search for a word or string in a file. But various options can be used with grep to make it more suited for particular problems at hand like searching for case sensitive patterns, searching for, say... 10th occurrence of a word in a file. grep can also search entire folders, containing any number of text files for a word in a single command. I highly suggest playing around with this command if you want to get into Linux shell scripting. So for basic usage, open a terminal in the file location, type in grep, the word you want to search for, space and the name of the file, enter. Here you go. This is just the basic usage, grep can be customized extensively using options.

Command history

The history command chronologically lists out all the commands that have been run on the terminal. Rather self-explanatory. Isn't it. A neat trick to remember, You can just note down or remember the command numbers from here, and you can run that command again by typing in an exclamation mark, followed by the command number. The numbers don't change so these can be long term shortcuts too. This works without running the history command too if you can remember the number. To clear the history, just run history -c.

Command ps

ps stands for process status and this command gives you an overview of all the processes running on your pc and information about them. The command is quite useful, especially if you have an interest in the working of Linux based operating systems. ps has many options, the one that gives you a detailed yet comprehendible amount of info on running processes is ps -aux. This throws a large list at you. So use it with the less command we saw earlier. You can see the owner of the process. Then we have the process identification number or the PID. This number is unique for a process and has significance. We'll see more about it later on. Then we have CPU and memory in percentage.

Command kill

Whenever your pc is lagging or unresponsive, you can quickly run this command and find out which application is causing the lag by noticing an unusually high amount of CPU or RAM consumption here. Then we can choose to kill the process. Quick tip. Run top instead of ps to get an interactive status of processes in descending order based on CPU usage. Once we've identified the culprit process that is causing system unresponsiveness by using up too much CPU or memory, we can kill it using the kill command. I know, not so subtle. Now consider the Gedit text editor is giving me an application not responding message, then I open up a terminal and get the PID of Gedit as shown in the last section, then I copy the PID and use it to kill Gedit. Type in kill space and paste the PID. Enter. Be careful with this command as you might lose unsaved work if you kill some applications. This is not the same as closing an application, but a strictly aggressive close by the operating system.

Command passwd

Passwd is a command that you can use to change your PC password. It also guides you to create a password that is secure enough by checking your password and giving you inputs regarding if you need to make it more secure. It outright rejects simple, commonly used passwords and even cross-checks if your new password is, in any way similar to the passwords you have used earlier. All you need to do is type is passwd and run it. Follow through. Only passwords that are strong will be accepted. You can close the terminal to retain the old password. 

Command shutdown

To shut down your computer through the terminal, we use, well, the shutdown command and there are many advanced options you can use here. To shut down the computer after some time, useful when you have downloads, renderings or any other processes running on the computer, you can use shutdown -t and time in seconds. So here the computer shutdowns after 300 seconds, which is 5 minutes. You can also type in the exact time you want the computer to shutdown by specifying the time in 24 hours format. Shutdown now does an immediate shutdown. shutdown -r performs a reboot. You can even use the command reboot to restart the computer.

Command sudo

Linux is a very secure system which strictly enforces permissions to protect the users as well itself. Yes, you heard me right. Linux protects itself. Anybody cannot just go ahead and delete or modify files that are critical to the system. But there are users, called super users or root, who have the absolute permission to do anything on the system. See, Linux does not allow anybody to install stuff on your computer when you're away. But it allows you to install software. Doesn't it. To bypass the restrictions of Linux, you use sudo before the command you run. Using sudo, you can install stuff, make changes to the OS and even delete system files. It's always a good practice to double-check the command you're about to run and understand what it does, whenever there's a sudo in the command.

Command wget

Especially for Linux newcomers who are copying commands from the internet. wget is an amazing command-line utility that I always use. Basically wget is a file downloader. To download files using wget, all you need to do it type in wget and then paste the URL of the file. Wget is much better than the default downloader in your browser. It's faster. Much more reliable I mean the downloads rarely fail, even on spotty connections. Wget also provides pause and continue support for most downloads which don't allow pause and continue in browsers. During downloads, if you close the terminal, the downloads pause and continue when you rerun the command. Although this might not work if the server prohibits pausing the transfer.

Command apt

Finally, we have apt. Apt is the package manager for Ubuntu and Debian-based Linux distros. Although it's perfectly fine to use the software center, using the apt command gives you superior control over package management. apt is a command that needs elevated privileges so we use sudo before apt. Firstly we have sudo apt update, which fetches information regarding latest updates to the software and such. It also contains info about available software and their dependencies. Then we have sudo apt upgrade, which upgrades all the software installed on the system to their newest versions. You can install a software by sudo apt install and then the software name, say vlc. We uninstall software by sudo apt remove and the software name. Then we have sudo apt autoremove, and what this does is, it removes all the packages that are not needed, dependencies that are left over after a software uninstall and all the garbage stuff that you don't need. You can run this command every couple of months or so.

Well, that's it for today.

Alex 10.6K
Joined: 4 years ago
In case you have found a mistake in the text, please send a message to the author by selecting the mistake and pressing Ctrl-Enter.
Comments (0)

    No comments yet

You must be logged in to comment.

Sign In / Sign Up