Learning Linux Day 4

1. File directory management commands

          1.touch: Used to create a blank file or set the time of the file, the format is "touch [option] [file]"

                         Parameter -a (only modify "read time atime"); -m (only modify "modify time" mtime); -d (colleagues modify atime and mtime)

                        For example: touch abc creates a blank text file named abc

                                   touch -d "2021-01-10 16:30" anaconda-ks.cfg The time of the modified file can be set to the time before modification through the touch command (***commonly used)

           2.mkdir: used to create a blank directory, the format is "mkdir [option] directory"

                         mkdir  abc

                        You can combine the -p parameter to recursively create a file directory with nested stacking relationships.

                       For example: mkdir -pa/b/c/d/e/f

            3.cp: used to copy files or directories, the format is "cp [option] source file target file"

                     Parameters: -p (retain the attributes of the original file); -d (if the object is a "linked file", retain the attributes of the "linked file"); -r (recursively and continuously copy (for directories)); -i (if If the target file exists, it will ask whether to overwrite); -a (equivalent to -pdr)

                          cp a.log b.log       

             4. mv: used to cut or rename the file, the format is "mv [option] source file [target path|target file name]"

             5.rm: used to delete files or directories, the format is "rm [option] file"

                       Parameters: -f (forcibly delete files) -r (delete directories)

             6.dd: used to copy files or convert files according to the specified size and number of data blocks, the format is "dd [parameter]"

                       Parameters: if (file name input by inputfile); of (file name output by outputfile); bs (set the size of each "block"); count (set the size of the "block" to be copied)

                      dd if=/dev/zero of=560_file count=1 bs=560M Take a 560MB data block from the /dev/zero device file and save it as a "560_file" file.

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

                      dd if=/dev/cdrom of=linux.iso The CD in the CD-ROM drive is made into an iso file

              7.file: used to view the file type, the format is "file file name"

  Two, package compression and search commands

             1.tar: used to pack or decompress files, the format is "tar [option] [file]"

                       tar -czvf name of the compressed package.tar.gz name to be packaged      

                       For example: tar -czvf etc.tar.gz /etc

                                 tar -xzvf etc.tar.gz -C /root/etc Unzip to the specified directory /root/etc

              2. grep: Extract by line, used to perform keyword search in the text, and display the matching results, the format is "grep [option] [file]"

                            grep /sbin/nologin  /etc/passwd  

              3.find: used to find files according to specified conditions. The format is "find [search path] search condition operation"

                           find /etc -name "host*" -print Get the list of files starting with host in the configuration file

                           find / -perm -4000 -print Search for all files with SUID permissions included

                           find / -user abc -exec cp -a {} /root/etc/ \; Find all files belonging to the abc user in the entire file system and copy them to the /root/etc directory

       Three, input and output redirection

                                                          Commands and files

                                    Output redirection >Clear >>Append 2>Error clear 2>>Error append &>All output is equivalent to 2>&1

                                    Input redirection <input

       Fourth, the pipeline command symbol 

                                Command A|Command B

                         Regard the standard normal data originally output to the screen by the previous command as the standard input of the next command

                          echo "abc"| passwd --stdin root The pipe conforms to the --stdin parameter combination of the passwd command, and the password is reset.

        Five, wildcards on the command line

                            * Empty value or infinite number of values;? A value; [az] lowercase letters; [AZ] uppercase letters; [0-9] numbers; [1,3,5] specify numbers; [a,c,e] specify letter

         Six, commonly used escape characters

                         \ Make a variable after the backslash a simple string

                         "If you want to escape the processed result globally, add single quotes

                        "" If there are spaces in the object to be processed, you need to add double quotes to make it a whole

                         `` Execute the command inside, and then feedback the final result

                         echo `uname -a` displays the linux version and kernel information of the machine

           Seven, important environmental variables

                         1. Determine whether the user enters the command in an absolute path or a relative path, and execute it directly if it is

                         2. Check whether it is an "alias command". alias alias=command unalias alias=command

                         3. The Bash interpreter judges whether the user inputs an internal command or an external command. The internal command is executed directly, and most of the user input is an external command.

                         4. The system searches for the command files entered by the user in multiple paths, and the variables that define these paths are called PATH, the assistant of the interpreter, tells the Bash interpreter where the commands to be executed may be stored.

            Everything in Linux is a file. 10 illusion variables: HOME SHELL HISTSIZ HISTFILESIZE MAIL LANG RANDOM PS1 PATH EDITOR

                          env set displays all environment variables in the system

                          export converts general variables into global variables

    

image.png

image.png

image.png

Guess you like

Origin blog.51cto.com/15047572/2586655