Linux Basic Commands you Should Know
Linux is the most popular Open Source operating system and it powers the vast majority of the servers that compose the Internet. Mastering the linux command line is a great help for any web developer, allowing them to be more agile and independent
when working in Linux/Unix development environments.
This article focuses on the small core commands that you will use the 80% or 90% of the time, and tries to simplify the
usage of the
more complex ones.
man: understand all the other commands
Just run this command to load a manual page about system commands, with definitions not only of the use of each tool,
but also
detailed descriptions of the many software parameters and usage examples.
To read the manual pages is very easy and you just have to execute man followed by the name of the command you want
to
find help for. Do not forget to press the Enter key after typing the command, otherwise it will not be executed.
By running man cp, for example, you can read all the instructions for using the cp command. And before moving on to
the
next item on the list, two pieces of advice are worth: the first is that there is the man man command, in case of
doubts
about the use of man itself. The second is that it is possible to translate the content of the manual pages into
Spanish, if they are in English, by installing manpages-es through the Ubuntu Software Center.
ls: list all the files that the folder
To list the existing files in a directory, just use the ls command. If run without parameters, it will display the
contents of the directory you are in. But you can specify a path to ls, like ls /usr/bin, for example. It is also
possible to use the ls command to see the size and creation date of each file or folder. To do this, use the -lh
parameter, as in the following example: ls -lh.
And if you also want to list the hidden files, which start with a dot, use the -a (ls -lha) option.
cd: browse the file system
To go from folder to folder, it is not necessary to open the file manager. In the terminal itself, it is possible to
navigate through the file system using the cd command followed by the path you wish to follow.
Example: cd /usr . It is worth noting that there are some shortcuts that can make life easier for the user. If you run
the cd command with no parameters, it returns you to the user's folder, which is located at /home. To go back one level
in the directory tree, use " cd .. ", without the quotes. That way, if you're in /usr/bin and run " cd .. ", you'll be
taken back to the /usr directory.
cp: copy files and folders
Copying a file from the terminal is also quite easy. It uses the cp command followed by the source file and the
destination, which can be either a new folder or a new file with a different name.
Example: cp file1.txt file2.txt or cp file1.txt pastanova/ . To copy an entire directory, don't forget to pass the -r
parameter. If you want to clone a folder, use cp -r book1 book2 , for example.
mv: move files and folders
To move files, there is the mv command which can be used both to transfer files and to rename them. If you want to send
the file from one folder to another, just follow the example mv folder1/file1 folder2/ . If you prefer to just rename
it, use mv file1 file2 .
more: read text files
In case you need to read the contents of a text file, use the more command followed by the path and name of the file, as
in more /home/user/file.txt .
The entire content of the file will be displayed in the terminal, filling the screen with the text. To continue reading,
press the space bar and, in case you need to go back one or more pages, use the «b» key. If you want to exit before the
end of the file, press «q».
df: check disk space
Do you want to know what is the total space and how many GB are available in each system partition? Use the df -h
command . The -h option, by the way, stands for human-readable. If you run the command without this option, the
information is displayed in kilobytes and will need to be mentally converted to other units.
sudo: special permissions
For security reasons, Linux works with user permissions. Therefore, certain commands or files are accessible only by the
owner or by the administrator user (root). So that you do not have to change users at all times, there is the sudo
command , which guarantees root user credentials temporarily, through the information of a password.
Try running the command ls /root . You will receive a permission denied notice. Next, run sudo ls
/root . After supplying the password of your own user (in the case of Ubuntu), the command is executed normally, and the
files in the root folder are displayed in the terminal.
grep: text searches
Imagine the following situation: you have a text file with about 200 names of students from a certain school, but you
are not sure if a specific student's name is listed.
The grep command helps you find that student and do a lot more with the help of regular expressions.
Just run the command grep “Student Name” file.txt for the terminal to search for the name that appears within the
relationship. In case you are not sure if the student's name was capitalized, add the -i parameter so that grep will
ignore this distinction during the search.
clear: : clear the buffer
Last, but not least, a command that helps to organize some of the confusion of letters found in the terminal after hours of use. To
clear the entire buffer, run the clear command . Afterwards, you just have to go back to using the terminal normally, as
if nothing had happened.
Note that there are many advantages to using console mode or a terminal emulator. Linux text mode offers more freedom to
the user, who can abuse the parameters of each command, executing highly customized actions.