blog.johanka.net

Introduction to the command line I

So far we've barely scratched the surface, the parts of the system that are immediately visible. It's time to plunge deeper and uncover the insides, the inner layers that form the essential part of what it means to work with a Unix system. The feature that is going to lead us there is the command line.

Click on the black and white icon labelled Terminal. You will see the user name, the name of the machine (mint@mint if you have the live preview running) followed by a ~ (which represents the Home folder), a $ and a blinking cursor. I will now introduce a couple of commands to perform some basic operations that you can use at this point. None of this is arcane knowledge, you will find it in every introductory handbook.

Supposing we want to get to the desktop. We will type in

cd Desktop

and press enter. You can always check your position in the directory structure by typing in the command pwd (with enter). Now we want to list all the files in this directory, including the hidden files that are not displayed in the graphical interface. Let's type in

ls -la

Alas, no hidden files. Let's create some. Type in the command touch followed by a file name that begins with a dot. Like this

touch .mynewfile.txt

(The .txt extension is optional.) Now, when you've pressed enter, no addition appears on the screen. In order to see this hidden file, you will need to type in the command ls -la again.

Let's rename this file to make it visible, create a new directory and move the file into it.

Type in

mkdir Mynewdirectory

(or "My new directory" if you prefer the version with spaces). To rename the file type in the command mv followed by the original name and the new name (without the dot).

mv .mynewfile.txt mynewfile.txt

To move the file into this new directory, you will need to type in this

mv mynewfile.txt Mynewdirectory

The file has disappeared from the Desktop. To find it, click on the directory you've just created with a mouse (touchpad if you are on a laptop) or type

cd Mynewdirectory
ls

in the Terminal window. Voilà! Exciting? Pretty addictive, I would say. Now let's move up one level in the directory structure. Like this

cd ..

and once more. You are now back in the Home directory where we started. You can now play with the commands I've just shown you, move up and down in the directory structure, list its contents and create some empty files.

To close the Terminal window, you can type in

exit

Let us now open it again so I can show you the ways to delete files and directories.

Type in

cd Desktop
cd Mynewdirectory
rm mynewfile.txt
ls -la

and you will see the directory is now empty.

cd ..

to move up one level again and

rmdir Mynewdirectory

to remove it.

Remember to always enclose file and directory names with "" if they include spaces.

As I've mentioned earlier, you can install programs in the command line as well. In the Terminal window type in

sudo apt-get update

You will see several package updates loading. To install a desired application, type in

sudo apt-get install <desired package name >

The last two commands are entered as root, user with administrator privileges. In Mint, every action you perform is done in a regular-user mode, unless you type in "sudo" to log in as administrator, supposing the user account you are logged in to has admin privileges, of course. This increases the security of the system and decreases the risk of you accidentally destroying anything.

Every Linux command is well documented, so you don't need to remember every modifier of every command you are using. If, for instance, you cannot remember the modifiers of the command tar (used to create compressed file archives), type in

man tar

and read up on the manual page. When you've found what you needed, type q to close the manual page and get back to the cursor line.

copy left Johanka Piskovská, 2020