This tutorial is supposed to show useful terminal commands to people who are new to Linux.
1 Preliminary Note
Terminal commands are powerful tools if they are used correctly, but can cause great damage if you are not completely aware of what you are doing. Before using commands that are new to you, look up the manual page and make sure you have your files saved and backed up.
This tutorial comes without guarantee of any kind.
2 Root User
On Linux Mint there is only one user with administrative rights which is the so called root user. However every system user can log him- or herself in as root to execute commands that need administrative rights to be run. I am going to show some of them in this tutorial, so what you need to do first is to log yourself in as root. Open Terminal and enter
You will then be asked for your password. Type it in (the letters are invisible) and hit Enter. When logged in to root, the font color of the command line will change from green to red. You will need to be extremely cautious performing commands in this mode since you have no restrictions set by the system. Make sure you know exactly what you are doing and have backups of your files made. To quit root status, just type in
Instead of keeping root active the whole session, you can also use it for single actions only by placing sudo in front of the command, e.g. like this:
sudo shutdown -r 16:00
You will also once be asked to type in your password using this method.
3 Software Management
Instead of using package or software manager to manage your software, as always, you can do that by using Terminal. To do that you must be logged in as root user, accomlish that by using the commands from the previous step. I am going to show you how to install and uninstall software by the example of the Stellarium app. After you have logged in to root, use the apt-get command to install the app:
apt-get install stellarium
If you prefer not to be logged in as root, just put a sudo in front of the command:
sudo apt-get install stellarium
Type in your password to perform the command. After you are done with the app, uninstall it by replacing the install option within the command with remove.
apt-get remove stellarium
sudo apt-get remove stellarium
The apt-get command has a lot more options to choose from, which I will not explain here. For more information just open its manual page. To see how, see the end of the tutorial.
4 Useful Process Commands
Former Microsoft Windows users might miss the task-manager structure in Linux, in case any application just won’t continue working or some other fatal error appears, but for that case Linux Mint has its own terminal commands. To print a snapshot of running processes, enter
ps -u [username]
and replace [username] with the name of the user you want a snapshot of the processes of. If you want a dynamic view of running processes, use the top command instead:
When using one of the above commands to view the running processes, you should have noticed the number in the first column, titled PID. This is the ID you need when you want to remove one of those processes. Should one them stop working due to misfunction or anything else, you may want to force close the process. The command you use for that is called kill. The most common uses are just the command followed by the PID (replace [PID] with a given four-digit number):
or place a 9 in between kill and the PID parameter to force kill a process. Be careful using this option though since killing important system processes might cause it to crash.
kill 9 [PID]
Please notice that processes do not have the same PID everytime they are run. Always doublecheck if you got the right PID before you actually kill or even force kill a process.
Another useful command is time. Followed by another command, it shows you how much time the command the follows actually needs to be run.
time sudo apt-get install stellarium
To shut down or reboot your system, there is the shutdown command. You can just perform instant shutdowns with it or set a specific time in multiple formats for when to do so. This can be used as sort of a time controller for your computer to automatically power off when you want it to.
shutdown [hh:mm] [message]
[hh:mm] is one of the possible formats to describe a time. View the manual page for more. You can enter a message instead of [message] which will then be shown shortly before shutdown. If you want a reboot after the shutdown, just put a -r option between shutdown and time.
shutdown -r 16:00 Going home after reboot, yay!
5 Archiving Files
To archive your files so that they use smaller space you can use the gzip command. To gzip files, browse the directory the file is in and enter
The original file will then be replaced by a gzipped package. To ungzip it, simply enter
gzip -d [filename]
which practically are the same commands.
6 Text Editing
There are multiple choices when it comes to text editing since there are many editors you can use, all of them available via terminal. The one you might be used to is gedit. To launch a text file via gedit just enter
Do not forget to pick the right directory and of course, replace [textfilename] with the correct title. Other possible texteditors are nano and vi. Open them with the same command structure as gedit.
Apart from real text editors, there are also commands that give you the content of a text file inside the terminal window. To give you a better overview over texts, there are commands like more, head or tail which only show a specified part of a text file that you can configure yourself using command options.
more gives you the selected textfile page after page. By hitting the Enter key you can easily flip pages until you reach the end of the document.
head -# [textfilename]
head gives you only the top lines of the chosen text file. Replace # with the number of lines you want to be shown with head as well as in tail.
tail -# [textfilename]
tail gives you the bottom lines of the chosen textfile, depending on which value you have given #.
The easiest way to display shorter textfiles inside the terminal is the cat (concatenate) command. Followed by the file’s name, it will display the contents right away inside the current terminal window.
cat [file name]
But as the name says, you cannot only display contents but also add contents to it or merge two or more text files into one single, leaving the original files unchanged. To add content to a file or create a new file with the specified content, enter
and type the content that the existing or new file shall have. Leave the input process by hitting Ctrl+D. To merge two or more files into another file which cannot be one of the original files but also an already exisiting one, enter
cat [file_1] [file_2] … [file_n] > [newfile]
7 Searching for Files
To locate files on you computer, there are multiple quick solutions in command form. If you want to search your whole system for specific files use the locate command. Give the file name or part of it as parameter following the command or the options and the command will give you all paths including the specified name parameter.
There is an extra command to locate executable files on you computer that gives you their full path, however the full name of the executable file is needed to run the command. Replace [executable file’s name] with its actual name.
which [executable file’s name]
To give you a list of contents located in your current directory, you have the ls (list) command. There are multiple options when using this commands, e.g. to give extra information about the content or to sort it in a specific way, the most commonly used being -l which displays the owner and the rights of each file and folder.