Command lines are really powerful tools. After having spent almost 10 years supporting remote users and companies, one learns to value the efficiency and versatility of this type of thing. Not in vain have they saved my day on more than one occasion. Both in Windows, if we use MS-DOS, as in Linux, we can perform advanced actions much faster if we do it through commands. And that is something that is appreciated in the long run, and a lot.
25 basic commands to learn how to use the Linux terminal
In today's post we review 25 of the most basic and useful commands for Linux. A small compilation that can be great if we want to learn to use the Linux terminal for the first time. Or to refresh our memory and recall certain orders that we had somewhat forgotten. In any case, a good list that never hurts to have on hand or in the "favorites" tab for a moment of need. Let's go there!
1 # ls
The command "ls" shows the list of all files and folders in a specific directory.
ls
If we also add the command "a" it will also show the hidden files of the folder in which we are.
ls -a
2 # cd
The command "cd" is used to change directory in the terminal. To change the folder in which the terminal loads by default to a different one:
cd / path / to / folder /
We can also go to a higher folder using the colon "..".
cd ..
3 # pwd
It shows the directory in which we are at that moment within the terminal.
pwd
4 # mkdir
If we want to create a new folder we will use the command "mkdir".
mkdir folder-name
We can also keep the same permissions of the upper folder if we add the option "-p".
mkdir –p folder-name
5 # rm
With this command we can delete a file directly from the command line.
rm / path / to / file
If we add the option "rf" we can also delete entire folders with all their content.
rm –rf / path / to / folder
6 # cp
Thanks to this command we can make a copy of a file. We just have to write the command, the source path and the destination path.
cp / path / source / file / path / destination / file
We can also copy an entire folder if we attach the "-r" option.
cp –r / path / source / folder / / path / destination / folder /
7 # mv
The "mv" command allows you to do various things on Linux. On the one hand, we can use it to move files from one place to another, but it also serves to rename files. For example, to move a file from one folder to another:
mv / path / source / file / path / destination / file
We can do the same to also move the folders from one path to another:
mv / path / source / folder / path / destination / file
If what we want is to rename a file in Linux, we only have to navigate in the terminal to the path where said file is located and write the following:
mv file-name new-file-name
We can do the same in the case of a folder.
mv folder-name new-folder-name
8 # cat
This command allows you to view the content of a file from the terminal. To use the command "cat" we only have to write the command, followed by the path where the file is located.
cat / path / to / file
9 # head
Head allows us to see the first 10 lines of the content of a file. It is used the same as "cat", writing the command and then the file path.
head / path / to / file
10 # tail
Very similar to "head". Tail allows you to see the last 10 lines of the content of a file.
tail / path / to / file
11 # ping
In Linux the "ping" command is used to check latency or response time between our network and a remote server on another LAN or the Internet. It is a fairly common command to check if we have an Internet connection.
ping website.com
We can also ping the IP instead of using the domain.
ping IP-address
If we want to do an infinite ping, we can do it by adding the option "-t" at the end.
ping website.com –t
12 # uptime
With the "uptime" command we can check how long we have been online.
uptime
# 13
The uname command is used to print information about the Linux system we are using (version number, distribution, date and time) on the screen. The most practical way to use it is by using the "-a" option.
join me
14 # man
This is one of the most practical commands in Linux: the manual. To know how a command works, we just have to type "man" followed by the command in question.
For example, if we want to see the user manual for the "mv" command, we will write the following:
man mv
15 # df
Df allows us to see how much space we have occupied in the Linux file system.
df
We can also display the result in a slightly more orderly way by adding the "-h" option.
df –h
16 # du
You want to know how much space does a directory occupy in your system? That's what the "du" command is for. For example, to find out how much your folder "/ home /" occupies, launch the following line:
du ~ /
To obtain a more readable result it is recommended to use the option "-hr" at the end.
du ~ / -hr
17 # whereis
If we control a little English we can surely imagine what “whereis” does. It basically serves for know the exact location of an item. For example, if we want to know where the Firefox binary is located within our Linux system, we would execute the following:
whereis firefox
18 # locate
With the command "locate" we can do file, program or folder searches. Just launch the command together with a search term.
locate search-term
19 # grep
This is a command that allows us to do searches for certain certain patterns. It is not a command that is usually executed alone, since it is usually accompanied by another command.
A good example can be the combination of the command "grep" and "cat" to search for a specific line of text within a file.
cat text-file.txt | grep 'search term'
Generally speaking, the search for patterns with the "grep" command follows this same formula:
command command-operations | grep 'search term'
20 # ps
With this execution line we can show in the Linux terminal the processes that are running at the moment.
ps
If we want a more detailed report we can also add the option "aux".
ps aux
21 # kill
If a program does not work or has been blocked, we can kill the process with the "kill" command. For example, if we want to close Firefox we will do the following:
- First we launch the command "pidof" to know the process identifier of Firefox. | pidof
- Now yes, we will kill the Firefox process with the "kill" command. | kill process-id-number
- If it still doesn't close, we can launch one last command using the "-9" option. | kill -9 process-id-number
22 # killall
With "killall" we can eliminate all instances of a program that is running. To use it, we just have to write the command next to the name of the program that we want to close.
For example, to close Firefox:
killall firefox
23 # free
If we're running out of memory, we can see how much RAM (and swap) we have left with the "free" command.
free
24 # chmod
Chmod is a really useful command since with it we can manage the read and write permissions of any folder or file.
For example, to update a file's permissions so that everyone can read (r), write (w), and execute (x):
chmod + rwx / location / of / file-or / folder /
25 # curl
With this command we can download files from the Internet directly from the Linux terminal window. To start the download, we just have to write the command "curl" followed by the URL where the file is located, plus the symbol ">" and the destination folder where we want to save the download.
curl //www.download.com/file.zip> ~ / Downloads / file.zip
Conclusions
These are 25 basic commands for Linux that it never hurts to remember. Apart from these there are many others to perform all kinds of tasks, so if this is the first time you hear about Linux you already know where to start, and if you are a veteran and want to share some other interesting command, do not hesitate to stop by the comment area.
Thanks for staying until the end and see you in the next post!
You have Telegram installed? Receive the best post of each day on our channel. Or if you prefer, find out everything from our Facebook page.