“The terminal is very simple and at the same time extremely powerful, it allows you to interact with the operating system without the need for a graphical interface.

Although Linux distributions make their GUI ( graphical user interface ) more and more complete and functional, the terminal has always been and will always be there to help you and not the other way around , as you may have thought. In fact, in some distributions it is the first contact between the user and the system.

shell

If you start using the terminal regularly, you will not only lose your fear, but you will notice that it is a powerful tool that allows you to maintain and manage your entire system in an agile and functional way.”

How to open a “terminal”

  • In any GNU/Linux we have the terminal or console call that opens a shell or command interpreter. In Ubuntu we open it by searching in the Dash or Unity board: « Terminal «, from the « Applications » menu -> « Accessories » -> « Terminal » or pressing the key combination CtrlAlt+T
  • You can also switch to text mode (command interpreter) from graphic mode by pressing: CtrlAltF1or with: F2 F3 F4 F5 F6. This causes the system to exit graphical mode and access one of six Linux virtual consoles, which can also be accessed when booted in text mode.
    To return to graphic mode, press CtrlAltF7.

pwd

pwd (from print working directory or print working directory), is a convenient command that prints our path or location at the time of execution, so we avoid getting lost if we are working with multiple directories and folders. Its syntax would be:

$ pwd

ls

ls (for listing), allows you to list the contents of a directory or file. The syntax is:

$ ls directorio

If you omit “directory” it will display the contents of the current directory. The ls command has several options that allow you to organize the output, which is particularly useful when the output is very large. For example, you can use ” -a” to show hidden files and ” -l” to show users, permissions and date of files. As with all Linux commands, these options can be combined, ending in something like:

$ ls -la directorio

CD

cd (from change directory or change directory), is as its name indicates the command you will need to access a path other than the one you are on. For example, if you are in the “/home” directory and you want to access “/home/books”, it would be:

$ cd libros

If you are in “/home/books” and wish to go up one level (i.e. go to the parent directory, “/home”), you would run:

$ cd ..

touch

touch creates an empty file, if the file exists it updates the modification time. To create the file “test1.txt” in “/home/teacher”, it would be:

$ touch prueba1.txt

mkdir

mkdir (from make directory or create directory), creates a new directory taking into account the current location. For example, if you are in “/home/teacher” and you want to create the “exercises” directory, it would be:

$ mkdir ejercicios

mkdir has a very useful option that allows you to create a whole directory tree that doesn’t exist. For that we use the “ -p” option :

$ mkdir -p ejercicios/uno/dos/tres

zip

cp (from copy ) Copies a source file or directory to a destination file or directory. For example, to copy the file “test.txt” located in “/home/teacher” to a backup directory (which must already exist), we can use:

$ cp prueba.txt /home/respaldo/prueba.txt

In the syntax, the source is always specified first and then the destination. If we indicate a different destination name, cp will copy the file or directory with the new name.

See also  Xpra - Establish remote access to graphical applications in Linux (Screen for X)

The command also has the ” -r” option which copies not only the specified directory but all its internal directories recursively. Assuming that we want to make a copy of the “/home/teacher/exercises” directory, which in turn has the “exercise1” and “exercise2” folders inside it, instead of executing a command for each folder, we execute:

$ cp -r /home/profesor/ejercicios /home/respaldos/

mv

mv (for move or mover), moves a file to a specific path, and unlike cp , removes it from the source when the operation is complete. For example:

$ mv prueba.txt /home/respaldos/prueba2.txt

Like cp , the syntax specifies the source first, then the destination. If we indicate a different destination name, mv will move the file or directory with the new name.

rm

rm (from remove ) is the command needed to delete a file or directory. To delete the “test.txt” file located in “/home/teacher”, we execute:

$ rm /home/profesor/prueba.txt

This command also presents several options. The ” -r” option deletes all files and directories recursively. On the other hand, ” -f” deletes everything without asking for confirmation. These options can be combined causing a recursive, unacknowledged delete of the specified directory. To do this in the “backups” directory located in “/home”, we would use:

$ rm -rf /home/respaldos

This command is very dangerous, therefore it is important that we thoroughly document the effects of these options on our system in order to avoid dire consequences.

rmdir

rmdir (from remove directory or remove directory), removes a directory as long as it is empty (otherwise it will give an error). To remove “/home/backups” we would use:

$ rmdir /home/respaldos

chown

chown (from   change owner or change owner), allows us to transfer ownership to another user and/or assign it to a group to which we belong. To give ownership of the file “test.txt” to the user “student” we would write:

$ chown alumno prueba.txt

This command also presents several options. The ” -R” option applies the change to all files and directories recursively. To give ownership to the user “student” and the group “practices” of the directory “/home/exercises” we would write:

$ chown -R alumno:practicas /home/ejercicios

NOTE : There is also the chgrp command to change the group of a document or folder.

chmod

chmod (from change mode or change mode) allows you to change the permissions of a file or directory. This particular command has several allowed syntaxes, of which we will explain the simplest: chmod [options] mode[,mode]?? file

See also  FFmpegfs - A file system that converts your videos automatically

For this we have to be clear about the different groups of users:

  • u : user owner of the file
  • g : group of users associated to the file
  • o : all other users
  • a : all user types (owner, group and others)

You also have to know the letter that abbreviates each type of permit:

  • r : read permission
  • w : write permission
  • x : execute permission (browsing into directories)

Assign read, write, and execute permissions for “other” users to all files in the folder:

$ chmod o=rwx *

Assign all permissions to all users for the file “file.txt”:

$ chmod a=rwx file.txt

Removes all permissions for group users and other users.

$ chmod go= *

It gives all the permissions to the owner of the file, it assigns read and write permissions to those in the owner’s group, and it removes all permissions from the other users. The ” -R” option applies the change to all files and directories recursively.

$ chmod -R u=rwx,g=rw,o= /home/exercises
Note: A space after the comma ‘,’ in the various permission modes listed causes the command to fail.

Give read-only permissions to all user types.

$ chmod a=r *

In a similar way to what we have just seen, you can also add or remove permissions with the + and – operators. To do this, the type of user and the permission that is subtracted or added are indicated. Something like this:

This removes all permissions for all user types.

$ chmod a-wrx *

This command assigns read permissions to all users and write permissions to the owner of the file and the owner’s group.

$ chmod a+r,gu+w *

This command assigns write permissions to the owner user and adds read permission to all users.

$ chmod u=w,a+r *

du

du (for disk usage ), estimates the space occupied by the directory and all its subdirectories. It is usually used with the “-h” parameter to facilitate the reading of the measurement units (Gigas, Mengas, Kb). To analyze the occupation of the contents stored in “/home/exercises” we would use:

$ du -h /home/ejercicios

If we are only interested in knowing the summary of the entire directory, we would add the “-s” parameter:

$ du -hs /home/ejercicios

df

df ( for disk filesystem or file system) shows the disk space used on each mounted volume or partition. The “-T” option shows the file system as well. Add “-h” to use multiples in the measurement units (Gigas, megas, etc):

$ df -Th

find

find (to find). Find the file or folder you indicate:

$ find /home -name test.txt

The above command would search all sites for folders and files named “test.txt” starting from the “/home” folder

See also  Q4OS - A stable and powerful Linux Desktop distribution

If we are not very sure of the name we can indicate it with wildcards. Suppose the name of what we’re looking for contains “exercise”, in the same folder as before:

$ find /home -name *exercise*

It has other advanced options that allow discriminating by file type, creation/access/modification dates, size, owner and/or permissions, among others.

clear

clear (to clean), is a simple command that will clean our terminal completely, leaving it as newly opened. For this we execute:

$ clear

As a bonus I recommend using man which shows a complete documentation of the given command. For clear , for example:

$ man clear

5/5 - (1 vote)