The most popular commands in Linux. Basic Linux commands for beginners. Archiving and Compressing Files

Not every Linux user needs to know how to work in command line. But sooner or later there will come a time when you need to perform some minimal actions in the terminal. The cases can be completely different - setting up the system, restoring, copying data in case of failure, and so on.

Therefore, I decided to compile this collection of commands for beginners in Linux that can be useful to everyone.

1.ls

Team ls(if executed without arguments) is used to display a list of files in the current directory.

To list files in a directory /home/vasya/.ssh do:

Ls /home/vasya/.ssh

2. cd

Team CD used to navigate through the directory tree (move to another folder).

For example, to go to the directory /home/vasya/.local need to be done

Cd /home/vasya/.local

3.mv

Team mv used to move (or rename) files and directories.

For example, to move a directory /home/vasya/documents to the directory /home/vasya/secret do:

Mv /home/vasya/documents /home/vasya/secret

4.cp

Team cp creates a copy of a file or directory.

To copy a file messages.log to file messages.log.bak do:

Cp messages.log messages.log.bak

To copy a directory, you need to add an argument after the command -r. For example, let's copy the directory drivers V display-drivers:

Cp -r drivers display-drivers

5. sudo

Team sudo used to execute other commands as superuser. But you need to use it carefully, as it can damage the system.

For example, if you try to create a copy of a file in the "system" directory /etc, you will receive a warning Permission denied. Therefore, in this case the command must be executed as a superuser, for example:

Sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.bak

6.touch

Team touch you can create an empty file.

For example, let's create an empty file path.dat:

Touch path.dat

7.find

Team find designed to search for files. Yes, this is not the simplest command, but knowing it is very useful. To begin with, just remember how to search for files and directories by name or by mask (part of the name).

For example, let's find in the current directory all files (and directories) whose names begin with document, and ends odt(these may be files document-history.odt, document1.odt, document.odt, document-linux.odt):

Find. -name "document*.odt"

Explanation: the dot symbol after the command means that we are searching in the current directory (and in all directories within the current one). After the argument -name The file name or mask (pattern) by which we are searching is written in quotes. The asterisk symbol in a mask means that any symbols can replace the asterisk.

8. cat

Team cat displays content specified file to the screen.

For example, to view the contents of a file /var/log/auth.log do:

Cat /var/log/auth.log

9.nano

In fact nano this is a console text editor. But sometimes, this is one of the few ways to edit a file from the command line (for example, when the GUI does not load or is missing).

For example, to create or edit existing file ftp.cfg do:

Nano ftp.cfg

A text editor will open. Make changes to the file. Then press the keyboard shortcut Ctrl+x and enter y to save changes and exit (or enter n to close the file without saving changes).

10.mkdir

Team mkdir creates an empty directory.

For example, to create a backup directory, run:

Mkdir backup

rm and rmdir

These are the eleventh teams in my selection, since I believe that beginners need to learn about them last. Team rm serves to delete files. rmdir is intended for deleting directories.

For example, delete the file veryimportantfile.dat:

Rm veryimportantfile.dat

To delete a directory, use the command command rmdir. For example, let's delete the directory photos:

Rmdir photos

apt or apt-get

And one more important command for those who use Ubuntu. apt is a package manager that is used to install and remove programs (packages), and update the system.

For example, to install the console file manager Midnight Commander, run:

Sudo apt install mc

If apt is not available, then use apt-get:

Sudo apt-get install mc

Something else?

I'm sure I haven't written a lot of important commands yet. So please add others in the comments. must have commands that you think will be very useful for beginners.

Did you know that Linux is not just for serious admin work? You can play text games on it, talk to the terminal, or even create beautiful ASCII pictures on it. Yes, Linux is really fun if you know the right commands. Let's look at commands that can make you smile or that you can enter at the end of a difficult work day and get a breath of fresh air in the form of positive emotions. You will return home in a good mood.

1)Get a random quote with the fortune command

You can get random quotes and funny predictions using the fortune command. In this case, it is necessary that the fortune package be installed on your system.
To install fortune on systems with apt or aptitude:

Linuxtechi@linuxarena:~$ sudo apt-get install fortune

To install fortune on yum systems like CentOS/RHEL/Fedora, enter the following lines:

# yum install fortune*

Once the installation is complete, enter the fortune command. The result can be seen just below.

2) Team Rev

This command expands any string given to it. The command is available immediately after installing Linux.

# rev
LinuxTechi
ihceTxuniL
Linux Rocks
skcoR xuniL
Opensource World
dlroW ecruosnepO
Linux Mint Ultimate Desktop
potkseD etamitlU tniMxuniL

You can even create a file with a list of names and then provide this file team. In this case, all names from the file will be expanded.

# rev rev.txt
ihceTxuniL
skcoR syawla xuniL
dlrow ecruosnepO fo enobkcab eht si xuniL
ihceTxuniL moob moob
#

3) Yes command

The yes command will endlessly display the text given to it until you force it to stop (CTRL+C).

Syntax:

# yes TEXT

# yesLinuxTechi.com
LinuxTechi.com
LinuxTechi.com
LinuxTechi.com
LinuxTechi.com
LinuxTechi.com
LinuxTechi.com
LinuxTechi.com
LinuxTechi.com
LinuxTechi.com^C
#

4) Turn the terminal into an aquarium

Did you know that you can turn your Lnux system terminal into a beautiful aquarium with fish and algae? To do this, you will need to install the term animator, libcurses, and asciiaquarium packages on your system.

Before following the instructions, make sure you have the 'perl', 'perl-Curses' and 'perl-devel' packages installed.

For systems with yum:

# yum install perl perl-devel perl-Curses

For Debian systems:

Linuxtechi@linuxarena:~$ sudo apt-get install perl libcurses-perl

Now you can start installing this awesome command.

First, make sure you download the term animator package:

# wget http://search.cpan.org/CPAN/authors/id/K/KB/KBAUCOM/Term-Animation-2.6.tar.gz

Install the package as shown below.

# tar zxpvf Term-Animation-2.6.tar.gz
# cd Term-Animation-2.6
# perl Makefile.PL && make && make test
# make install

Attention: If you have difficulties with anything described above, then you can always use the cpan console and install the “Term Animation” package through it. You can do it like this:

Cpan> install Term::Animation

Finally download and install the asciiaquarium package. Here's how to do it:

# wget http://www.robobunny.com/projects/asciiquarium/asciiquarium.tar.gz
# tar zxpvf asciiquarium.tar.gz
# cd asciiquarium_1.1/
# cp asciiquarium /usr/local/bin/
# chmod 755 /usr/local/bin/asciiquarium

Now run the command

# /usr/local/bin/asciiquarium

#asciiquarium

5)Team Toilet

It is not at all clear why the team is called that way, because what it does has nothing to do with the latrine. This command produces beautiful titles made entirely of characters.

To install the toilet package on Debian based systems use the command below:

Linuxtechi@linuxarena:~$ sudo apt-get install toilet

For bases like CentOS or RHEL use:

# wget http://caca.zoy.org/raw-attachment/wiki/toilet/toilet-0.3.tar.gz
# tar zxpvf toilet-0.3.tar.gz
# cd toilet-0.3
# ./configure && make && make install

Linuxtechi@linuxarena:~$ toilet LinuxTechi Rocks

Toilet provides a wide range of features such as fonts, colorful symbols and filters. Use the man page for the toilet command to see more options.

6) Set your terminal on fire

Don't worry, this command will only display symbols that form flames in your terminal.

Install a package that will allow you to issue the aafire command on a Debian-based system:

Linuxtechi@linuxarena:~$ sudo apt-get install libaa-bin
linuxtechi@linuxarena:~$ aafire

7) Ask the cow to repeat what he wrote

cowsay is another fun Linux command that displays the entered sentence as a statement from a cow or any other animal of your choice.

Linuxtechi@linuxarena:~$ sudo apt-get install cowsay
linuxtechi@linuxarena:~$ cowsay Linux world Rocks

cowsay can be used in conjunction with the fortune command. An example can be seen just below:

Linuxtechi@linuxarena:~$ fortune | cowsay

8)Enter the world of the matrix

Let's brush up on the matrix using the cmatrix command.

The cmatrix command is not available by default. To install it on a Debian based system you need to enter the following:

The matrix starts like this:

Linuxtechi@linuxarena:~$ sudo apt-get install cmatrix

9) Do you love Jerry the mouse?

Are you tired of the old dark mouse pointer, so much so that you would like to do something special with it? The "oneko" package will help you. It attaches the famous Jerry mouse to your mouse pointer. As a result, wherever you point the pointer, the mouse will follow it. Quite funny, isn't it?

To install the oneko package on a Debian-based system, enter:

Linuxtechi@linuxarena:~$ sudo apt-get install oneko

Once the installation is complete, type the command "oneko" .

10) Make the terminal talk to you

Turn on your speakers, because with the espeak command you can make your Linux terminal speak. First, let's install the espeak package.

Linuxtechi@linuxarena:~$ sudo apt-get install espeak

For systems with yum:

Execute the espeak command with the text:

Linuxtechi@linuxarena:~$ espeak "LinuxTechi is the best Website for Linux guide and tutorials"

11) Steam locomotive in your terminal

Everyone knows the "ls" command, which can be used to display the contents of a directory, but do you know the "sl" command? This is a fun command that draws a steam locomotive in your ASCII terminal.

"sl" is not a basic command, so it's worth installing first.

For Debian based systems, enter:

Linuxtechi@linuxarena:~$ sudo apt-get install sl

For systems with yum:

# yum install espeak

Run the sl command and enjoy:

# sl

12) Let's watch Star Wars

Want to go back to school when you were fascinated by Star Wars characters? Of course, you can’t watch a movie in the terminal, but you can quite enjoy scenes from the movie in ASCII format.

# telnet towel.blinkenlights.nl

You just need to wait a little and the Star Wars scenes will be displayed in ASCII format.









To stop, press ctrl combination+]. Once the telnet terminal appears, enter quit in it.

This is where the article ends. I hope you enjoyed the teams. If you know any other similar commands, be sure to share them in the comments!

Whoami #display the name under which you are registered date #display the date and time time<имя программы>#execute a program or command and get information about the time #required for its execution who #determine which user is running on the machine uname -a #display version information operating system cat /etc/issue #show the operating system version (12.04, 13.04 etc.) lsb_release -a #distribution name and version uname -m #find out how many bits are in linux OS free #display information on memory usage df -h #display information about free and used disk space uptime #shows current time, time elapsed since loading the OS, number of current #users in computer system and load for the last 1, 5 and 15 minutes top (htop) #displays a list of processes running in the system and information about them ps axu | grep php #list of processes whose name contains php ps aux | head -n 1; ps aux | grep:searchd #processes with explanation of parameters above netstat -lnp | grep:9000 #find out what's hanging on port 9000 netstat -luntp #shows all open ports with applications using them lsusb #information about devices connected via USB lscpu #processor characteristics

Here I will only briefly describe the main commands. You can learn more about most commands online by contacting the Help. Linux system using the man command. To make it easier to remember, from the word man ual:

Man<имя изучаемой команды>

To execute certain commands, such as setting access rights to system files and much more, you need rights superuser. To execute a command on behalf of superuser, you need to write before the command name sudo(for example: sudo service nginx restart). In some debian systems sudo may not be installed by default (but can be installed with apt-get install sudo). To install sudo you need to log in using root`om:

When prompted for a password, you must enter the superuser password. After which any command will be executed as the superuser root.

Eugene@PCname:~$ su - Password: root@PCname:~#<команда, которая выполнится от имени root>

Common Linux Commands

Here is a list of useful commands that are not included in other sections.

Sudo shutdown -h now #shut down the computer now sudo shutdown -h 90 #shut down the computer in 90 minutes. sudo reboot #reboot the computer wget --convert-links -r http://www.linux.org/ #copy the entire site and convert links for battery life#copying occurs 5 levels deep!! #execute last executed command history | tail -50 #show the last 50 typed commands passwd #changes the password of the current user cal -3 #shows the previous, current and next month in a convenient form (like a calendar)

Working with Linux files and directories

ls #show a list of files in the current directory (list) ls -la<имя каталога>#list of files in the directory<имя каталога>, including hidden pwd #prints current path (current directory command) cd [directory] #change current directory (change directory) cp<что_копировать> <куда_копировать>#copy files (copy) mv<что_перемещать> <куда_перемещать>#move or rename file (move) mkdir<каталог>#create a new directory (make directory) rmdir<каталог>#remove directory rm<файлы>#delete files (remove) rm -rf<имя каталога>#removing a directory along with its subfiles locate /var/www*index.php #find all files with names ending in index.php #in the directory /var/www tail<имя файла>#prints the end of the file. Convenient when working with logs and large du files. -bh | more #display information about the size of files and directories, starting from the current directory sudo chmod 777 -R ~/Public #read/write/execute permission for everyone on the directory ~/Public # -R - recursively, that is, on everything subfiles and folders sudo chown<имя пользователя> <имя файла>#set file owner >filename #makes filename an empty file, i.e. erases the contents touch filename #creates an empty file, also changes the time last change file

Linux commands that give information about the system

whoami #display the name under which you are registered date #display the date and time time<имя программы>#execute a program or command and get information about the time #required for its execution who #determine which user is running on the machine uname -a #display information about the operating system version cat /etc/issue #show the operating system version (12.04, 13.04 etc .) lsb_release -a #distribution name and version uname -m #find out how many bits are in Linux OS free #display information on memory usage df -h #display information about free and used disk space uptime #shows the current time, elapsed time after loading the OS, the number of current #users in the computer system and the load for the last 1, 5 and 15 minutes of work after boot, #the number of current users in the computer system and the load for the last 1, 5 and 15 minutes top (htop) #displays a list of workers in the system of processes and information about them ps axu | grep php #list of processes whose name contains php ps aux | head -n 1; ps aux | grep:searchd #processes with explanation of parameters above netstat -lnp | grep:9000 #find out what's hanging on port 9000 netstat -luntp #shows all open ports with applications using them lsusb #information about devices connected via USB lscpu #processor characteristics

How to terminate a process? If during withdrawal top press k (from the word kill), you will be prompted

PID to kill:

you need to enter the process identifier (PID) and then press enter. This is something like the task manager in Windows.

Working with Linux archives

tar cf primer.tar /home/primer.txt #create a tar archive named primer.tar, #containing /home/primer.txt tar czf primer.tar.gz /home/primer.txt #create a tar archive with Gzip compression by #name primer.tar.gz tar xf primer.tar #unpack the primer.tar archive into the current folder tar xzf primer.tar.gz #unpack the tar archive with Gzip tar xjf primer.tar.bz #unpack the tar archive from Bzip2

Examples of searching text and files in Linux

grep -rl "what are we looking for" /path #search for files recursively with the text #"what are we looking for" along the path "/path" less ~/Documents/http.txt | grep -A 2 "skype" #search the file ~/Documents/http.txt, #will display the matching line + 2 next lines tail -f -n100 ~/logs/php-error.log #very convenient feature for reading logs #in prints the last 100 lines of the find file in real time. -name "*.php" -mtime -1 -print #recursive search for files using the pattern (mask) "*.php" #that have changed in the last 24 hours find /var/www/ -mtime -10 #search for files that have been changed in the last 24 hours last 10 days find /var/www/ -mtime -10 > filename.txt #write output to file find . -perm 777 | xargs rm #find all files with permissions 777 and delete them find . -name cache | xargs chmod -R 777 #find the cache directory and give it permissions 777

Execute pieces of code on the command line (php, python):

Php -r "var_dump(strlen("hello"));" python -c "print("hello");"

This is an incomplete list of commands that have already been very useful to me. As we learn Linux, the post will be updated with other commands.

In all operating systems, including Linux, the term "command" means either a command line utility or a specific feature built into the system's command shell. However, for the users themselves this difference does not matter much. After all, both Linux terminal commands are invoked in the same way. You enter a word into your terminal emulator and get the command output.

I have already written about Linux terminal commands, but then I touched only on a few of the most interesting, most useful commands, relying on the fact that the user is already quite familiar with the capabilities of the terminal. But we need to make one more article, aimed at beginners, those who are just taking their first steps in mastering Linux.

And here she is. Its goal is to collect the basic simple and complex Linux commands that every user should know in order to most effectively manage their system. To make it easier to remember the command options, I added in parentheses the words from which they originated - it’s much easier, I’ve tested it myself.

This does not mean that I will list all the commands - I will try to cover all the most useful things that can be useful in everyday life. To make it easier to read, we will divide this list into categories of commands by purpose. Most of the utilities discussed here do not require additional installation, they will be pre-installed in any Linux distribution, and if not, then they are easy to find in the official repositories.

1.ls

A utility for viewing the contents of directories. By default shows the current directory. If you specify a path in the parameters, it will list the contents of the destination directory. Useful options -l ( L ist) and -a ( A ll). The first formats the output as a list with more detailed information, and the second includes showing hidden files.

2.cat

Prints the contents of the file passed as a parameter to standard output. If you transfer several files, the command will merge them. You can also redirect output to another file using the ">" symbol. If you only need to print a certain number of lines, use the -n option ( N umber).

3. cd

Allows you to move from the current directory to the specified one. If run without parameters, it returns to the home directory. A call with two dots returns one level up from the current directory. Calling with a dash (cd -) returns to the previous directory.

4.pwd

Prints the current directory to the screen. This may be useful if your Linux command line does not output such information. This command will be useful in Bash programming, where a script is executed to obtain a link to a directory.

5.mkdir

Creation of new directories. The most convenient option is -p ( P arents), allows you to create an entire subdirectory structure with one command, even if they do not exist yet.

6. file

Shows the file type. IN Linux files you don't always have to have extensions to work with them. Therefore, it is sometimes difficult for the user to determine what kind of file is in front of him. This little utility solves the problem.

7.cp

Copying files and directories. It does not copy directories recursively by default (that is, all subdirectories and all files within subdirectories), so be sure to add the -r option ( R ecursive) or -a ( A rchive). The latter includes a mode for storing attributes, owner and timestamp in addition to recursive copying.

8.mv

Moving or renaming files and directories. It is noteworthy that in Linux this is the same operation. Renaming is moving a file to the same folder with a different name.

9.rm

Deletes files and folders. Very useful command Linux: You can use it to clean up all the clutter. If you need recursive deletion, use the -r option. However, be careful: of course, in order to damage the system you will need to seriously try, but you can delete your own important files. Rm does not delete files to the recycle bin, from which everything can then be restored, but completely erases them. Operator actions rm irreversible. Believe me, your excuses like “rm ate my coursework” will not be interesting to anyone.

10.ln

Creates hard or symbolic links to files. Symbolic or soft links are something similar to shortcuts in Windows. They provide a convenient way to access specific file. Symbolic links point to a file but do not have any metadata. Hard links, unlike symbolic links, point to the physical address of the disk area where the file data is stored.

11.chmod

Changes file permissions. These are read, write and execute. Each user can change the permissions for their files.

12. chown

Changes the owner of a file. Only the superuser can change owners. To change recursively, use the -R option.

13.find

Search the file system, files and folders. This is a very flexible and powerful Linux command, not only because of its sniffer abilities, but also because of its ability to execute arbitrary commands on the files it finds.

14. locate

Unlike find, the locate command searches the updatedb database for filename patterns. This database contains a snapshot file system, which allows you to search very quickly. But this search is unreliable because you can't be sure that nothing has changed since the last snapshot.

15.du

Shows the size of a file or directory. The most useful options: -h ( H uman), which converts file sizes to an easy-to-read format, -s ( S ummarize), which outputs minimal data, and -d ( D epth), which sets the depth of recursion across directories.

16.df

Disk space analyzer. By default, the output is quite detailed: all file systems are listed, their size, amount of used and free space. For convenience, there is an option -h, which makes the dimensions easy to read.

17.dd

As stated in the official manual, this is a terminal command for copying and converting files. Not a very clear description, but that's all dd does. You give it the source file, destination and pair additional options. It then makes a copy of one file to another. You can specify the exact size of the data to be written or copied. The utility works with all devices. For example, if you want to overwrite HDD zeros from /dev/zero, you can do this. It is also often used to create LiveUSB or hybrid ISO images.

18 mount/umount

These are Linux console commands for mounting and unmounting Linux file systems. You can connect everything: from USB drives, to ISO images. And only the superuser has the rights to do this.

Linux console commands for working with text

19. more / less

These are two simple terminal commands to view long texts, which do not fit on one screen. Imagine a very long command output. Or you called cat to view a file and your terminal emulator took a few seconds to scroll through all the text. If your terminal doesn't support scrolling, you can do it with less. Less is newer than more and supports more options, so there's no reason to use more.

20. head/tail

Another pair, but here each team has its own area of ​​application. Head prints the first few lines of the file (head), and tail prints the last few lines (tail). By default, each utility outputs ten lines. But this can be changed using the -n option. Another useful parameter-f is short for f ollow (follow). The utility constantly displays changes in the file on the screen. For example, if you want to monitor a log file instead of constantly opening and closing it, use the tail -nf command.

21. grep

Grep, like other Linux tools, does one thing, but it does it well: it searches for text based on a pattern. By default it accepts standard input, but you can search in files. The pattern can be a string or regular expression. It can display both matching and non-matching strings and their context. Any time you run a command that produces a lot of information, you don't need to parse everything manually - let grep do its magic.

22.sort

Sorting lines of text according to various criteria. Most useful options:-n ( N umeric), by numeric value, and -r ( R everse), which reverses the output. This can be useful for sorting the output of du. For example, if you want to sort files by size, simply combine these commands.

23.wc

Linux command line utility for counting words, lines, bytes and characters.

24. diff

Shows the differences between two files in a line-by-line comparison. Moreover, only the lines in which differences are found are displayed. Changed lines are marked with the symbol "c", deleted ones with "d", and new ones with "a".

By the way, I have prepared another detailed article, which describes it using the terminal.

Linux commands for managing processes

25. kill/xkill/pkill/killall

Serve to terminate processes. But they accept different parameters to identify processes. Kill needs the PID of the process, xkill - just click on the window to close it, killall and pkill take the name of the process. Use the one that is convenient in a certain situation.

26.ps/pgrep

As already mentioned, to kill a process, you need its identifier. One way to get it is with the ps utility, which prints information about running processes. By default the output is very long, so use the -e option to see information about a specific process. This is only a snapshot of the state at the time of the call and the information will not be updated. The ps command with the aux switch outputs full information about processes. Pgrep works like this: you give the process a name, and the utility displays its ID.

27.top/htop

Both commands are similar, both display processes and can be used as console system monitors. I recommend installing htop if your distribution doesn't come with it by default, as it is an improved version of top. You can not only view, but also control processes through its interactive interface.

28. time

Process execution time. This is a stopwatch for program execution. Useful if you are interested in how far your implementation of an algorithm lags behind the standard one. But despite its name, it will not tell you the current time; use the date command for this.

Linux user environment commands

29.su/sudo

Su and sudo are two ways to accomplish the same task: run a program as a different user. Depending on your distribution, you probably use one or the other. But both work. The difference is that su switches you to another user, while sudo only runs the command on their behalf. Therefore, using sudo will be the safest option to work with.

30.date

Unlike time, it does exactly what you'd expect it to do: print the date and time to standard output. It can be formatted depending on your needs: display year, month, day, set 12 or 24 hour format, get nanoseconds or week number. For example, date +"%j %V" will output the day of the year and week number in ISO format.

31. alias

The command creates synonyms for other Linux commands. That is, you can create new commands or groups of commands, as well as rename existing ones. This is very useful for shortening long commands that you use frequently, or creating clearer names for commands that you use infrequently and cannot remember.

32. uname

Displays some basic information about the system. Without parameters, it will not show anything useful except the Linux line, but if you set the -a parameter ( A ll), you can get information about the kernel, hostname and processor architecture.

33.uptime

Tells you the operating time of the system. Not very significant information, but can be useful for random calculations or just for fun to find out how long ago the server was rebooted.

34. sleep

You're probably wondering how you can use it. Even without Bash scripting, it has its advantages. For example, if you want to turn off your computer after a certain period of time or use it as an impromptu alarm.

Linux Commands for User Management

35. useradd/userdel/usermod

These Linux console commands allow you to add, remove, and change user accounts. Chances are you won't use them very often. Especially if this is a home computer and you are the only user. You can manage users using the GUI, but it's better to know about these commands just in case.

36. passwd

This command allows you to change the password account user. As a superuser, you can reset everyone's passwords even though you can't see them. It is a good security practice to change your password frequently.

Linux commands to view documentation

37.man/whatis

The man command opens a manual for a specific command. There are man pages for all basic Linux commands. Whatis shows which manual sections there are for a given command.

38. whereis

Shows the full path to the program's executable file. It can also show the path to the sources, if they are in the system.

Linux Commands for Network Management

39.ip

If the list of Linux commands for network management seems too short to you, you are most likely not familiar with the ip utility. The net-tools package contains many other utilities: ipconfig, netstat and other outdated ones, like iproute2. All this is replaced by one utility - ip. You can view it as a Swiss army knife for networking or as an incomprehensible mass, but either way, it is the future. Just deal with it.

In this article we will look at the basic Linux commands that will be useful for beginners in mastering this operating system.

What is Linux?

Linux is the operating system kernel. You may have heard of UNIX. Well, Linux is a clone of UNIX. It was created by Linus Torvalds of Scratch. Linux is free and open source - you can simply change anything in Linux and redistribute it under your own name! There are several builds on Linux based, usually called distributions.

  • Ubuntu Linux
  • Red Hat Enterprise Linux
  • Linux Mint
  • Debian
  • Fedora

Linux is mainly used on servers. About 90% of the Internet runs on Linux servers and that's why.

Linux is free, but the main problem with using Windows servers is their cost. Linux is fast: The OS that runs on about 80% of the world's smartphones, Android, is also made from Linux kernels. Linux is safe and most of the viruses in the world run on Windows.

Linux Shell or "Terminal"

Linux Shell is a program that receives commands from the user and passes them to the OS for processing and displays the output. Shell Linux is its main part. Most distributions come with graphical interface user interface (GUI), but mostly server Linux uses CLI (command line interface).

In this tutorial, we will look at the basic commands that we use in the Linux shell.

To open a terminal, click Ctrl + Alt + T in Ubuntu or click Alt+F2, type gnome-terminal and press enter. On the Raspberry Pi, enter lxterminal.

Linux Commands

Basic commands

1.pwd- when you first open a terminal, you are taken to your user's home directory. To find out which directory you are in, you can use the "pwd" command. This command displays the full path from the root directory to the current working directory: in the context in which (by default) the entered commands will be executed. The root is the basis of the Linux file system. Indicated by a slash (/). The user directory usually looks like "/home/username".

Result of pwd command in linux

2.ls- use the "ls" command to find out what files are in the directory you are in. You can see everything hidden files using the command "ls -a".


result of ls command in linux

3. cd- use the "cd" command to change to a directory. For example, if you are in your home folder and want to go to your downloads folder, you can type " CD Downloads" Remember that this command is case sensitive and you must enter the folder name exactly as it is. But there is one caveat. Imagine you have a folder named "Raspberry Pi". In this case, when you enter " cd Raspberry Pi", the shell will accept the second argument of the command as something else, so you will get an error message saying that the directory does not exist. Here you can use a backslash, i.e.: " cd Raspberry\ Pi" Spaces work like this: if you just type " CD” and press enter, you will be taken to your home directory. To go back from a folder to a previous folder, you can type "cd..". Two dots return to the previous directory.

result of cd command in linux

4. mkdir and rmdir- use the mkdir command when you need to create a folder or directory. For example, if you want to create a directory called "DIY", you can enter " mkdir DIY" Remember, as already said, if you want to create a directory named "DIY Hacking", you can enter " mkdir DIY\ Hacking" Use rmdir to remove a directory. But rmdir can only be used to delete an empty directory. To remove a directory containing files, use the rm command.

result of mkdir and rmdir command in linux

5.rm- use the rm command to remove files and directories. Use "rm -r" to remove only the directory. It deletes both the folder and the files it contains when using only the rm command.


result of rm command in linux

6.touch- The touch command is used to create a file. This could be anything from an empty txt file to an empty zip file. For example, " touch new.txt».

result of touch command in linux

7. man And --help- To learn more about the command and how to use it, use the man command. Shows the command's help pages. For example, " man ls" shows the man pages for the ls command. Typing the command name and argument helps show how the command can be used (for example, cd --help).


result of cd --help command in linux

8.cp- use the cp command to copy files via the command line. It takes two arguments: the first is the location of the file to be copied, the second is where to copy.

result of cp command in linux

9.mv- use mv command to move files via command line. We can also use the mv command to rename a file. For example, if we want to rename the file "text" to "new", we can use " mv text new" It takes two arguments, just like the cp command.

result of mv command in linux

10.locate- The locate command is used to locate a file on a Linux system, just like the search command on Windows. This command is useful when you don't know where the file is saved or the actual file name. Using the -i argument with the command helps ignore case (it doesn't matter if it's uppercase or lowercase). So, if you want a file with the word "hello", it gives a list of all the files on your Linux system that contain the word "hello" when you type "locate -i hello". If you remember two words, you can separate them with an asterisk (*). For example, to find a file containing the words "hello" and "this", you can use the command "locate -i * hello * this".

Intermediate commands

1. echo- The "echo" command helps us move some data, usually text, into a file. For example, if you want to create a new text file or add to an already created text file, you just need to type "echo hello, my name is hich >> new.txt". You don't need to separate spaces with a backslash here because we enclose in two triangle brackets when we end what we need to write.

2.cat- Use the cat command to display the contents of a file. Typically used for convenient viewing of programs.

result of echo command in linux

3. nano, vi, jed- nano and vi are already installed text editors in the command line Linux string. The nano command is a good text editor that marks keywords color and can recognize most languages. And vi is simpler than nano. You can create new file or edit the file using this editor. For example, if you need to create a new file called "check.txt", you can create it using the "nano check.txt" command. You can save your files after editing using the sequence Ctrl + X then Y (or N for no). In my experience, using nano to edit HTML doesn't look very good because of its color, so I recommend jed text editor. We'll start installing packages soon.

4. sudo- A widely used command in the Linux command line, sudo stands for "SuperUser Do". So if you want any command to be executed as an administrator or root, you can use the sudo command. For example, if you want to edit a file such as viz. alsa-base.conf, which requires root rights, you can use the command - sudo nano alsa-base.conf. You can enter the root command prompt using the "sudo bash" command and then enter your user password. You can also use the "su" command, but before that you need to install root password. To do this, you can use the command "sudo passwd" (not misspelled, it's passwd). Then enter New Password root.

5.df- use the df command to see the available disk space on each partition of your system. You can simply type df on the command line and see each mounted partition and its used/available space in % and in kilobytes. If you want it to be displayed in megabytes, you can use the "df -m" command.


result of df -m command in linux

6.du- Use du to find out how a file is used on your system. If you want to know the disk space size of a specific folder or file in Linux, you can enter the df command and the name of the folder or file. For example, if you want to know the amount of disk space used by the documents folder in Linux, you can use the "du Documents" command. You can also use the "ls -lah" command to view the sizes of all files in a folder.

7. tar- Use tar to work with tarballs (or files compressed in a tarball archive) on the Linux command line. It has a long list of uses. It can be used for compression and decompression various types archives tar, such as .tar, .tar.gz, .tar.bz2 etc. It works based on the arguments given to it. Eg, " tar -cvf" for creating .tar archive, - xvf to unpack the .tar archive, - tvf to view the contents of the archive, etc.

8. zip, unzip- use zip to compress files into a zip archive and unzip to extract files from a zip archive.

9. uname- use uname to show information about the system your Linux distribution is running on. Using the "uname -a" command will display most information about the system: kernel release date, version, processor type, etc.

result of uname -a command in linux

10.apt-get- use apt to work with packages on the Linux command line. Use apt-get to install packages. This command requires root privileges, so use the sudo command with it. For example, if you want to install the text editor jed (as I mentioned earlier), we can enter the command “sudo apt-get install jed”. Likewise, any packages can be installed as follows. It is recommended to update your repository every time you try to install a new package. You can do this by typing "sudo apt-get update". You can upgrade your system by typing "sudo apt-get upgrade". We can also upgrade the distribution by typing "sudo apt-get dist-upgrade". The "apt-cache search" command is used to search for a package. If you want to search for it, you can type "apt-cache search jed" (this does not require root).


11.chmod- use chmod to make a file executable and change the permissions granted to it in Linux. Imagine you have Python code on your computer called numbers.py. You will need to run "python numbers.py" every time you need to run it. Instead, when you make it executable, you just need to run "numbers.py" in a terminal to run the file. To make the file executable, you can use the command "chmod + x numbers.py" in this case. You can use "chmod 755 numbers.py" to give it root permissions, or "sudo chmod + x numbers.py" to executable file root. Here's a little more.

12.hostname- Use the command hostname to find out your name on your host or network. Basically, it displays your hostname and IP address. Simply typing "hostname" will give you the hostname. By typing “hostname -I” you will get your IP address on the network.

13.ping- use ping to test your connection to the server. Wikipedia says: "Ping is an administrative utility computer network, used to test the availability of a host on an Internet Protocol (IP) network.” For example, when you type, " ping google.com", it checks if it can connect to the server and get back. It measures this round trip time and gives you detailed information about him. You can also use this command to check your Internet connection. If it pings the Google server (in this case) - the Internet connection is active!


ping command result in linux
  • You can use the command clear to clear the terminal if there are too many commands accumulated there.
  • TAB can be used to fill in the terminal. For example, you just need to type "cd Doc" and then TAB, and the terminal fills in the rest and makes it "cd Documents".
  • Ctrl+C can be used to safely stop any command in the terminal. If Crtl+C did not work, then you can use Ctrl+Z to stop a process running in the terminal.
  • You can exit the terminal using the command exit.
    You can shut down or restart your computer using the commands sudo halt And sudo reboot.


2024 wisemotors.ru. How it works. Iron. Mining. Cryptocurrency.