Basic unix commands. Command line Using the Apt package manager

  1. && . Strictly speaking, this is not a team. If you want to execute several commands at once, put a double ampersand between them like this: first_command && second_command. The terminal will execute the commands in order. You can enter as many commands as you like.
  2. alias Assigns names you create to long commands that you can't remember. Enter the alias long_command short_command.
  3. cd. Changes the current terminal folder. When you start the terminal, it uses your home folder. Enter cd folder_address, and the terminal will work with the files that are located there.
  4. clear. Clears the terminal window of all messages.
  5. history. Displays all the commands you have recently entered. Additionally, you can switch between recent commands using the Up and Down keys. If you do not want the command you entered to be written down, put a space in front of it like this: your_command.
  6. man. Displays a guide to programs and commands. Type man package_name or man your_command.
  7. whatis. Displays a brief description of a program. Enter the command and the program name whatis package_name.

To perform many actions on the system, such as installing and uninstalling programs, you will need administrator rights, or the superuser root as it is called in Linux.

  1. sudo This command will give you superuser rights. Type sudo before the command you want (for example, sudo apt upgrade) to run it as an administrator. The system will ask you for your password.
  2. sudo su . After this command, all commands you enter will be executed as the superuser until you close the terminal. Use it if you need to run a lot of commands with administrator rights.
  3. sudo gksudo . Command to run a GUI application with administrator rights. For example, if you want to move or change system files, type sudo gksudo nautilus (indicate the file manager you use).
  4. sudo!! . This command will run the previously entered command with administrator rights. Useful if you typed the command without sudo .

Do not execute commands as superuser that you do not understand.

Installing and uninstalling applications in Linux is performed by package managers. In Ubuntu the package manager is called apt, in Fedora - dnf, in Arch and Manjaro - pacman. They download applications from online repositories, package sources. Commands should be given to them with superuser rights.

apt (Debian/Ubuntu/Mint)

  1. sudo apt install package_name. Install the required package.
  2. sudo apt-add-repository repository_address. Add a third-party repository.
  3. sudo apt update . Update package information.
  4. sudo apt upgrade . Update all packages to the latest (perform after apt update).
  5. sudo apt remove package_name. Remove unnecessary package.
  6. sudo apt purge package_name. Remove an unnecessary package with all dependencies if you want to free up more space.
  7. sudo apt autoremove . Remove all unnecessary dependencies, orphan packages and other garbage.

dnf (Red Hat/Fedora/CentOS)

  1. sudo dnf install package_name. Install the required package.
  2. sudo dnf config-manager --add-repo repository_address. Add a third-party repository.
  3. sudo dnf upgrade . Update all packages to the latest ones.
  4. sudo dnf remove package_name. Remove unnecessary package.
  5. sudo dnf autoremove . Remove all unnecessary dependencies.

pacman (Arch/Manjaro)

  1. sudo pacman -S package_name. Install the required package.
  2. sudo yaourt -S package_name. Install a package from AUR if it is not in the main repository.
  3. sudo pacman -Sy . Update package information.
  4. sudo pacman -Syu . Update all packages to the latest ones.
  5. sudo pacman -R package_name. Remove unnecessary package.
  6. sudo pacman -Rs package_name. Remove an unnecessary package with all dependencies.

You can install and remove several packages at once by simply listing them separated by a space.

sudo apt install firefox clementine vlc

If you want to install a package but don't know its exact name, type the first few letters of the package name and press Tab twice. The package manager will show all packages whose names start with the same name.

  1. kill. This command is used to forcefully terminate processes. You need to enter kill PID_process. The PID of a process can be found by typing top .
  2. xkill. Another command to end processes. Enter it, then click on the window you want to close.
  3. killall. Kills processes with a specific name. For example, killall firefox.
  4. top. Displays a list of running processes, sorted depending on CPU resource consumption. A kind of terminal “System Monitor”.

Viewing and editing files

  1. cat. When the command is used with a single text file (like this: cat file_path), it displays its contents in a terminal window. If you specify two or more files, cat path_to_file_1 path_to_file_2 , it will merge them. If you enter cat file_path_1 > new_file, it will merge the contents of the specified files into a new file.
  2. chmod. Allows you to change file permissions. Can be useful if you want to make changes to a system file.
  3. chown. Changes the owner of a file. Must be executed with superuser rights.
  4. file. Displays information about the specified file.
  5. nano . Opens a simple text editor. You can create a new text file or open an existing one: nano file_path.
  6. rename. Renames a file or several files. The command can also be used for files by mask.
  7. touch. Changes the date the specified file was last opened or modified.
  8. wget. Downloads files from the Internet into a terminal folder.
  9. zip. Unpacks and compresses archives.

Creating and deleting files and folders

  1. mkdir. Creates a new folder in the current terminal folder or in the specified folder: mkdir folder_path.
  2. rmdir. Deletes the specified folder.
  3. rm. Deletes files. It can delete both an individual file and a group that meets certain criteria.

Copying and moving files

  1. cp. Creates a copy of the specified file in the terminal folder: cp path_to_file. Or you can specify the destination cp path_to_file path_to_copy.
  2. mv. Moves a file from one folder to another. You can specify a name for the file to be moved. Funnily enough, in Linux this command can also be used to rename files. Just specify the same folder where the file is located and a different name.

Search files

  1. find . Search files by specific criteria, such as name, type, size, owner, creation and modification date.
  2. grep. Search for text files containing specific strings. The criteria are very flexible.
  3. locate. Searches for files and folders whose names match the query and displays their paths in the file system.

  1. lsblk. This command shows you what drives you have on your system and what partitions they are divided into. The command also displays the names of your partitions and drives, in the format sda1, sda2 and so on.
  2. mount Mounts drives, devices, or file systems so you can work with them. Typically, devices will connect automatically as soon as you click on them in the file manager. But sometimes you may need to mount something manually. You can connect anything: disks, external drives, partitions and even ISO images. This command must be executed with superuser rights. To mount an existing disk or partition, enter mount sdX .
  3. umount. Dismounts file systems. The umount sdX command will mount the external media's file system so you can eject it.
  4. dd. This command copies and converts files and partitions. It has many different uses. For example, dd if=/dev/sda of=/dev/sdb will make an exact copy of the sda ​​partition on the sdb partition. dd if=/dev/zero of=/dev/sdX will erase the contents of the specified media with zeros so that the information cannot be recovered. And dd if=~/Downloads/ubuntu.iso of=/dev/sdX bs=4M will make bootable media from the distribution image you downloaded.

Linux Commands for User Management

  1. useradd. Registers a new user. Enter useradd username and the user will be created.
  2. userdel. Deletes the user's account and files.
  3. usermod. Changes a user account. May move the user's home folder or set a date for the account to be locked.
  4. passwd. Changes account passwords. A regular user can only change the password for his own account; a superuser can change the password for any account.

Linux Commands for Network Management

  1. ip. Multifunctional team to work with the network. The ip address show command displays information about network addresses, ip route controls routing, and so on. By issuing the commands ip link set ethX up, ip link set ethX down, you can turn connections on and off. The ip command has many uses, so it's best to read the manual before using it, or type ip --help
  2. ping. Shows whether you are connected to the network and helps determine the quality of the connection.

And one more thing

Finally, the main Linux commands. They put a cow on the screen that can talk to you (don't ask what the developers use).

  1. cowsay anything. The cow will say what you tell it.
  2. fortune | cowsay. The cow will give out a smart (or not so smart) thought or quote.
  3. cowsay -l . Lists all animals that can be displayed in the terminal. In case you don't like cows.
  4. fortune | cowsay -f animal_from_list. The animal of your choice begins to spout quotes, sometimes relevant ones.
  5. sudo apt-get install fortunes fortune-mod fortunes-min fortunes-ru . Will force the entire zoo to speak Russian. Without this, animals quote Twain and Wilde.

These are not all Linux commands. If you need to know in detail the parameters and how to use Linux commands, you can use the built-in tutorial. Type man your_command or your_command --help .

One of the fundamental differences between the Linux OS family and Windows OS is the leading role of the command line or terminal in system administration. To successfully work with Linux, a graphical interface is not enough. Full control here is possible only through the terminal. And when working with the terminal, there is no way to do without learning the basic Linux commands.

Linux has several hundred basic commands and their modifications. They are grouped into several categories. By location - they can be command line utilities or a built-in command shell function. By frequency of use – used constantly, occasionally and rarely. By type of action - from getting help to managing files and processes. It is the third, functional component that will become the basis for the grouping of utilities in this article.

The review contains all the most important Linux commands that may be useful for administering the Linux OS. The article is intended for both beginners and advanced users who are already familiar with the basic functionality of the terminal. This unique cheat sheet can be safely added to the bookmarks of anyone who wants to extract the maximum useful properties from Linux and increase their productivity several times.

Help/Documentation

  1. man

    (Manual). Shows instructions to Linux programs and commands. To get the program manual, type:

    Man program_name

    For command instructions, enter:

    Man team_name

  2. whatis

    Outputs short description programs. Example:

    What is program_name

  3. whereis

    Shows full path to the executable file and other program files. Example:

    Whereis program_name

    Also provides information about program-related help information.

  4. file

    Shows what type of file is it?. The peculiarity of Linux is that working files may not have an extension. Therefore, the user may have problems identifying the files that this command removes.

  5. –help

    All necessary information about the team will be available if you type:

    Program_name --help

  6. whoami

    The command shows valid user ID(UID).

  7. TAB

    Shows options command auto-completion. Pressing the tab key after a certain command or sequence of commands displays a tooltip with options for possible continuation of the command.

  8. Ctrl+R

    This keyboard shortcut helps you launch reverse search for all parameters associated with the specified command. You just need to specify a keyword to search. There is a serious disadvantage - you can only see 1 result at a time. The combination Ctrl + C will help you exit the reverse search mode.

Superuser rights

A large number of basic Linux commands, such as installing programs or creating files in the root system, require root or superuser privileges to execute. The use of this mode brings serious changes to the operating system, so you need to understand exactly how the launched command will work.

Ways to get root rights in Linux

  • Login as superuser in the virtual console by entering the root username and password.
  • One-time switching to the superuser role in the terminal using special utilities.

Let's talk about the second option in more detail.

  1. sudo

    (Super User Do). Allows execute commands with superuser rights. Before switching to root administrator mode, the system will prompt you for the root password and login. Example:

    Sudo command_name

  2. sudo su

    The tool is used when you need to run some"superuser" commands. All following commands entered will run in superuser mode until the Command Prompt is closed.

  3. sudo gksudo

    Launches applications on behalf of the superuser, using not the terminal, but GUI. In the Kubuntu distribution, the name of this command looks slightly different - sudo kdesudo.

  4. sudo!!

    The command is used if you need to restart with root rights already given away(as a regular user) command.

Maximum performance of Linux applications depends on the correct choice of OS platform. A powerful one will provide the Internet resource with stable operation and space for development.

File and directory management

  1. ls

    (List). Using this utility you can see what's in the folder. Without specifying a specific path, shows the current directory. If the path is specified, then the transition is made to its final directory. To display the directory as a list with additional explanatory information, enter:

    To show hidden files:

  2. ll

    Command to view directory contents. The more modern alternative to this utility, ls -l, may not work on all Linux distributions.

  3. cat

    (Concatenate / Catenate). Dual purpose command. Shows on screen what does the file contain? or standard input. Also to "glues" several files transferred in a row into one. If you need to view the contents of one file, enter:

    Cat filename

    If you need to find out the contents of several files in a row:

    Cat file_№1 file_№2 file_№3

    To “glue” files, enter:

    Cat file_№1 file_№2 > file_№3

    To set the desired number of rows shown:

  4. CD

    (Change Directory). Changes current catalog, in which the terminal running on the specified one. When the terminal is launched, it uses the root directory by default, which you can return to by typing:

    To specify a different folder for working with files, you need to enter:

    CD folder_address

    To move up the directory tree one level, type:

    To return to the previous directory:

  5. &&

    The double ampersand is not a full-fledged command, but a control operator. It is designed to perform sequential a number of teams. In order for the terminal to execute the commands one after another, you need to separate them as follows:

    Team_No.1 && Team_No.2 && Team_No.3

    The number of commands in this sequence is not limited.

  6. mkdir

    (Make Directory). Creates new directory. You can also create a complete subdirectory structure by typing:

    Mkdir –p

  7. cp

    (Copy). A utility that allows copy file or directory. Copying files and directories. To make copying recursive, i.e., include all subdirectories and files in them, you need to add to the command:

    And if you need to supplement the recursive copying by saving all the attributes, information about the owner and the time stamp, add the “archive” option -a to get:

    Cp –r –a

  8. mv

    (Move). This command in Linux is also responsible for moving And renaming file or directory. When renaming, the file is moved to the same folder, but with a new name.

  9. rm

    (Remove). Responsible for deletion folders and files. The rm operator should be used with extreme caution. In Linux, files are not deleted into the trash, from where they can be restored, but are erased permanently. For recursive deletion, use the combination:

  10. ln

    Linux Link Types

  • symbolic (-s) – an indication of the address of a file or folder without metadata;
  • hard or hard (-P) - contains information about the physical address on the disk where the file is stored.
    You can remove a link in Linux using the –f attribute.
  1. chmod

    (Change Mode). Changes access permissions to the file. By access we mean the classic triad of reading r, modifying w, and running x. General form:

    Chmod permissions filename

    In this case, “permissions” can be indicated by an alphabetic, symbolic (rwx) or numeric code. Additionally, this variable can include owner information (u/g/o/a) and rights transactions (+/–/=).

Popular permission combinations for the chmod command

Type of permission Character code Numeric code
No clearance 0
Reading r– 4
Change -w- 2
Launch –x 1
Launch + Change -wx 3
Read + Run r-x 5
Read + Change rw- 6
Launch + Change + Launch rwx 7
  1. chown

    (Change Owner). Team for change of owner file and its group. To change the owner we use the syntax:

    Chown new_owner file_name

    To change a file group:

    Chown new_group file_name

    If you need to change both parameters:

    Chown new_owner:new_group file_name

    The command can only be used with superuser rights. To change the owner/group we recursively add:

    Chown–R

  2. chgrp

    (Change Group). Changes group file. Unlike chown, this command allows you to change groups only to those who are in it.

  3. dd

    (Dataset Definition). Allows copy data at the binary level from one place to another. The data can be of any size - from a CD/DVD image to an entire hard drive.
    The utility moves blocks of data from the specified source - if filename to the destination - of filename , which can be a device or a file. To copy multiple files, use the cp utility.
    This command must be handled with extreme caution, as evidenced by its alternative name "Data Destroyer". An error in data entry can easily cause data loss on the disk.

  4. df

    (Disk Free). Gives complete information about free space on disk. The analysis includes listing the file systems of mounted partitions and an overview of used and free disk space. For more convenient display of information, it is better to use the combination:

  5. du

    (Disk Usage). Allows determine size file or directory. Used together with additional operators:

  • df –h - represents size data in an easy-to-read format;
  • df –s - gives the required minimum data;
  • df –d - sets the recursion depth for directories.
  1. mount/umount

    Linux commands for installation and disconnection any file systems - from CDs and USB flash drives to OS kernels. The file system type is usually determined by the command itself by reading the superblock. The option is used only with superuser rights.

Navigation

  1. find

    Implements search in the file system, files and folders. You can run additional commands on search results.

  2. pwd

    Displays on screen current directory.

  3. clear

    Team complete cleaning terminal window deletes all previously printed messages.

  4. history

    Shows previously introduced user of the team. You can move through the list of entered commands by pressing “Up” and “Down” on the keyboard.

  5. locate

    Quick search files using the updatedb database for filename patterns. This database works with a snapshot of the file system, which greatly speeds up the search process. But there is also a significant disadvantage. The accuracy of the search depends on how up-to-date the file system data is in the current version of the snapshot.

  6. zcat/zless/zmore

    Viewing utilities compressed files. Using zcat you can find and see a list of compressed files, zless displays them in a page-by-page list with the ability to scroll forward and backward, and zmore only displays them forward.

  7. ;

    The semicolon is another operator for sequential start several commands on one line. If you want commands to be executed in parallel, use the statement like this:

    (command_#1 &); (command_#2 &); (team_№3 &)

Network management

  1. ip

    (Internet Protocol). The utility displays a complete list of parameters for network settings. Among them:

  • link - network device;
  • address - IP address of the network device;
  • monitor - device monitoring;
  • route - routing;
  • tunnel - tunneled.
    Each of the output objects can be changed using additional commands: add, change, del, save, etc.
  1. ping

    The team checks Availability and quality of Internet connection.

  2. nethogs

    Utility network activity monitoring devices in the system. To set the network interface, enter:

    Nethogs -i

  3. traceroute

    Utility internet connection tracking, tracking the routes of data packets in TCP/IP networks. A more advanced tool for tracking network connection problems than the ping command mentioned above. Runs only with superuser rights.

Working with Processes

  1. kill/xkill/pkill/killall

    Command variations for completion of operations. The main difference between them is the method of identification.

  • kill - Terminates an operation by finding it through the process identifier (PID).
  • xkill - graphical method. After entering the command, the cursor turns into a cross, which, when you click on the window of an open process, stops it;
  • pkill - Kills a specific process by finding it by name.
  • killall - kills all processes with the specified name.
  1. Ctrl +C

    This keyboard shortcut is another quick way complete execution of any process in the Linux terminal.

  2. Ctrl+Z

    The combination puts any process running in the console on pause. You can start it again by entering %.

  3. ps/pgrep

    (Process Status / Process-ID Global Regular Expressions Print). The commands find the specified parameters and display information about active processes. The most accessible way to find the process identifier (PID). The pstree modification shows the entire list (“tree”) of executing processes.

  4. top / htop / atop

    (Table of Processes). Three command options that call the console program monitoring active processes in system. The information is displayed in the form of a table with a list of processes in real time. It is recommended to use the two latest modifications of the program - they have more capabilities and advanced functions.

  5. crontab

    Run Cron (Command Run ON) - scheduled tasks in Linux.

  6. time

  • real - total execution time;
  • user - how much time the user took from the CPU;
  • sys - how much CPU time was spent by the system.

It will help to make the execution time of the Linux OS process minimal! A universal solution at an affordable price!

Working with archives

  1. gzip

    Creates archives with compressed files. The archive file will have a .gz extension.

  2. gunzip

    Team- unpacker for zip archives. Extracts compressed files and deletes the archived .gz file.

  3. tar

    Saves files and directories in the archive with a .tar extension. A convenient utility for creating backup copies or reliable archiving of data.

user management

  1. useradd/userdel/usermod

    Teams account management users. Allows you to add, delete and edit user profiles. Example:

    Useradd username.

  2. passwd

    Allows change account passwords. A regular user can only change the password associated with his name: passwd username. In superuser mode, you can “blindly” reset all user passwords in the system.

Work with text

  1. Ctrl + A / Ctrl + E

    Quick keys go to the beginning(A) and end(E) lines.

  2. Ctrl + Shift + C / Ctrl + Shift + V

    This keyboard shortcut in Linux will allow you to quickly copy(C) and insert(V) text in the terminal.

  3. more / less

    Two commands to make it easier viewing large texts, which do not fit on one terminal emulator screen. Because The commands are functionally the same, but less is newer and supports more options, it is recommended to use it.

  4. head / tail

    A pair of complementary commands for viewing on one screen beginning and end of text. The head command produces the first 10 (by default) lines of text, tail the last. The number of lines in both cases is changed using the -n argument. The -f operator allows you to monitor changes to a file on screen. To display the file log (log) in real time, enter the command:

    Tail –nf,

    To track logs of several files, a modification of the command is used - multitail.

  5. grep

    (Global Regular Expression and Print). Searches for text according to a given template. This is very useful when you need to analyze the work of a team, which is accompanied by a large amount of textual information. The template can be filled with a string or a regular expression. Example:

    Alias ​​old_name new_name

  6. sort

    Sorting text information on specified indicators. Additional variables allow you to:

  • -n - sort text lines by numerical value;
  • du - by size;
  • -r - apply reverse sorting;
  • -u - remove duplicates when sorting.
  1. wc

    (Word Count). Program for calculation of specified parameters in the text. Counts metrics such as characters, words, lines and bytes.

  2. diff

    (Difference). Produces line by line comparing two text files, drawing out the differences between them. Work algorithm:

    Diff file_№1 file_№2

    Differences between two versions of files are marked by symbols such as:

  • c - modified lines;
  • d - deleted lines;
  • a - new lines.

User environment

  1. su/sudo

    (Switch User / Substitute User & Do). Two commands to start processes on behalf of another user without ending the current session. When using su, the default is to switch to the root user. The sudo command can not only enable superuser mode (as mentioned above), but also execute a command as another user without actually switching to that user. Therefore, the second option is considered safer.

  2. date

    Linux command reporting time information. Individual variables can be used to set a convenient output format and the number of displayed parameters, down to milliseconds.

  3. alias

    Team for creating synonyms names of non-replaceable commands to abbreviate them. It changes the long name to a user-friendly short name or abbreviation. Example:

    Alias ​​old_name new_name

    This same technique is perfect for correct typos in teams. The unalias command will help you cancel the renaming utility.

  4. uname

    Utility that displays operating system information. Without additional parameters, it will only display the name of the kernel. To get all possible system information, enter:

  5. uptime

    Shows uptime – continuous operation time systems.

  6. sleep

    Sets sleep timer systems.

  7. yes

    Autocomplete utility consent fields in a command or script. Enter: yes team_name and you won’t have to confirm manually when the program’s interaction with the user requires it.

Package managers

Package managers (PMs) in Linux are responsible for installing, updating, and uninstalling applications. The principle of their operation is to download software packages from their own network repositories. These utilities only work with superuser rights. Different Linux distributions have their own versions of PM.

  1. apt

    PM for Debian, UbuntuAndMint

    Sudo apt install package_name

    To remove an application:

    Sudo apt remove package_name

  2. dnf/yum

    The two most common PMs for operating systems Red Hat, Fedora and CentOS. To install the application, enter:

    Sudo dnf install package_name

    To delete:

    Sudo dnf remove package_name

  3. pacman

    Distribution package manager Arch and Manjaro. To install the application, enter:

    Sudo pacman -S package_name

    To remove an application:

    Sudo pacman -R package_name

Conclusion

A complete list of commands for Linux distributions is more material for a lengthy book than for one article. However, in this review we tried to collect the most important of them. These commands are guaranteed to be useful both in everyday tasks and for unlocking the advanced capabilities of this operating system.

Each Linux user has his own list of must-have commands. Surely you have something to add to this review? Share your favorite Linux commands in the comments!

Do you want your operating system to work like a Swiss watch? A reliable and powerful platform for deploying any Linux distribution - !

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 Linux-based builds, commonly 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 here's why.

Linux is free, but the main problem with using Windows servers is their cost. Linux is fast: The OS that runs about 80% of the world's smartphones, Android, is also made from the Linux kernel. 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 a graphical user interface (GUI), but mostly server-based Linux uses a 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 all hidden files using the "ls -a" command.


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 enter “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 on the Linux command line. The nano command is a good text editor that colors keywords and can recognize most languages. And vi is simpler than nano. You can create a new file or change a 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 due to 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 privileges, 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 set the root password. To do this, you can use the command "sudo passwd" (not misspelled, it's passwd). Then enter your new root password.

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 to compress and decompress various types of 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 displays 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" for the root executable. 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 a computer network administration utility used to test the reachability 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 it. 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.

When starting to study the Linux console, you cannot do without knowledge of console commands.

This note lists the main Linux console commands, available both when working at the terminal and via ssh:
su, sudo, whoami, fsck, uptime, who, w, df, du, ifconfig, ping, traceroute, mtr, whois, ps, top, kill, killall, man, passwd, ls, pwd, mkdir, rmdir, rm, mv, cat, less, more, chmod, chown, tar, wget, find, locate, history, reboot, halt, shutdown

su Log in as peleh without logging off your current session.

The invitation sign for users is $, and for the root superuser it is #.

Usually the team su used for temporary superuser login to perform administrative work.

sudo command

sudo allows users to execute commands as root or other users. The rules that sudo uses to decide whether to grant access are in the file /etc/sudoers.

whoami team

whoami— display the name of the user who is authorized in the system

fsck command

fsck is a UNIX command that checks and fixes errors in the file system. After running the command, you must confirm (y) or not confirm (n) the correction of a particular error. To automatically check and correct errors, you need to run the command with the ‘-y’ switch: fsck -y

uptime command

uptime shows the current time, uptime after boot, number of current users and load for the last 1, 5 and 15 minutes.

who command

who— show a list of users in the system

w command

w- show information about the users currently working on the server and their processes, as well as the average server load for the last 1, 5 and 15 minutes ( uptime + who).

df command

df(an abbreviation for disk free) - show a list of all file systems by device name, reporting their size, used and free space, and mount points. Convenient to use with the -h switch (the size is displayed in Gb):

du command

du— show the size of an individual file:

ifconfig command

ifconfig— show network settings (interfaces):

ping command

ping- a utility for checking connections in TCP/IP-based networks:

traceroute command

traceroute— determine the data route in TCP/IP networks:

mtr command

mtr ya.ru - show the route of data on the Internet and the percentage of losses, constantly updating the data:

whois command

whois— show information about the domain (data about the registrar, domain renewal period, name server...):

ps command

ps– display your currently active processes

top command

top– show all running processes

kill command

kill pid – kill the process with id pid

killall command

killall ispmgr – kill all processes named ispmgr

man command

man passwd — display help about the passwd command

passwd command

passwd testuser — change the password for the testuser user. By default, the passwd command without specifying a specific user will change the password for the user who is authorized in the system.

ls command

ls– list of files and directories (with the switch “-la” - list with hidden files):

pwd command - current directory

pwd- display the full path from the root directory to the current working directory (shows the directory you are in):

mkdir command

mkdir folder – create a directory/directory folder

rmdir command

rmdir- remove a directory from the file system. Removing a directory and its contents can also be done with the rm -rf command (the -r switch for directories).

rm command

rm file - delete file file with confirmation

rm file * — delete all files that begin with the characters file with confirmation:

Team mv

mv(from the English move) - used to move or rename files or directories:

1 - renaming the directory folder to folder00:

2 - moving the file to the directory:

cat command

cat> file – direct standard input to file (that is, create a file with the necessary content):

To complete entering information into this file, you must press the keyboard shortcut as usual .

cat file — show the contents of the file file:

cat file file1 > file22 — create file file22 and write data from files file and file1 to it:

Less, more command

You can also view the contents of a file with the command less or more.

chmod command

chmod— change the access rights to a file or directory (751(-rwxr-xr-x) is often used for directories, and 644(-rw-rw-r—) for files), where

4 – reading (r)
2 – record (w)
1 – version (x):

Team chown

chown- change the owner of the file

tar command

tar file.tar file - archive the file file and name it file.tar:

where the option -c (create) - create. Team tar-xpf folder00.tar will unzip the archive into the current directory while maintaining file permissions.

wget command

wget— copy a file to the server over the network:

find command

find— file search:

locate command

locate— file search:

history command

history— show command history (you can specify the number of lines to view):

reboot command

reboot- reboot the server

halt command

halt- shut down the server

shutdown command

shutdown— turn off or restart the server (depending on options)

To work in Ubuntu, the user can choose one of two possible interface options: graphical or command line interface. GUI(GUI - Graphical user interface) is familiar to most users, in which you need to use various desktop elements to perform actions. It has its advantages, which are expressed mainly in the convenient and familiar format for presenting information, as well as in the absence of the need to know any commands.

However, many Linux users prefer to work in command line(CLI, Command Line Interface). Typically, these users will be involved in some way with programming or system administration, however, knowledge of the basics of bash will be useful for all users. The command line allows you to execute commands much faster than using the GUI, while saving resources. Moreover, commands often have no analogues in the graphical interface and, thanks to this, give users significant freedom in their actions. At the same time, the command line interface is built into the operating system kernel, which means it is available even when you cannot use the graphical shell. The commands themselves are the same for all Linux-based operating systems, be it Ubuntu, CentOs, Fedora or any other.

What is bash

Bash stands for Bourne again shell, a name partly borrowed from an earlier version of the UNIX shell, which was simply called the Bourne shell (after the name of its developer, Stephen Bourne).

Bash allows you to interact interactively with your computer by entering specific commands and receiving the appropriate response. This command processor also allows you to execute scripts (commands from a file), can autocomplete file and directory names, and allows the use of variables, branching and looping operators.
Further in the article we will present the simplest and most necessary commands for working in bash, which will help you get your bearings and start using the command line for your tasks yourself, but first you need to go to the command line interface.

Login to the command line

Using Ubuntu as your operating system, you can access the command line in two ways, namely through the console or through the terminal.
If you want to enter the command line through the terminal, then to do this you need to press Ctrl+Alt+F(1-6) - depending on the selected number (F1, F2...) you will be taken to the first, second or other virtual console ( they are independent and run when Ubuntu boots), each of which has a command line interface. If you press Ctrl+Alt+F7, you will go to the seventh virtual console, which has a graphical interface.

As for the terminal, it is a graphical program that emulates a console. You can find it in the menu by selecting Applications, then Accessories, and then Terminal, or by pressing the keyboard shortcut Ctrl+Alt+T. You will be able to execute commands while still being in the GUI.
It is also possible that you need to connect to a server on which Ubuntu is installed. In this case, you need to use a special program (for example, puTTy): enter the desired IP address, and then enter the username and password.

Note.
When you enter your password into the command line, it is not displayed - you just need to type the password and press Enter. If the password is entered correctly, you will be able to continue working at the command prompt.

User and system

Using bash, you can easily get any technical information you need about users and the system.
If you want to identify which user is currently logged in, you need to enter the following command into the command line:

If you need to find out not only about yours, but also about other users currently on this operating system, use the commands:

Unlike whoami, these commands show more detailed information: in addition to the username, you will also find out what terminal line is being used, the start time of the session, the IP address and some other data.

As for system data, you can view it using the uname command. By itself, this command will not give you much information - only the name of the system. However, if you use the keys, you can learn much more.

Keys- these are special arguments that are written separated by a space after the command and begin with one or two hyphens. They define the parameters that will be applied to the command. Typically, you can find out about available keys by writing a command followed by --help (or -help): for example,

For the uname command, you can specify the -a (or --all) switch, and then all information about the operating system will be displayed on the screen:

If you are interested specifically in kernel data, then type the following command:

In this case, you will learn about the release and version of the operating system kernel.
You can get information about all processes using this command:

And the pstree command will display information in the form of a process tree.

You can find out the network name of a machine using the hostname command.

Navigating directories

This section will introduce you to the basic bash commands, which will allow you to perform very basic command line actions.
The cd command allows you to move from one directory to another. Moreover, if you use a command without switches, you will end up in your home directory; in order to go to a specific directory, you just need to write down its path, for example:

Cd /home/users/dir1

You can also specify the cd command with specific options:

cd ../.. - move up two directories;

cd - - go to the previous directory (in which you were before moving to the current one).

The pwd command will indicate the path of the directory in which you are currently located.

Create, move and delete

Use the mkdir command to create a directory. Don't forget to include a name:

A new directory will be created in the directory where you are currently located, but you can also enter some other path to create a new directory:

Mkdir /home/users/dir1

To create a file, you need to enter the touch command and the name of the future file:

In this case, it is also possible to specify the path where you need to create the file:

Touch /home/users/dir1/file1

To move directories and files, use the mv command, after which you write the name of the directory or file you want to move, and then the location where you want to move it:

Mv file2 /home/users/dir2 mv dir1 /home/users/dir3

Note that the mv command is also used for renaming, so if there is no dir2 directory, you would write a command like this:

then the dir1 directory will be renamed to the dir2 directory. This example also applies to files that you can give different names using the mv command.

To delete files you should use the rm command, and to delete directories rmdir. If you want to remove a directory, use the rm command with the -rf switches:

Rm -rf /home/users/

Another action you can use is copy using the cp command. The syntax for this command is the same as the previous ones - you simply write what you want to copy and where. To copy a directory, you must use the -r switch, and if the final directory (dir2) does not exist, it will be created during copying:

Cp -r dir1 dir2

Information about files, directories and processes

To display information about the contents of a directory, use the ls command. If you use it without keys, it will simply display information about the files and directories in a given (or specified) directory. The main switches that are often used with this command are:

A - you will be shown all the files in the directory, including those that start with. (dots);

S - request information about the sizes of files (or directories);

L - data about files, in particular the name of the user who created them, access rights and creation time;

H - conversion of file sizes into an easy-to-read format (KB, MB, etc.).

Keys can also be combined, so the usual command to display the size of the content is:

Another command that will help you get the information you need is the du command. For example, by entering this command:

you will receive information about file sizes and names.

You can get information about running processes using the df command. It is best to use it immediately with the -h switch so that the data is shown in a more readable format:

Finding and Using Regular Expressions

To search for files in bash, use the find command. Its syntax is as follows: find + desired directory (path) + key (or several) + key criteria + (optional) subsequent action on the found files.

You can familiarize yourself with many of the keys of this command, which greatly facilitate and narrow the search, by entering into the command line:

For example, the following command will allow you to find all files that are located in the dir1 directory and are named file:

Find /home/users/dir1 -name ‘file*’

For searching, it is most convenient to use some regular expressions, namely:

* - denotes any number of characters, including their absence (for example, the request file* will find all files: file, file1, file829, fileabc, etc.);

Indicates one character (the request file? will find files with one character after the word file: file1, file9, filea, etc.; the request file?? will find files with two characters: file12, file34, file92, etc. .);

Denotes a subset of values ​​that one character can take (the request file will find the following files: file1, file2, file3 and so on up to file9; the request file will find files filea, fileb, filec and filed).

Redirection and pipeline

Redirection of the output of a command is specified by the symbol > or >>. The difference is that when using > the output of the command will be written over the contents of the file, and when using >> the output will be appended to the end of the file.

This is very convenient to use for logging if you want to write some data to a file. For example, this command will write all files found according to the specified parameters to a log file (it will automatically appear in the directory in which you are working):

Find /home/users -name ‘file*’ >> log

As for the pipeline, this tool allows you to use the output of one command as the input of another command. To do this you need to use the | symbol:

Find /home/users -name ‘file*’ | sort -r

If you enter this line, it will first find all the files that match the condition, and then with the sort command they will be sorted in reverse order (due to the use of the -r switch).

File Contents

If you want to see the contents of a file, you can use the cat command - in response to the command you will see everything that is contained in the file. If there is too much data, use the pipeline and the more command - it will allow you to view the content page by page:

Cat file1 | more

If you need to not only view the contents of a file, but also edit it, then you need to use one of the utilities: nano or vim. These are text editors with which you can open a file, edit it, and save it. Despite the apparent similarity, these utilities have a number of differences; Most users agree that nano is a simpler editor, while vim has more capabilities.

You can find the Russian documentation for nano at this link: http://help.ubuntu.ru/wiki/nano

And vim documentation is available in this section: http://help.ubuntu.ru/wiki/vim

Conclusion

There are many different commands and switches that can be used in bash. In this article, we focused only on the most basic, basic commands with which you can perform operations and obtain the necessary information.

Full Russian-language documentation can be found at this address: