In the context of operating systems in general, and Linux in particular, the term "command" means a command line application or functionality built into the user's shell. However, for the end user, this distinction is of little importance. Both are used in the same way. You enter words in your terminal emulator and generate the results.
The purpose of this article is to list some commands that every Linux user should know, or at least know, in the case of those with a phobia of text-based interfaces. It does not mean listing all useful commands, it is not a list of lesser known utilities and it is not a manual. Its objective is the coverage of the most useful application in everyday life.
As such, it is divided into several categories, corresponding to particular tasks. It does not involve a particular distribution, and although not all of the programs described will be installed by default in each distribution, most of them will be present and the others can be found in the repositories.
Linux commands for file system management
By default, list the contents of the current directory. If you provide a route, list the content of that. The useful options to know are -l and -a, a long list format with more information and show hidden files (dots), respectively.
If you are given a single file, print its contents in the standard output. If you give more than one file, concatenate them, and then you can redirect the output to a new file. Potentially useful is the -n option, which numbers the lines.
Allows you to go from the current directory to the specified directory. If you call it without arguments, return to your personal directory. Calling it with a colon (cd ..) returns it to a directory "above" the current one, while calling it with a dash (cd -) returns it to the previous directory, regardless of where it is in relation to the current one.
Print your current directory. Useful if your message does not contain this information, and especially useful in BASH programming to obtain a reference to the directory in which you are executing the code.
Create new directories. The most practical switch is -p, which creates the entire specified structure if an does not exist yet.
It tells you the type of a file. Since files on Linux do not have the obligation to have extensions for the system to work (it is not always useful to have extensions), it is sometimes difficult for the user to know what type of file is something, and this small utility solves that problem.
Copy files and directories. Since you do not copy directories recursively by default, remember to use -r or -a. The latter retains the mode, ownership and timestamp information in addition to the recursive copy.
Move or rename files and directories. Essentially, moving and renaming is an operation, changing the name is simply "moving" a single file to the same place with a different name.
Delete files and directories. Without a doubt, it is a very useful command to know, since the disorder cannot be eliminated without it. However, be careful when using it. Although today you will really have to work on it to cause some damage to the system, you can still harm yourself. Rm does not delete the files to any imaginary trash bin from which you can extract them later when you realize that you have created a horrible error, and "rm ate my homework" will not convince anyone. Deleting directories requires a recursive operation, so once again we have the -r switch.
Create hard or symbolic links between files. Symbolic or soft links are similar to Windows shortcuts, they provide a convenient way to access a particular file, although the analogue is not enough: symbolic links can point to anything, but do not have metadata. It is very unlikely that you will never use hard links, but knowing that they are aliases for files, unlike symbolic links, which are aliases for file names, cannot harm you.
Change user permissions. This refers to view, write and execute files. A normal user can change the permissions of the files he owns.
Change file ownership. Only the root user can change the owner of a file. To recursively change the owner of all files in a directory, use it with -R.
Search the file system for files or directories. Find is a very versatile and powerful command, not only because of its search capabilities, but also because it allows you to execute arbitrary commands on matching (or non-matching, even) files.
Unlike the search, search the database for updated file name patterns. This database contains a snapshot of the file system. This makes the location very fast, but also unreliable – you can't tell if something changed from the last instant.
Show file or directory size. Among the most useful options are -h, which converts the reported sizes into a more user-friendly format, -s that provides only a summary instead of the full list, and -d that controls the depth of directory recursion .
Show disk usage. The default output is good enough: it lists all file systems, reports its size and the amount of space used and available, but you may want to include -h, which once again provides a more human-friendly report.
Convert and copy a file, according to your manual page. It is not exactly the clearest or most useful description, and yet that is all it does. It assigns a source and a destination, and optionally some other commands, and is copied from one to another. Its power comes from flexibility: it can tell you the exact size of the block, it can copy around given data and it is not demanding with the devices; If you want to overwrite your hard drive with zeros directly from / dev / zero, you are welcome to do so. It is also commonly used to create live USB sticks from hybrid ISO images.
18. assemble / disassemble
This pair is responsible for mounting and unmounting file systems. This can range from USB sticks to ISO images. Usually, only the reason has mounting privileges.
Linux commands for text processing
19. ms / less
These two similar utilities allow you to see the text divided into screens. Imagine a very long exit from some command. Maybe you called cat in a file and it took your terminal emulator a few seconds to move all the text. Well, if you put it in one of these, now you can scroll as you wish. Less is newer and offers more options, so there is no reason to use more.
20. head / tail
Another pair, but here both halves have their uses. Head generates a number of the first lines ("head") of a file, while tail generates a number of the last lines ("tail") of a file. The default number is ten, but this can be controlled by the -n option. Another til switch is -f, which is the abbreviation for "follow", which continuously generates attached lines, so, for example, if you want to monitor a log file instead of constantly opening and closing it, you can use "tail -f / path / to / logfile ".
Grep, like all good Unix tools, does one thing, but does it well. Search text by patterns. By default, it looks in the standard entry, but you can specify files to search. A pattern can be a normal string or a regular expression. You can print matching or mismatched lines, and their context. Every time you execute a command that throws a lot of information you don't need, put it in grep and let it do its magic.
Sort the text lines by several criteria. Among the most useful, there is -n, which is sorted by the numerical value of a string, and -r, which reverses the output. An example of how this can be useful is to sort the output. For example, if you want to see the files sorted in descending order according to size, you must combine the two options.
The word count utility of the command line. And the line count. And counting bytes. And the character count.
It shows the difference between two files through line-by-line comparison. It only shows altered lines, the abbreviations change as c, are deleted as d and added as a.
Linux commands for process management
25. kill / xkill / pkill / killall
All these serve to "kill" a process, that is, finish it. The difference is what they accept as input. Kill wants the process ID, xkill allows you to click on a window to close it, while killall and pkill accept the name of a process, but have somewhat different options and subtly different behavior. Note that these do not belong to the same package and, in particular, it is likely that xkill is not installed by default. We advise you to rectify it for your own convenience.
26. ps / pgrep
As mentioned, kill needs the process ID. One way to get this is by using ps, which prints information about the currently active processes. The default output is not very useful, therefore, paste a -e there to see information about each process in the system. This is just a snapshot, I don't know how to update, see above for that. The pgrep command works as follows: you give it a process name, it gives you the process ID. Partial items count, so be careful.
27. top / htop
These two are similar, both display processes, and can be considered as monitors of the console system. We recommend that you install htop the first opportunity you have if your distribution is not sent by default, as it is a much improved top version. For starters, it is not simply a viewer, but allows you to control processes through its easy-to-use console GUI interface.
Time a process. Think of it as a timer for program execution. Useful if you are curious to know how much slower is the implementation of your task of a classification algorithm compared to the built-in one. Contrary to what you might expect according to the name, it does not tell you the time. See the date for that.
Linux commands for BASH and user environment
29. su / sudo
Su and sudo are two ways to achieve the same: execute a command as another user. Depending on what your distribution is, you have probably seen only one or the other, but both are useful. The difference is that your user changes to another, while sudo only executes the command with the privileges of another user.
Unlike the time, the date does exactly what you would expect: print the date (and time) on the standard output. The output itself can be formatted according to your specification, and it takes all of the usual things, such as year, month, day, 12 or 24 hour format in nanoseconds and the ISO week number. For example, the date + "% j% V" will give you the day of the year followed by the ISO week number.
This command creates or changes the aliases to other commands. What this means is that you can give names to new commands (or groups of commands) or "rename" existing ones. It is very useful to abbreviate long command strings that you use often, or to give more memorable names to things you do not use frequently and have trouble memorizing.
32. join me
Displays basic system information. By itself, it will not give you anything very useful ("Linux"), but call it with -a, and provide you with kernel information, as well as tell you the host name and processor architecture.
It tells you how long the system has been running. It is not exactly the essential information, but it is good to show off the rights and the occasional situation of things in relation to the time I have been using the computer.
You may be wondering why this will be useful, but even outside of BASH scripts, it has its uses: for example, if you want to turn off the computer after a certain period of time, or even as an improvised alarm.
Linux commands for user management
35. useradd, userdel, usermod
These commands allow you to add, delete and modify user accounts. It is not very likely that you use them often, especially if you are the only user of your system, and even if not, you can choose to do it through a GUI, but it is good to know what they do and what they do. You are there in case you suddenly need them.
This command allows you to change the password of your user account. As root, you can reset normal user passwords, although you cannot see them. It is a good security practice to change your password from time to time.
Linux Commands for Help / Documentation
37. man / whatis
The man command shows the manual for a particular command. Most command line applications come with a manual page. Whatis provides a summary of a line drawn from the relevant sections of the manual. What are the sections of the manual? See for yourself with "man man".
38. where is it
It tells you where an executable binary file lives, as long as it is in its path. You can also find your manual page and source code, provided they are present.
Linux commands for the network
If the list of network-related commands seems very short, you are probably not familiar with ip. In summary, the net-utils package containing ipconfig, netstat and others has been deprecated in favor of the iproute2 package. Provide the ip command, which replaces ipconfig, netstat, route, etc. You can see it as a Swiss army knife, or an unwanted disorder, but in any case, it is the future.
The pings are ICMP ECHO_REQUEST datagrams, but that is not important. The important thing is that the ping utility is a useful diagnostic tool. It allows you to quickly test whether it is connected to your router or the Internet, and gives you some indication of the quality of that connection.
SEE TAMBIN: The 10 best Linux desktop environments