25+ Linux Terminal Commands everyone should know

We know how the commands on Linux are a really powerful tool because they allow you to perform multiple things very quickly once you understand how they work. In this new guide today, we have decided to group together what we believe to be the best commands to know absolutely to use Linux Terminal in the best possible way.

25+ Linux Terminal Commands everyone should know

Linux terminal: what it is

Before knowing the commands specifically, we wanted to first clarify what the Terminal is, especially for those users who have little knowledge about it. The Terminal, also known as shell, is a work environment that allows commands to be given to the computer.

In this way, the commands are sent as text strings and in turn the PC always responds with text strings or with the execution of applications. The Terminal can also be used for programming as scripts can be created to automate even complex and repetitive operations.

To open the Terminal, all you need to do is access the Applications menu. Since different types of shells are available on the square, it is necessary to know which one is used by the running system. You can access the complete list by consulting the /etc/shells file. The most used and implemented as default in most Linux distributions is Bash, which stands for Bourne Again Shell.

Linux terminal: the commands to know absolutely

After having seen in principle what it is and how to use the Linux terminal, we are now ready to see the best commands to know absolutely.

ls

ls is a command that lets you list information about files and the contents of directories in the most concise form possible. To understand the type of file, type the command ls -F. In this case, you will get as a result some entries with symbols indicating whether it is a directory ( / ), an executable ( * ) or a symbolic link ( @ ).

For the uninitiated, the symbolic link is an appointment to the real file in another directory. These can be moved, created, deleted and so on and are used to move faster in the structure of a directory. Furthermore, they are sometimes used to shorten the name of a file or directory that is too long to type.

If you want more information on each file, use the command ls -l where -l stands for long. If you want to know more information about the current directory, use the command ls -ld.

Also through the Terminal, it is possible to sort the list by date using the string ls -t (from the oldest to the most recent) or ls -tr (from the most recent to the oldest). To see the files in the subfolders of a directory, use the command ls -R. In conclusion, it is possible to see hidden files using the ls -a command or combine multiple options at once by typing them one after the other (eg ls -a -l ).

CD

cd (which stands for change directory) is a command that allows you to change the current directory of the shell from which it is executed. For example, it is possible to access the tmp folder using the cd /tmp command while to return to the main directory, just type cd again. In addition to this, through the cd string  you can go to the previous folder.

pwd

Through the pwd command (acronym of present working directory ) it is possible to ask the Terminal to indicate us in which directory we are.

mkdir

mkdir is a very useful command that allows you to create a new folder using the Linux Terminal. To this you can add the -m options to set directory permissions, -p to not display error messages if the directory already exists and -v to display a message for each directory created.

rm

The command rm (remove) allows you to delete files and directories from the file system as long as you have the necessary permissions. Just type rm followed by the name of the file to be deleted. Once this is done, a confirmation request should appear: enter y to confirm or n to cancel the operation. Alternatively, you can force the deletion using the rm -f command followed by the name of the file to be deleted.

If you want to delete an entire directory (maybe present in another directory), first use the cd command as reported earlier to reach the primary directory and then type the command rm -r followed by the name of the sub-directory. In this case, -r (recursive option) allows you to do just that. Alternatively, you can take advantage of the rm -r command followed by the path to the folder to be deleted (eg /home/folder/sub-folder).

cp

Among the commands to be absolutely known, we have decided to also include cp that allows you to make a copy of a file or a folder in a very simple way. To copy a file, type the command cp followed by the path to the file while, to copy a folder, type cp -r followed by the path to the folder.

If you want to copy a particular file, for example, in the home folder, use the command cp filename.jpg/home. To copy a specific folder within the same home folder (or another favorite one), use the command cp -r folder name/home.

mv

Just like the command indicated earlier, mv is also very important as it serves to move files and folders to different locations within Linux. So, to move a file from one location to another, use the command mv filed to set the destination folder (eg mv filename home). The same thing applies to folders. The same command can also be used to rename files. Just type mv oldname newname (eg mv photo1.jpg photo2.jpg ).

cat

The cat command is very useful as it allows you to view the contents of a file directly in the Linux terminal. All you have to do is type cat followed by the name of the file you want to view (eg cat file.txt ). By adding the -n option to the cat command (hence cat -n), you can number the lines shown. The final result will be like this: cat -n file.txt. Cat can also be used to concatenate two or more files. Just type cat file1.txt file2.txt.

head

Head lets you view the first major lines of a text file. As standard, this command shows the first 10 lines of the data but it is also possible to specify them. For example, using the command head -n 10 file.txt, you can see the first 10 lines of the file file.txt while, by typing 20, the first 20 lines.

tail

Unlike the command seen earlier, tail allows you to show the last lines of data from one or more text files. With tail -n 10 dati.txt, you see the last 10 rows of files while, for the last 20 rows, you need to type in the number 20. If you want to see the lines of a file starting from the 20th, use the command tail -n +20 data.txt. To see the last 15 bytes of a file, use the command tail -c 15 data.txt.

ping

As seen on Windows and MacOS, the ping command allows you to check the time it takes for a packet of data, sent by the computer, to reach another and go back. To do this, you can use the command ping sitointernet.com or ping IP address. You can also use the -c option to run the ping command a preferred number of times. For example, to ping 3 times on Google, use the ping google.com -c3 command.

uptime

If you want to find out how long Linux has been running and other useful information, just use the uptime command. In particular, display the current time in order, how long the system has been running (data expressed in days, hours and minutes), how many users are connected to the system, the average load of the last minute system, the load average of the last 5 minutes and the average load of the last 15 minutes. Here is an example of result after sending the uptime command: 22:21:45 up 9 days, 11:50, 12 users, load average: 0.19, 0.17, 0.15.

uname

Among the best commands to know absolutely and to use in the Linux Terminal we have also included uname (abbreviation of unix name). Thanks to this command it is possible to get information on the computer used and the operating system installed (the type and version, the architecture of the computer and the name of the latter on the network).

You can also add several options to the uname command. Through that -a, you can see all the known information, with -m the type of hardware, with -n the computer’s network name, with -r the operating system version, with -s the type of operating system and with -v the sub-version of the OS.

man

The man command allows you to view the manual pages of any program. Simply run the man command followed by the software name (eg man cat to see the cat manual).

df

df lets you know the free disk space on the individual file systems available in the system. To this command it is possible to add some options. For example, by adding -k, you can see the dimensions in units of a kb and with -P displayed information about a file system (file system name, total size, amount of used space, amount of free space available, percentage of space used compared to the total size and directory where the file system is attached -mount point).

By adding the -a option you can have the list of special file systems (such as those whose size is equal to 0), with the option -h display the dimensions compactly using powers of 1024 and adding suffixes that indicate the unit of measurement (eg G for GB) while with -H you visualize the dimensions in a compact manner using powers of 1000 and adding suffixes that indicate the unit of measurement. In conclusion, through the -T option, you can know the type of file system.

du

This very useful Linux command allows you to calculate and show the total space occupied by specific files or directories in the file system. For example, to know the size of the home folder, just give the command du home.

Taking advantage of the -a option, you can also see how much space the files contained in the specified folders and subfolders occupy, while with -k you set the measurement in blocks of 1024 bytes. Using the -s option, you can see the space occupied only by the specified directories and not by the subdirectories while with -c you can have the total sum of the space occupied by the specified files or folders.

whereis

Among the best commands to know absolutely we have decided to report also whereis. It allows you to track the exact position of an object on the command line. For example, to find the location of the Firefox binaries on the operating system, use the command whereis firefox.

locate

locate is a great command to search for files or directories quickly and easily. Simply add the name of what you want to search after the command. The result returned will be the list of files and directories containing the search term in their name and path (eg locate filename ).

grep

Compared to the command seen a while ago, with grep it is possible to carry out more in-depth searches in the files to see whether or not they contain specific sentences or words. For example, if you want to search for the word orange in the expense.txt file, just type the command grep “orange” expense.txt.

If, on the other hand, you want to search for the same word in a specific directory or subdirectory, you must use the command grep -r “orange” home/expense. You can also combine options such as -i to ignore the differences between uppercase and lowercase letters, -n to know the line number within the file, -l to report only the names of the files in which at least one match was found and so on.

ps

The ps command allows you to have information regarding the processes present at that moment in the system. This can be combined with different options. For example, adding -d, you can see all the processes of all users except those that are section leaders. With -e you can see all the processes of all users while with -f you can view the information through a format that specifies them all. By using the -l option, on the other hand, you can view information using an extended format.

kill

You can kill a problematic program using the kill command. For example, if you want to close Firefox, you must first find the number of the Mozilla browser process using the kill command. Once identified, type kill followed by the signal number (in this case 9) and the process number (eg kill -9 35879 ).

killall

Through the command killall it is possible to terminate all the instances of a running program. Type the command killall followed by the name of the software in question (eg killall firefox ).

curl

The Linux terminal also allows you to download a file from the Internet in a very simple way. All you have to do is type the command curl followed by the address of the file, the symbol > and the path where you want to save it (eg curl http://www.linkdownload.com> home/file.zip ).

free

The free command keeps the available RAM space under control at all times. In addition to this, it shows details about the free memory in the swap partition. The free command can also be combined with options such as -b to show the result in bytes, -k to see the result in kilobytes, -l to get more details on the memory status, -t to see the totals of each column by adding two lines at a time and -s to receive, at regular intervals, information on the memory without manually launching the command whenever you want. To specify that the parameter -s must be followed by the number of seconds (eg free -s 10 ).

chmod

Through this command it is possible to modify the read, write and execute permissions. Furthermore, the command must be combined with options. Taking advantage of the syntax chmod a = rwx filename, it is possible to give all the permissions to access the file filename. The letter a can be replaced with the u for owner user, with g for a group or with or for other users.

If you want to update the permissions of a file so that all users can read, write and execute it, use the command chmod + rwx followed by the location of the file or folder (eg chmod + rwx home). To update the permissions so that only the owner has access, instead, use the command chmod + rw. Finally, to update the permissions for a specific group, run chmod + rx.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top