Linux Shell Basics

& nbsp & nbsp Command line, shell, console - these terms are used to refer to human operator interaction with operating system using standard I / O devices that provide input teams and getting the results of their execution. In operating systems of the Linux family, such interaction is provided by a special software product - shell... The most common of these is the shell for the GNU project bash (B ourne A gain SH ell). Bash shell based Bourne (sh) created by Stephen Born and includes the properties of many other shells - C (csh) , Korn (ksh), tc (tcsh). Bash was written by Brian Fox and is currently maintained by Chet Ramey.

& nbsp & nbsp Bash shell properties make it the most versatile and convenient way to interact with Linux OS:

- Bash provides command line editing. The cursor can be moved to any position of the command to change its content.

- Bash Supports command history mode, allowing you to display and modify previously entered commands. Shell bash also has several variables, the values ​​of which affect the saving and re-invocation of previously entered commands.

- Bash provides partial word completion for variable names, users, hosts, commands, and files.

- Bash Provides flexible control of processes, allowing them to suspend, restart, switch between foreground and background tasks, and even continue execution of a task when the parent process exits.

- Bash allows you to use functions and aliases, perform arithmetic operations, and enter arithmetic expressions as commands.

- Bash allows you to create entire sets of sequentially executed commands (scripts or scripts) using the flexible and functional programming language of this shell.

- Bash has flexible settings that allow changing appearance command line.

Shell bash can be performed in both interactive and non-interactive modes. In the first case, the program bash interacts with the user, in the second, it is used to execute scripts (specially prepared text files with a sequence of commands).

& nbsp & nbsp A Linux Shell Command is a character string of command name and arguments, separated by spaces. Arguments provide the command with additional parameters that determine its behavior. For example, the command
echo 12345
will display the string of characters 12345 entered as an argument to the command.

The commands that are part of the shell are called embedded... Naturally, they can be different for different skins. In addition, the names of the executable files are used as commands. As arguments, commands are passed the keys or options consisting of a dash and one or more characters. An example of such a command:

Ls -l

ls is a command to display information about files. If entered without arguments, this command will simply display a list of files in the current directory. When entered with the parameter -l- list in long format - displaying attributes, owners, date and time.

When using multiple keys, they can be combined. The command options below are identical:

How to get a hint on using a Linux command

When working in the Linux command shell, in most cases, you can get help information on using a specific command by entering its name with the parameter --help:

Ls --help - display help for a command ls... In most cases, to obtain reference information, it is allowed to use the key -h

Ls -h On Linux operating systems, more detailed help information can be obtained from the documentation set known as man pages as it is accessible by the command man... This kit contains 8 sections of help information that can be displayed using the command man

List of Sections man pages:

1 - User level commands.

2 - System calls. Documentation about library system calls like open, read, exec etc. This section is usually used by programmers.

3 - Libraries. This section is also intended for programmers and contains reference information about the libraries application programs (abs, rint etc.)

4 and 5- Formats of system and user files. Contains documentation on various file formats such as file passwd

6 - Games. Descriptions of the games supplied with the installed system.

7 - Drivers. Driver documentation such as ip or ipv6

8 - System support. System administration command documentation ( init, fdisk, ifconfig etc.).

Examples:

Man 1 ls - display help for a command ls from the first section of the documentation (it contains information about user-level commands).

In practice, if information about a command is required, the section number is omitted. In this case, the search will be performed in all sections, starting from the first one up to the match with the argument specified in the command man:

Man ls - display help for a command ls from the first section of the documentation where it will be found.

Sometimes the lack of a section number in a command man even preferable. For example, help for the command

Man 1 init - display help for a command init from the first section of the documentation, will end with a message about the absence of reference information, because this command belongs to the system support commands and information about it is contained in the 8th section.

To search for help documentation in all sections, use the option -a:

Man -a passwd - display help for an argument passwd from all sections where it will be found: As a result, help will be displayed on the passwd command from the first section and description of the format passwd password file from the fifth.

As an argument for the search string in the command man the template can be used:

Man -a ip * - display help for all options starting with ip from all sections of the help documentation.

When viewing the help documentation displayed by the command man the keys are used:

up / down arrow- move one line up / down.

PgUp / PgDown- go to page up / down.

Enter- move one line down.

Space- go to page down

Q- exit from help.

Also, a convenient tool for finding help information is the utilities apropos and whatis allowing you to search by keyword in the documentation database. The first one displays those lines that contain the search string in the manual page names and short descriptions, and the second one displays the one-line descriptions of the manual pages that appear at the beginning of each page. With default parameters, the commands will return different information. For example, whatis tar will give you information related to the archiving utility tar, and the apropos tar command will give information about the utility tar, and in addition, reference data, where the string “tar” is part of a word, for example “s tar t ”. Using the utility apropos at first glance it seems not very effective, however, it is not. For example, the apropos net command will give you a quick quick reference on network utilities present in this system. In these commands, you can use the parameter -s indicating the number of the help system section in which to search:

apropos –s 1 net - Search only the first section of the man page.

When searching, both utilities use index databases that are updated with the program mandb(or traditional text database, the program being created makewhatis), so the search is very fast. Extra options command line used apropos and whatis can be obtained using the command man .

& nbsp & nbsp Work in command line Linux has some fundamental differences compared to working in a Windows environment.

& nbsp & nbsp First, remember that uppercase and lowercase letters are different characters for Linux. In the operating room Windows system catalog TEMP and catalog Temp is the same directory, in Linux they are two different. The same goes for commands, their keys, usernames, passwords, etc.

& nbsp & nbsp Second, help on command with parameter --help and the help from the man page are different. The latter is usually more detailed, with examples and links to related sections of the documentation.

Thirdly, the available list of commands and the result of their execution depends on your rights in the system. As a rule, commands that are potentially dangerous to the integrity of the system, and commands that affect the work of other users are not available ordinary user. Full rights in relation to the system has only one user (superuser) - root... Usually, the account given user is used only to change system settings, and in most Linux distributions, after installing the system, there is no way to work under root‘In a graphical environment, in remote sessions, or even when logging in locally, as is done in Ubuntu. This approach allows you to prevent the destruction of the system due to user error, and is quite justified, however, there are cases when no rights root not enough. To obtain user rights root(superuser, superuser), to whom all possible commands are available, use the command su... It allows you to change the current user. If the user is not specified, then it is assumed root..

To execute a single command as the superuser root or another user, use the command sudo:

sudo ifconfig - execute command ifconfig as superuser root

sudo su - Combination sudo and su- execute the command su as the superuser root. This version of the command allows the user to go to the account root without saving the current user environment ("-" sign).

Usually, using the command sudo preferred over using su and, with additional system settings, it makes it easy to give individual users only strictly necessary privileges. The main part of the settings sudo stored in file / etc / sudoers and sets the rules that determine which users, which computers, which commands can be executed with or without entering a password. The system administrator can even transfer superuser privileges for a while. root any user without giving him the password from account root.

& nbsp & nbsp Beginners Linux users it is usually intimidating to work in a command shell due to the need to type too long lines of commands, directory names or files. However, very often such a set is not necessary. When working in a command shell environment, it is very convenient to use the name substitution mode using the key Tab... For example, to get a list of files in the / home / everyone directory, the user needs to type the command

ls / home / everyone

However, the shell does away with the complete set of paths. If after dialing ls / h press the key Tab, then the missing part of the directory name will be substituted on the command line - ome, and the input line displays

ls / home /

Similarly, you do not need to complete the rest of the path, but only e and Tab... If there are overlapping file or directory names, only the common part of the name is substituted. If the directory / home there are subdirectories everyone1 and everyone2 then after pressing the key Tab the substitution of the common part will be performed everyone and the screen will display a list of possible input options - everyone1 and everyone2... It remains only to enter the missing part of the name (1 or 2). The same technique is used when typing commands. For example, if you type the character e and press Tab then a list of all available commands starting with a letter will be displayed e if you then type the character c and press again Tab, then the name substitution will be exposed up to echo, or if there are other options - substitution of the common part and possible options name.

How to control the output to the screen.

& nbsp To view text that has gone beyond the visibility of the screen, use key combinations SHIFT and PAGE UP or PAGE DOWN(depending on the direction of viewing).
To pause displaying - CTRL-S, cancel suspension - CTRL-Q

& nbsp To display a large amount of text on the screen in page mode, use the less command, chained with the main command. Let me explain with an example. Let us have text file mytxt is 10 screens in size. To display text on the screen (standard output), you can use the command cat filename
cat mytxt

After executing this command, you will see a quick flashing text and the last (tenth) output screen. You can, of course, use the keyboard shortcuts SHIFT-PAGEDOUN or SHIFT-PAGEUP to view the text, but you can also use the less command.
cat mytxt | less
Symbol | means chaining the command to print the text cat and the command to control the paging of less. As a result, after the first page of text is displayed on the screen, the output will be paused until you click
PAGE DOWN
or ENTER(line-by-line movement). Press the key to end paging. Q.
& nbsp Multiple commands can be chained together. For example, you need to display in page mode all lines containing the word mail... To search, you can use the command
grep
The final chain of three teams:
cat mytxt | grep mail | less

& nbsp For most Linux distributions, you can use more instead of less.

Sometimes it is convenient to use several terminals at the same time, switching between them (for example, when it is necessary to view log information in one window and manage processes and settings in another).

To switch, use the key combination CTRL - ALT - F1 ... F6(from the first terminal to the 6th or further). To switch to the graphical shell, one of the combinations is used, which may differ for different distributions. For instance, CTRL-ALT-F7.

To start another graphics server on the same computer, use the startx 1 -: 1 command. You will have a new graphical terminal added. To go to the second graphical terminal, press Alt + F8., and to return to the first one - Alt + F7... This way you can open up to 64 graphic terminals. (startx 2 -: 2, etc.).

To end a shell session, use the exit command.

& nbsp & nbsp You can create a log of your console session, which will display everything that you entered from the keyboard, and everything that was displayed on the terminal screen.
To do this, use the command

script log file name

For instance:

script /home/user/mysession.log

To stop logging, enter the exit command.

Use the Up / Down arrows to view the history of previously entered commands. When entering a command typed or called from the history, the position of the cursor relative to the input line does not matter.

In addition, in the user's home directory, there is a command history file for the given shell, for example .bash_history... To display its contents on the screen, you can use the command history.

To view information in the back end of the files (for example, logs), use the command tail:

tail / var / log / mrssages - display the last 10 lines (default) from the log file / var / log / messages.

tail –n 100 / var / log / mrssages - display the last 100 lines from the log file / var / log / messages.


How to restart or shut down your computer.

& nbsp The same action in Linux can often be done in several ways. Shutdown is typically used to restart or shut down the computer. The command has many options, allowing you to reboot at a specific time, quick reboot without checking file system, simulate and cancel an already running (waiting for its time) reboot process.

Full list options can be obtained by shutdown --help

For an immediate restart (restart), the command will look like this:
shutdown -r now
& nbsp To turn off the power (halt):
shutdown -h now

Most distributions can use short commands:
- shutdown

You can also use the init command to change the runlevel of the system, which allows you to control the starting and ending of processes on the system using scripts stored in / etc / inittab. Level 0 - shutdown, level 6 - reboot. Respectively
to turn off:
init 0

To reboot:
init 6

The init command can be used to change the runlevels of the system.
Levels:
1 - Single user mode. Access is granted to the root user.
2 - Multiplayer mode without support for network functions.
3 - With network support.
4 - Reserved.
5 - Using the graphical shell.

& nbsp & nbsp If you need to terminate the graphical shell (for example, when the installation of some applications requires it to be closed) enter:

init 3

& nbsp & nbsp The GUI will close and the system will go to runlevel 3. To return to runlevel 5, enter:

init 5

& nbsp & nbsp The default system startup level is determined by the initdefault value from the / etc / inittab file. To start a system with graphical shell support, it looks like this:

Id: 5: initdefault:

If 5 is replaced by 3, then the graphical shell will not start at system startup.

All of the above applies to init systems SysV(SystemV), which has been used for many years in all Linux distributions to boot a working environment using scripts init... However, starting in 2012, there has been a gradual transition to systemd a new init system originally developed for the Fedora distribution starting with Fedora 148. Simply put, systemd is a daemon for initializing other daemons in Linux, replacing the previously used init script (/ sbin / init). Its main feature is the parallelization of the launch of services during the system boot process, which significantly accelerates the launch of the operating system. Implementation systemd significantly differs not only in logic, but also in the principles of managing the startup process, a set of program modules and configuration files. File / etc / initd no longer, and to determine the trigger level in systemd symbolic links are used, for example:

For init state 3
ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

For init state 5
ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target

Commands init N on distributions using systemd so far supported, but it is clear that her time is running out.


Process control in Linux.

& nbsp & nbsp You can view the list of processes in Linux using the command ps... If you run it without any parameters, then it displays a list of processes running in the current user session. A complete list of options can be obtained as standard - by running

Ps --help

Examples of using:

  • List of all processes running on the system:
    ps -e - will list processes with identifiers (PIDs) and their names
    or:
    ps -eF - will give the same list of processes, but with a complete startup line
  • list of tasks generated by user:
    ps -U user
  • list of tasks related to the current terminal:
    ps -T
  • list of tasks related to terminal N:
    ps t ttyN
  • If the list of tasks is large, and we are interested in the status of one or more tasks, you can use grep:
    ps -U root | grep ppp - print out a list of tasks containing "ppp" in the name

    & nbsp & nbsp You can use the top command to get information about your computer's resource usage

    In the upper part of the window, summary data about the state of the system is displayed - the current time, the time since the system was booted, the number of users in the system, the number of processes in different states, data on the use of the processor and memory.

    Below is a table that characterizes individual processes. The number of rows displayed in this table is determined by the size of the window. The content of the window is refreshed every 3 seconds. Pressing the h key displays help for the commands that allow you to change the format of the displayed data and control some parameters of the processes in the system:

  • s or d- change the window refresh interval.
  • z- color / black and white display
  • n or # - the number of displayed processes
  • You can sort the list of processes by CPU usage ( P), memory (M), runtime (T) etc.

    & nbsp & nbsp In utility environment top there are also subcommands that allow you to manage processes interactively:

  • k- kill (kill) the task. This command will ask for a process identifier (PID), after entering which, the process will be terminated.
  • r- change the current priority of the task (renice). As with the previous command, the PID will be requested, and then the new priority value (displayed in the NI column). Priority values ​​range from minus 20 (highest) to plus 19. Negative values ​​and 0 can only be set by the root user.
    & nbsp & nbsp To exit top press q


    Kill command

    & nbsp & nbsp The same actions (forcibly terminating the process and changing its priority) can be performed without the top command.

    & nbsp & nbsp Processes in Linux have the ability to exchange so-called "signals" with the kernel and other processes. When a process receives a signal, control is transferred to its processing subroutine or the kernel, if such a subroutine does not exist. Linux has a kill command that lets you send any signal to a given process. The list of signals can be obtained by the command:
    kill -l
    As a result of executing this command, you will see a list of signal numbers and names. In order to send a specific signal to the selected process, you need to enter:
    kill PID number of the selected process
    For example, we need to shutdown the Midnight Commander (mc) application.

  • Let's define the process id mc:
    ps -e | grep mc
    Let PID = 11597.
  • We send the SIGQUIT signal (number 3):
    kill -3 11597
    The mc process will then process the GIGQUIT signal and exit. However, if mc "hangs", then, of course, it will not be able to complete, since the signal handling routine SIGQUIT will not receive control. In such cases, signal 9 (SIGKILL) is used, processed by the operating system kernel, and forcibly terminating the specified process:
    kill -9 11597

    If the signal number is not specified in the kill command, then the SIGKILL value is used, i.e. the previous command could be entered as kill PID:
    kill 11597

    & nbsp & nbsp When a process terminates, the processes it spawns are also terminated.

    & nbsp & nbsp To terminate a process by its name, use the killall command:
    killall mc - kill a process with "mc" in its name
    killall -u user - kill processes spawned by user


    Changing Priorities - Nice and Renice Commands

    & nbsp & nbsp The nice and renice commands are used to change the priority of processes. When a process is started, its priority is set by the value of the parent process, for example, the xterm terminal or the shell. The nice command allows you to start a process with a priority equal to the sum of the parent (for example, 8) and the number specified as an option to the nice command:
    nice - command
    nice -4 mc - will start mc with priority = 8 + 4 = 12

    The renice command is used to change the priority of an already running process:
    renice -p PID
    renice 4 -p 11597 - set the priority value for the mc process (PID = 11597) to 4.
    Upon execution, renice will produce the result string:
    11597: old priority 12, new priority 4- old priority 12, new priority 4
    Setting zero and negative priority numbers is possible only with root privileges.

    A list of the most commonly used commands:

    Commands for working with files and directories:

    pwd- display the path of the current directory
    cd- go to the specified directory
    ls- display a list of directory files, with the -l switch shows additional information about files.
    cp- copy files / folders
    mv- moving files / folders
    mkdir- create a folder
    rm- delete files / folders, with the -r switch removes all subfolders, with the -f switch - deletes open files or directories
    rmdir- deleting an empty folder
    chmod- change file permissions
    chown- change the owner of a file or directory
    find- find the file. The source path for the search and the search pattern are set, find / -name .X *- search from the root directory for files containing characters in the name .X
    which- display the full path of the executable file available in the given shell, for example which ifconfig
    touch- change the time stamps of the file. Convenient to use for creating empty files - touch myfile will create empty file myfile.

    System Commands

    These commands are usually used as superuser (with the sudo command).

    - computer shutdown
    reset- clears the terminal window
    passwd- change your password, and the superuser - change the password of any user
    users- display a list of users logged in to the system.
    yum- installing, removing or updating software in Fedora, RedHat, etc. distributions.
    dpkg- installing, removing or updating software in distributions Debian, Ubuntu, etc.
    apt-get- installing, removing or updating software in Debian based distributions (Ubuntu, Mint, etc.)

    Process management

    ps- display a list of currently active processes
    lsof- display the list open files process or user
    strace- display a list of system calls
    last- display the history of reboots and user registrations in the system
    kill- send a signal to a process, usually used to force a process to terminate.
    killall- termination of all processes, the names of which are specified by the command line parameter
    top- displaying a list of current processes and interactive management of them.

    Network Commands

    ifconfig- configuration of network interfaces
    route- routing table
    ifup / ifdown- enable / disable network interface
    ip- view or change the configuration parameters of the IP protocol
    netstat- display the status of network connections
    arp, ping, nslookup, traceroute are the most commonly used commands for network diagnostics.

    All Linux newbies have probably already heard about the terminal, or as it is also called the command line. After all, the presence and complexity of the terminal is one of the main arguments of the opponents of Linux. You may have already come across the command line in Windows in practice and already know what it is.

    Indeed, in the operating room Linux system there is a terminal where you can execute the commands you need to manage your system very efficiently. But this is not at all necessary, the graphical interface is enough for many. Now the use of the terminal has faded into the background, but it remains the main tool for accessing remote servers and a tool for professionals.

    Linux terminal is much more interesting than command terminal Windows string and this article will take a closer look at working in the Linux terminal for beginners, as well as what a Linux terminal is and what it actually is.

    The use of the terminal began a long time ago. Even before DOS was created and there was no graphical interface. In the distant eighties, the operating Unix system just beginning to develop. Users need to interact with the system in some way and the easiest way is to use commands. You enter the command, the system returns the answer to you.

    Since then, this type of input has been used in many systems, including DOS and OS / 2 from Apple, until it was invented graphical interface... The terminal's text mode was then successfully preempted, but it still continues to be used where needed.

    Above, under the terminal, we understood the place where you can enter commands and receive a response from the computer. This can be Linux text mode or a terminal window open in graphical mode. In Linux, words are often found: console, terminal, command line, command shell, tty, terminal emulator. They all refer to the terminal, but mean slightly different things. Before moving on, let's understand the terms so that we can call everything by its proper name.

    Under terminal it is customary to understand the environment where you can enter commands and receive a response to them, it can be a physical terminal or a terminal on a computer.

    Console is the physical hardware used to manage the server. When the server cannot be accessed from the network, only the console can be used to manage it.

    TTY is a device file that is created by the kernel and provides terminal access for programs. These files can be / dev / tty for permanent text terminals and / dev / pts / * for terminal emulators. You can execute a command or send a message simply by writing data to this file, and also get the result by reading data from this file.

    Terminal emulator is a graphical program that gives you access to a tty or pts terminal. For example, Gnome Terminal, Konsole, Terminix, Xterm and many more.

    Command shell- the tty device is only engaged in transmitting and receiving data, but all this data must still be processed by someone else, execute commands, interpret their syntax. There are a lot of command shells, these are bash, sh, zsh, ksh and others, but most often Bash is used.

    Well command line- this is where you will enter your commands, the terminal prompt for input.

    Now that we have figured out what a Linux terminal is and know all the basic principles, let's move on to the practice of working with it.

    How do I open a Linux terminal?

    There are several ways to access the terminal. Your init system creates 12 virtual terminals by default. One of them - usually the seventh - starts your graphical shell, but all the others are free to use. To switch between terminals, you can use the shortcuts Ctrl + Alt + F1-F12. For authorization, you will need to enter your username and password.

    These are text terminals without a graphical interface, it may not be very convenient to work in them, but, on the other hand, such terminals will be useful if the graphical interface does not work.

    The second method allows you to open a virtual terminal directly in the GUI using a terminal emulator. The linux terminal emulator works with files in the / dev / pts / * directory and is also called a pseudo terminal because it does not use tty.

    On Ubuntu, you can launch the linux terminal by pressing the keyboard shortcut Ctrl + Alt + T:

    It can also be found in the Dash Apps menu:

    As you can see, it is very easy to open the command line in linux.

    Executing Commands in Terminal

    Let's take a closer look at the Linux terminal for beginners. As I said, the terminal and tty device files are only responsible for transferring data. The command shell is responsible for processing commands, and the data received from the user is transferred to it.

    You can type anything and see if it works:

    To execute a command, just write it and press Enter.

    Moreover, the Bash shell supports auto-completion, so you can write half a command, press TAB and if only one command begins on such characters, then it will be automatically completed, if not, then you can press TAB twice to see the possible options ...

    The exact same scheme works for file paths and command parameters:

    On Windows, you could not have dreamed of this. To execute a command, you can specify the name of its executable file or, relative to the root or any other folder. It is important to note that the Linux command shell, unlike Windows, is case sensitive, and therefore, be careful when entering commands and their parameters.

    By default, work in the linux command line can be performed using a large number of commands, many of them, for example, for moving through directories, viewing contents, installing software, are supplied with the system.

    An instance of a running command is called a process. When one command is executed in the Linux terminal, we need to wait for it to complete in order to execute the next one.

    Commands can be executed without parameters, as we saw above, or with parameters that allow you to specify the data with which the program will work, there are also options with which you can customize the behavior. Most of the standard utilities follow this syntax:

    $ command options parameter1 parameter2 ...

    Options are often optional and specify one or another aspect of the program's operation. They are written in the form of a dash and a symbol or a double dash and a word. For example -o or --output. Let's give an example for the ls command. Without options and parameters:

    With a parameter indicating which folder to look at:

    With the -l option, output as a list:

    B with option and parameter:

    Two options can be combined:

    Basically, this is everything you need to know about commands in order to use them productively. You could also talk about combining commands and redirecting the output of one command to another, but this is a separate topic.

    conclusions

    This article has covered working in the linux terminal for beginners. Command linux string It may seem very complicated at first, but it is not at all, it is much easier to use than in Windows and allows you to manage the system more efficiently. Hopefully this article has shed some light on this very big topic.

    about the author

    Founder and administrator of the site site, I am fond of open software and the Linux operating system. I am currently using Ubuntu as my main OS. In addition to Linux, I am interested in everything related to information technology and modern science.

    Any Linux user just needs to master the basic skills of working in the terminal. Below are 15 commands \ hacks for comfortable work with a console. Whether you are a beginner or a pro, I am sure you will find some useful tips and tricks below.

    1. man

    Let's start simple, the man command, which stands for manual. If you want to read about a command, just type:

    Man

    man is not a little-known command, you can find it in any Unix textbook, but I would like to draw your attention to some of its peculiarities.

    Man ascii

    Ever confused which is less pico or femto? Try the following:

    Man units

    There are many more similar funny teams. There is something to have fun with. (try xkill). Until then, let's move on.

    2. cd -

    If you accidentally change the directory, you can simply return to the last one by typing:

    cd -

    3. sudo !!

    This comic highlights the importance of the sudo command in Unix. sudo runs the command as an administrator. If you typed a command without sudo, and then it turned out that you need it, just type:

    and it will start with root rights.

    4. mtr

    mtr is a powerful tool for network diagnostics. It combines the functionality of traceroute and ping.

    Mtr

    5.command

    Experienced users may know that the history of running commands is stored in the ~ / .bash_history file.
    So that the command is not recorded in history, just type a space before the command. This can be useful when working with admin rights - or just if you want no one to see the history of your actions.

    6. jot

    jot generates text. Numbers, text, all together. To generate numbers, try this:

    Jot [number of numbers] [starting from]

    If you write one argument, numbers from 1 to the value of the argument will be generated.

    To get random:

    Jot -r [number of numbers] [lower limit] [upper limit]

    Read more or type man jot

    7. df

    Quite a simple command. Shows free disk space ( disk free)

    8. pkill

    pkill(or process kill) terminates running process... This command is especially useful when the application is not responding:

    Pkill

    The command can be hilarious / brutal if you run it on a remote machine. Be careful, you may lose important data. after completing the application with the data working.

    9. ddate

    Discordian calendar

    10. cal

    Good old Gregorian calendar.

    11. tac

    You may have heard of the command cat... It has a number of utilities for creating, copying, merging and displaying text files. tac does the same, but in reverse order.

    12. w

    Team w shows who is on this moment logged in along with another useful information such as running time or processor load.

    13. factor

    factor factorizes a number:

    Factor

    14. yes

    Back to the fun teams yes prints the text multiple times:

    Yes

    Use it to confuse friends sneaking up behind you. Attention, the only way to stop it is CTRL + C (well, or close the terminal)

    15. nl

    nl numbers lines. Most useful when used as an argument. Let's take a look at a couple of examples:


    Thank you for your attention, all the best.

    2016-06-17T19: 56: 26 + 00: 00 admin Where to start? Manuals Command Referencesbash, Debian \ Ubuntu \ Mint, Administration, Commands, Console, Manuals, System Utilities, Command Reference, Hacks

    Any Linux user just needs to master the basic skills of working in the terminal. Below are 15 commands / hacks for comfortable work with the console. Whether you are a beginner or a pro, I am sure you will find some useful tips and tricks below. 1. man Let's start simple, the command man, which stands for manual. If you want to read ...

    [email protected] Administrator Tutorial LINUX

    Linux console commands, or as they say the command line, is a kind of intermediate link between the user and the computer itself. In order for the machine to carry out your order, it must be given the appropriate command. Initially, this is exactly how the relationship between a person and a computer took place, but a little later, appeared additional tool mouse, which greatly simplified the whole process of information exchange and made it more accessible to all users. Nevertheless, the console today remains a powerful and sometimes very convenient tool for performing all kinds of actions.


    In general, there are a great many console utilities, but here we will briefly, as an example, consider only two of them, but very important and often used. Utility Apt-get designed to work with software packages. For those who do not recognize the console at all, you can use the wonderful graphical shell for Apt-get, entitled Synaptic(available in the official repository).

    How do I use the utility?

    // basic formula

    sudo apt-get command

    // update all packages as an example

    sudo apt-get upgrade


    Basic apt-get commands for working with packages.

    apt-get update // update information about packages from repositories
    apt-get upgrade // update all packages
    apt-get dist-upgrade // update the system as a whole
    apt-get clean // cleans out local storage except for cache files
    apt-get autoclean // same as clean, with deleted. cache files
    apt-get check // refreshes the cache and checks. unsatisfactory dependencies
    apt-get autoremove // remove previously downloaded but unnecessary packages
    apt-get remove // remove package with save config. files
    apt-get purge // remove the package with all dependencies
    apt-get install // install the package
    apt-get build-dep // install everything to build source packages
    apt-get source // downloads the source packages


    Parameters:

    -h, --help //reference
    -q, --quiet // hide the progress bar
    -qq // show nothing but errors
    -d, --download-only // just get packets and exit
    -s, --simulate // simulate events
    -y, --yes // auto answer "Yes" to all questions
    --reinstall // reinstall packages
    -f, --fix-broken // fix broken dependencies
    -m, --ignore-missing // ignore missing packages
    -u, --show-upgraded // show updated packages
    --no-upgrade // do not update packages
    -b, --compile, --build // collect the package after receiving
    -D // on uninstall, remove dependent components
    -V // show package version numbers in detail
    --no-remove // if packages are marked. to deleted., then apt-get off
    --force-yes // forced execution of the specified operation


    Funny.

    apt-get moo

    Must see a cow that asks, "Did you bellow today?"

    The "aptitude" utility.

    Consider another very good utility entitled " aptitude", in fact it is the same as" apt-get", but it is considered better, and also has a pseudo-graphical interface. The principle of operation is exactly the same, only instead of" apt-get", you need to enter a value" aptitude". First, install the utility itself:

    sudo apt-get aptitude

    Now if you type: aptitude, you will be taken to the program interface.

    Let's look at some commands:

    // Install the package.

    sudo aptitude package1 package2 package3

    As you can see, you can install an unlimited number of packages at once. No matter how much you install them, aptitude will automatically resolve all dependencies, you just have to agree (y) and press (enter)... Also, by analogy, you can delete packages:

    sudo aptitude remove package_name1
    or
    sudo aptitude purge package_name1

    The first command removes only the package files without changing the settings, the second one removes everything completely. You can view the package description like this:

    aptitude show package_name

    In general, this utility is an absolute analogue " apt-get", but when installing and removing packages, it is advisable to use it rather than" apt-get". Anyway, on the official website Ubuntu give just such recommendations.

    Other console commands.

    List of commands related to information.

    hostname // network name of the machine
    whoami // name of the current user
    uname -m // show the architecture of the machine
    uname -r // kernel version
    sudo dmidecode -q // inform. about the device. system support
    cat / proc / cpuinfo // information about the processor
    cat / proc / interrupts // interrupts
    cat / proc / meminfo // all memory information
    cat / proc / swaps // all information about swap
    cat / proc / version // kernel version and other information
    cat / proc / net / dev // network interfaces and statistics
    cat / proc / mounts // mounted devices
    cat / proc / partitions // available sections
    cat / proc / modules // loaded kernel modules
    lspci -tv //PCI devices
    lsusb -tv //USB devices
    date //The current date
    cal // calendar and current month
    cal 2012 // will show the entire 201x year


    Commands related to the reboot and shutdown processes.

    shutdown -h now // turn off the system
    init 0 // turn off the system
    telinit 0 // turn off the system
    shutdown -h hours: minutes & // schedule system shutdown
    shutdown -c // cancel scheduled shutdown
    shutdown -r now // reboot the system
    reboot // reboot the system
    logout // end session


    File operations and more ...

    cd / home // go to home directory
    cd .. // go to a higher level
    cd ../ .. // go 2 levels higher
    cd - // go to the previous directory
    pwd // show the path to the current directory
    ls
    ls -F // show files and directories
    ls -l // show. details about files, directories
    ls -a // show hidden files
    mkdir dir1 // create a directory named dir1
    mkdir dir1 dir2 // create directories dir1 and dir2
    mkdir -p / tmp / dir1 / dir2 // create a directory at the specified location
    rm -f file1 // delete file named file1
    rmdir dir1 // delete directory named dir1
    rm -rf dir1 // remove the directory dir1 and all its contents
    rm -rf dir1 dir2 // remove directories dir1\dir2 and content
    mv dir1 new_dir // rename / move directory
    cp // copy files / folders
    ln -s // create a symbolic link
    chmod // assigning rights to files
    find / -user user1 // search for files, direct. Withuser1 find / home / user1 -name \ *. bin // search for files .bin v / home/ user1 find / usr / bin -type f -atime +100 // claim. bin. files, non-write. 100 days find / usr / bin -type f -mtime -10 // claim. files created / modified in 10 days find / -name \ *. deb -exec chmod 755 "()" \; // claim. files ( .deb) and cheating. rights locate \ *. ps // find files with extension.ps whereis halt // show the path to the programhalt which halt // show. full path to the program.halt


    At first glance, all this may look somewhat intimidating, but this is only at first glance. You should not immediately rush into panic and immediately return to Windows(y). Modern distributions Linux, a Ubuntu in particular, it allows you to do without the command line. Nevertheless, the command line, in some cases, is much more convenient than the graphical interface. Also, it is not at all necessary to memorize all these commands by heart, it will be enough to create a text file, copy all the contents into it and keep it nearby, like a cheat sheet, which you can use if necessary.

    Of course, this is far from all that concerns the topic of the command line and the commands themselves, if someone is really interested in this, then I can advise you to go to the next link, there you can find and download a lot, the only question is, is it necessary it's all for you. In general, I doubt that today there is at least one person in the whole world who would know all the existing console commands by heart (maybe I'm wrong).

    Terminal introduction

    Among all the elements of the system Linux the most important is perhaps the command line ( bash-B ourne A gain Sh ell) or Terminal:

    It seems to novice users that they will never resort to using the command line, and some are simply afraid of it. However, the more experience they gain, the more often they turn to the terminal.
    Using the command line, you can perform actions that would be inconceivable when working with a graphical user interface... It turns out that many actions are much faster and more efficient to perform using the command line.
    The command line is used in all OS: Windows, macOS X and Linux.
    Many novice users might argue: "Well, we don't use the command line on Windows." ... And there will be not right since all actions to install / uninstall programs or others systemic changes are invisibly flowing in the terminal, not to mention system administrators which very often use command line services.
    Initially, the terminal window was displayed in the first computer monitors, even before graphical programs (GUI) appeared and until in the foreseeable future it is not visible that it could be replaced by something else.

    Terminal Commands


    In system Linux thousands of commands are used, which are not at all necessary for an ordinary user to know, but it is simply necessary to have a general idea and know some of the frequently used ones, since willy-nilly, you will encounter them when setting up the system or installing the desired program absent in Application Center etc.
    I use systems Ubuntu / Linux Mint and examples will be used based on them, but I think that in addition to the command sudo, the rest applies to other systems Linux.

    Updating programs

    Many users, probably, have executed such commands more than once in the terminal:

    sudo apt-get update
    sudo apt-get upgrade

    Let's break them down in more detail to understand what they are.
    First of all, I would like to note that all commands are written in English language and not just "from the flashlight", but each has a certain meaning for its application. And the fact that the command line Linux very case sensitive. In other words, these commands are written in lowercase ( lowercase letters), but if you enter an identical command, but in uppercase ( capital letters), then it will not work. This must be remembered.

    Team sudo, it is essentially an abbreviation, consisting of the following words: s uper u ser do, which literally means the following in English: s uper u ser - superuser(administrator), do - does... Those. when the given command is present in common team, then the command line is given to understand that it can be executed superuser(administrator), the user who was registered during the system installation and entered his password:

    Team apt-get that follows sudo and a space, consists of two words separated by a hyphen, which combines these two words into one command and literally means in translation: inclined to do.

    Team update, in translation - update.

    so sudo apt-get update literally - superuser inclined-to-executeupdate.

    After entering this command and pressing the key Enter, the terminal asks for a password. After entering the password and pressing again Enter, the process of updating the package list will begin.

    Note. The terminal has quirks after entering the command with sudo, namely, when you enter a password, it is not displayed in letters or symbols, so you should always pay attention to the keyboard layout in which you enter the password and another, this is after the first command with the presence sudo, subsequent commands (even if they contain sudo), no longer requires you to enter a password for a certain time (keeps the sudo session open) in the same terminal window, that is, assuming that the terminal continues to use superuser(administrator).

    Team sudo apt-get upgrade very similar to the previous command, where upgrade - modernize, improve(system). This command is usually executed after the update command. After the command is executed, it issues in the terminal possible packages to install, i.e. modernization, improvement of the system. The user has to agree or not with the installation of these packages.

    Installing, removing programs

    sudo apt-get install chromium-browser

    sudo apt-get remove chromium-browser

    As you can see, the commands are very similar to each other, with the exception of one word highlighted in red. In the first team install - install chromium-browser and in the second remove - delete chromium-browser

    Thus, applications (programs) and other files in the system are installed and removed.
    If you found on one of the sites a similar command to install the program and installed it, but the program did not suit you and you want to uninstall, it is enough to change the command to install install on the remove and execute in the terminal as the program is uninstalled.

    Installing programs from a third-party repository

    Now let's look at the commands for installing and removing programs with the addition of a third-party repository (example):

    sudo add -apt-repository ppa: upubuntu-com / gtk + 3.6
    sudo apt-get update
    sudo apt-get install flatstudiodark-gtk

    First of all, let's find out why include a third-party repository? A repository is a repository of files on the developer's site. In this case, with the third command we want to set the theme, but it is not in Application Center, which means that we first need to connect the repository (repository) with the theme (first command), where add - add, ppa: upubuntu-com / gtk + 3.6- the name of the repository, then the second command is to update the list of packages and the third is to install the package with the theme itself.

    If this application(in a specific case, the theme) you did not like and you decided to remove it, then you can change the commands for installation so that they look like commands for removal:

    sudo apt-get remove flatstudiodark-gtk
    sudo add-apt-repository --remove ppa: upubuntu-com / gtk + 3.6
    sudo apt-get update

    First, you need to execute the command to remove the package with the program, where we change install on the remove, then delete the repository (repository) by adding to the command --remove - delete since the repository is now unnecessary and we update the system with the last command.

    Launching graphics programs with administrator rights.

    Let's say we need to run file manager Nautilus with administrator rights to somehow change the content through the graphical interface system folders... To do this, enter the following command:

    gksudo nautilus

    gksu nautilus

    Where the password entry, in this case, will take place in the graphics window, and not in the terminal.

    But you can additionally specify the required path in the command, directly to the desired folder:

    gksu nautilus / usr / share / themes

    In this command, a forward slash (/) - slash tells the terminal to go to the next folder after it.

    Launching programs from the terminal with the command

    In system Linux you can run any program installed on your system from the terminal, the main thing is to know its correct name. Many programs consist of one word-name, and some of two or three words. For instance: Nautilus; Ubuntu Tweak Gnome tweak tool... If we enter the name of the commands in the terminal as they are written, then we will not be able to open any of the applications. I repeat once again that the terminal is very case-sensitive, i.e. the command must be entered only in lowercase (lowercase letters) and must be monolithic, with a dash if it consists of several words (examples):

    nautilus

    ubuntu-tweak

    gnome-tweak-tool

    This way you can open applications, but if you close the terminal, the program will close with it. To prevent this from happening, you need to add the command exit to close the terminal after opening the program, separated by spaces and a separator & :

    nautilus & exit

    ubuntu-tweak& exit

    gnome-tweak-tool& exit

    Through the dividing mark & you can include several commands for execution (open) by combining them into one command:

    nautilus & ubuntu-tweak & gnome-tweak-tool & exit

    Creating directories (folders) and placing files in them

    Many of you have checked the boxes to display the keyboard layout in the tray using terminal commands:

    mkdir ~ / .icons

    mkdir ~ / .icons / flags

    cd ~ / .icons / flags

    Now let's take a closer look at each of the commands given.

    Team mkdir ~ / .icons- creates a hidden directory (folder) in Home folder entitled icons.

    mk- abbreviated from make - do, create. dir- abbreviated directoria - directory, folder.~ - tilde always means Home folder user. / - folder designation. .icons- indicates the name of the folder being created, and a dot in front always indicates that this folder is hidden.

    Team mkdir ~ / .icons / flags also creates a folder called / flags in a hidden folder /.icons and Home folder - ~ .

    Team cd ~ / .icons / flags makes a transition to a folder / flags, which in turn is located in Home folder - ~ and in hidden folder /.icons.

    cd - c- transition designation, d - directoria - directory (folder).

    Team wget http://suservice.net/icons/flags2/(ru,us).png loads checkbox files into a folder / flags, which we switched to in the previous step.
    wget- abbreviated from w - web- net, get - receive, i.e. get files from the network and always put before Url an address separated by a space. In this case, before http://suservice.net/icons/flags2/(ru,us).png from which files with flags are loaded.

    Kill the process with the command

    First of all, let's find out what is a process?

    When the system starts, many processes are launched that the user often does not even know about. But we see many processes on the monitor screen, we launch and manage them ourselves, this is open programs... Best of all, the program will tell us about this. top running in terminal:

    Sometimes it happens that some process in the system has crashed or some program simply "hangs" and the close button does not respond, or there is no close button at all (conky widget). In this case, in Linux there is a very good command - "killer":

    p- abbreviated from process(process), kill - kill.
    But by itself this command does not work, it needs an argument, i.e. or the number of the process, which is displayed in the column PID(see terminal snapshot) after executing the command top, or the name of the process in the column COMMAND... Don't worry, the command will not kill the program itself, it will only stop the execution process. If it is a graphics program, it will simply close. For the experiment, I chose the most innocuous process, which, when closed, will not harm anything. So run the following command:

    pkill gnome-terminal

    The terminal window has disappeared i.e. was "killed"(stopped) a process displaying a program on the monitor screen.

    xkill- kills the visible process and works by itself, i.e. after executing the command, click the resulting cross instead of the cursor on any visible program (window), as it closes.

    Conclusion

    I have selected parsing commands that a simple user usually encounters when setting up a system.
    If anyone wants to learn more about terminal commands, I recommend that you download the free reference Scott Granneman "Linux. Pocket Guide"... Just google Scott Granneman and give a search.

  • Did you like the article? Share with friends: