03 Common Commands of Linux

SHELL

        pcntl A complete computer is composed of arithmetic, controller, memory, input and output and other hardware devices, and the thing that allows various hardware devices to perform their duties and work together is the system kernel, Linux The kernel of the system is responsible for the allocation and scheduling of hardware resources, and it plays a very important role in the normal operation of the system.

image.png


           Shell is the general term for terminal programs. It is responsible for the translation work between humans and the kernel (hardware). When the user "tells" some commands to the terminal program, it will call the corresponding program services to complete certain tasks. The default terminal used by many mainstream Linux systems is the Bash (Bourne-Again SHell) interpreter, which has the following 4 advantages:

                        1: Use the up and down arrow keys to retrieve previously executed Linux commands;

                        2: Command or parameter can be completed with Tab key by entering only the first few digits;

                        3: Powerful batch script;

                        4: Practical environment variable function.


Command format

                Command name [command parameter] [command object]

                Command name: It is the "verb" in our grammar, which expresses what we want to do, such as creating users, viewing files, restarting the system, and so on.

                Command parameters: used to adjust the commands, so that the "modified" commands can better fit the work requirements, and achieve a multiplier effect. Parameters can be in long format (complete words) or short format (single letter abbreviation), and the two are prefixed with "--" and "-" respectively.

                Command object: generally refers to the file, directory, user and other resource names to be processed, which is the "receiver" after the command is executed. For example, create a user named Xiaoming, view a file called salary table, restart an IP with 192.168 .10.10 system and so on.

                Note: Use spaces to separate the command name, command parameters and command objects, and strictly distinguish between uppercase and lowercase letters.


Linux commands

                man: ( abbreviation of the word manual, that is, the meaning of the manual ) This command will list a complete description. Its content includes command syntax, meaning of each option and related commands. What’s more powerful is that you can view not only the help of commands in Linux, but also help information such as software service configuration files, system calls, library functions, etc. The man page files are stored in the /usr/share/man directory, and the syntax format : Man [command].

image.png

image.png

      

Common system work commands          

                Echo: used to output the string or the extracted value of the variable on the terminal device. This is one of the most commonly used commands in Linux systems, but the operation is very simple, the syntax format: echo [parameter] [string] .

        date: used to display or set the system time and date, the syntax format is: "date [+specified format]". "+%Y-%m-%d %H:%M:%S"

        reboot: Used to restart the system, press Enter and execute.

        poweroff: After closing the system, press Enter to execute. (halt \ init \ init 0)

        wget: Used to download network files in the terminal command line. The full English name is "web get", and the syntax format is: "wget ​​[parameter] URL". -c resume upload

        ps: Used to view the status of the processes in the system. The full English name is "processes", and the syntax format is: "ps [parameter]".  

            R: running

            S: Waiting for service (sleep state)

            D: Uninterruptible process

            Z: zombie process \ no service status

            T: stopped service stopped

image.png

                Example:

                ps aux all user displays processes without a terminal, which refers to processes or background processes opened by the system

                ps aux | wc -l View the number of lines

                ps aux | grep ssh filter

top: It is used to dynamically monitor information such as process activity and system load. After inputting, press Enter to execute. The syntax format is: "top [parameter]".

    5, 6, 7 version 1 user is the number of terminals, 8 version represents the number of logged-in users

    Load 1 minute 5 minutes 15 minutes # Number of cores*5 There is overload, you need to pay attention to the cpu may not be enough to use the cpu queue


    Tasks: 430 total,     2 running,     428 sleeping,     0 stopped,     0 zombie

    Total process: 430 2 running 428 sleep waiting 0 closed 0 dead processes


        cpu 0.0 us,      99.0 id

Use value cpu idle value


        MiB Mem: 1966.1 total,     146.5 free,      1374.2 used,      445.5 buff/cache

          Physical memory M Free memory has been used Used when tuning the value of interaction with the hard disk


        MiB Swap:  2048.0 total, 

           Swap partition (use part of the hard disk space as memory)


        pid user PR NI         

        Unique value user The lower the priority, the better

pidof: Used to query the PID number value of a specified service process, the syntax format is: "pidof [parameter] service name".

kill: used to terminate a service process with a specified PID value, the syntax format is: "kill [parameter] PID of the process".

killall: Used to terminate all processes corresponding to a service with a specified name, the syntax format is: "killall [parameter] service name".


System status detection command

        ifconfig: Used to obtain information such as network card configuration and network status. The full English name is "interface config", and the syntax format is "ifconfig [parameter] [network equipment]".

Rhel5\6 version eth0 eth1 eth2

Rhel7 ens16777728 ens16777728

Rhe8    ens160

iftop is a real-time traffic monitoring tool, monitoring TCP/IP connections, etc. The disadvantage is that there is no report function. Must be run as root.

uname: Used to view information such as the system kernel version and system architecture. The full English name is "Unix name", and the syntax format is "uname [-a]".

linux host system host name kernel version number system discovery time system architecture hardware kernel system system name

uptime: used to obtain information such as host running time and query Linux system load. , Press Enter to execute after input, syntax format: uptime [parameter].

free: Used to display the physical free and used memory in the system, as well as swap memory. At the same time, it can also display the buffers and caches used by the kernel. This information is collected by parsing the file /proc/meminfo. The syntax format is: "free [-h]".

who: Used to view the information of the user terminal currently logged in to the host. After inputting, press Enter to execute, the syntax format: who [parameter] [option]. The output information of the who command comes from the files "/var/log/utmp" and "/var/log/wtmp" by default.

last: used to retrieve the visited records of the host. After inputting, press Enter to execute, the syntax format: last [option]. When the last command is executed, it will read the file named wtmp in the /var/log directory, and display all the list of users logging in to the system or terminal recorded in the file. The record of wtmp is displayed by default, and btmp can display more detailed information, including remote login.

history: Used to display the history of executed commands, the syntax format is: "history [-c]". !Number Quickly use the used commands

sosreport: Used to collect system configuration and architecture information and output diagnostic documents, and press Enter to execute after input.


Working directory switch command

        pwd: used to display the current working directory of the user, the full English name is: "print working directory", after inputting, press Enter to execute, syntax format: pwd [parameter].

        cd: Used to switch the current working path. The full English name is "change directory", and the syntax format is: "cd [parameter] [directory]".

                cd ~ jump to the user's home directory

                cd .. jump to the upper directory

                cd-jump to the previous directory

        ls: Used to display the file information in the directory, the English name is "list", and the syntax format is: "ls [parameter] [file name]".


Text file editing commands

        cat: Used to view plain text files (with less content), the full English name is "concatenate", and the syntax format is "cat [parameter] file name".

        more: Used to view plain text files (more content), the syntax format is: "more [parameter] file name".

                    Press space next screen

                        B key up-screen

                    Press Enter to go down one line

        head: Used to view the first N lines of a plain text file, the syntax format is: "head [parameter] file name".

        tail: used to view the last N lines of a plain text file or continuously refresh the latest content of the file, the syntax format is: "tail [parameter] file name". -f refresh in real time

        tr: Used to replace characters in the text content. The full name in English is "translate", and the syntax format is: "tr [original character] [target character]".

                Example lowercase to uppercase cat file name | tr [az] [AZ]

        wc: used to count the number of lines, words, or bytes of a specified text file. The full English name is: "word counts", and the syntax format is: "wc [parameter] file name".

        stat: Used to view the specific storage details and time of the file. The full English name is "status", and the syntax format is "stat file name".

                        Atime The last time the file content was accessed Access

                        Mtime The time when the file content was last modified Modify

                        Ctime Last modified time of file attributes Change

    image.png


        cut: used to extract text content by column, the syntax format is: "cut [parameter] file name".

        diff: It is used to compare the content differences between multiple files. The full English name is "different", and the syntax format is "diff [parameter] file name A file name B".

                        diff --brief a.txt b.txt compares whether the two files are different

                        diff -c a.txt b.txt lists the differences between the two files      

                        View 10-30 data head -n 30 file name | tail -n 20


File directory management commands

        touch: used to create a blank file or set the time of the file, the syntax format is: "touch [parameter] file name".

                            touch -d "00:00" The last access time and modification time of the object name modification file

        mkdir: used to create a blank directory. The full English name is "make directory", and the syntax format is "mkdir [parameter] directory name".

                        Create recursive directory -p

        cp: Used to copy files or directories, the full English name is "copy", and the syntax format is: "cp [parameter] source file name and target file name".

                        Copy directory -r

                        Retain attribute permissions -a

        mv: used to cut or rename files, the full English name is "move", and the syntax format is: "mv [parameter] source file name and target file name".

                        rename rename

        rm: Used to delete files or directories. The full English name is "remove", and the syntax format is: "rm [parameter] file name".

                        -f false ignore reminder

                        -r Recursion recursion

        dd: Used to copy files or convert files according to the number of data blocks of the specified size. The syntax format is: "dd if=parameter value of=parameter value count=parameter value bs=parameter value".

                        if input file

                        ofoutput file

                        count   

                        bs

                        dd if=file name of=new file name bs=size byte count=number of copies

                        Hard disk directory /dev/sda

                            The 512 bytes stored in the first sector in the front are

        446 ibml master computer record 

        64 4 pointers to each 16-byte partition table

                                        2 Terminator

        Backup partition table dd if=/dev/sda of=backup count=1 bs=512

        file: Used to view the file type, the syntax format is: "file file name".


Package compression and search commands

        tar: used to pack, compress or decompress files, the syntax format is: "tar parameter file name".

        grep: used to extract text content by line, the syntax format is: "grep [parameter] file name".

                    grep keyword file

                        Example:

                                    grep /bin/bash /etc/passwd #Extract users who can log in to the system

        find: It is used to find the location corresponding to the file according to the specified conditions, the syntax format is: "find [find range] search condition".

                        find / -user username #Find out all the files about the user in the system

                        find / -mtime -1 files modified within 1 day

               
passwd: used to set user authentication information, including user password, account lock, password invalidation, etc. Run the passwd command directly to modify the current user password. The password operation of other users requires administrator authority. The syntax format is "passwd username".

image.png




Guess you like

Origin blog.51cto.com/14032821/2593394