The basic characteristics of the Shell-bash

1, command history
        function: Before using the view commands
        on the command history file
            for each user's home directory below .bash_history
            when the shutdown will automatically write-once (history -r command history will be written to the file memory)
        on variables (environment variables) command history
            env // viewing environment variable
            set // View detailed environmental variable parameters
            HISIZE = 1000 the number of
            HISCONTROL = ignoredups
        common operating history of
            view the command history
            !! command on
            *! * $ a command on the last parameter
                    LS / etc
                    LS! $
                    the ESC +
            common options
            -a
            -d
            -c
            History # # line displays the most recent command
2, command completion
        TAB
            1, Tip 2, automatic completion
        extension: Tab \ t four spacebar
3, catalogs complement
        the TAB
        1, Tip 2, automatic completion
4, the command expand -date command
        {}
        Linux directories need to follow any rules? --FHS directory rules
        date to create a directory on the date command
                % F CCYY-mm-dd
                % H HH
                % MM M
                % S SS
                
                log files created by the for loop to month:: Practice .log 2019-08-6.http. log
            for I in {1..30}; do
                Touch DATE + `% F-% m -% $ i.http.log
            DONE
        the tar
            compression tool
            [compression can compress the file, the directory can not be compressed]
            the gzip
            bzip2
            xz
            zcat // view compressed files without decompressing
        common parameters of tar:
            tar archiving tool can operate on [directory]
            -j bzip2
            -J the xz
            the -z gzip
            -c the Create
            -x Extract // can not specify an extraction tool
            -f specified filename
            -v displays detailed information verbose
            -t not extract the contents of the same view and zcat
        tar cjvf 2018-08.http.log.bz2 2018-08 -. * http.log
        tar xvf 2018-08.http.log.bz2 -C abc
        
        exercise: to write scripts, 02:20 daily backups / etc / directory of all files, the name of the current date; and save the file as a compressed file;
        crontab -e - 20 2 * * * /root/xx.sh
        vim xx. SH
            #! / bin / the bash
            #
            the tar cJvd / var / DATE + `% F`.xz / etc /
        Clock
        hwclock
5, execution status of the command
in Linux, after executing each command, there will be two results:
    the command itself in return the contents
    Secondly, the results of the command execution state of
$ variable, the variable is used to store the command execution state;?
    0 status indicates success (and Python opposite)
    1-255 represents a failure state
6, command shortcuts
    Ctrl + the I
    Ctrl + C
    Ctrl + U // delete the character before the cursor
    ctrl + K // delete character after the cursor
    ctrl + a
    E + Ctrl
    Ctrl + W // a space as a separator, to delete a file
    ctrl + R // enter an interactive interface, search a recently used command
7, alias alias
    system reads the order of some special files on startup;
    
    alias cdnet = "cd / etc / sysconfig / network-scripts" // this definition only applies to the current alias shell
    / etc / Profile: define environment variables (for all users) --export HISTCONTROL =
    / etc / bashrc: this amount is defined locally --alias (all users)
    ~ / .bash_profile: definition of environment variables (user specified)
    define local variables --alias (user specified): ~ / .bashrc
    
    Sources ~ / .bashrc
the globbing -. 8, wildcard file
        [File] not a regular expression wildcard
        any single character?
        any character of any length *
        [] within the specified range any one character
        to the beginning of what ^ 1
          any 2, [^] a character other than the specified range
            [0-9A-Za-Z ^]
            [0-9] [AZ] [AZ] [a-zA-the Z]
        specified character class:
        symbol
character identifier
        [: digit for:]
            any number, equivalent to 0-9
        [: Lower]
            any lowercase letter
        [Upper:]
            any capital letters
        [Alpha:]
            any case letters
        [: alnum:]
            any number or letters
        [: blank:] |
            horizontal white space
        [: space:]
            horizontal or vertical whitespace
        [punct:]
            Punctuation
        [Print:]
            Printable characters
        [: cntrl:]
            the control (non-printing) characters
        [: graph:]
            graphic character
        [xdigit:]
            hexadecimal characters

9. exercise
    1, show all beginning with 1 and ending with a lowercase letter, and had at least one intermediate digital file or directory in / var;
        LS / var / 1 * [0-9] * [AZ]
    2, display / etc directory, start with any digit, and ending in a non-digital files or directories
        LS / etc / [0-9] * [^ 0-9]
    3, the display / etc directory to begin with non-alphabetic followed by a letter and any other arbitrary length character file or directory
        LS / etc / [^ [: Alpha:]] [[: Alpha:]] *
    . 4, copy / etc directory, all beginning with m, to end of the non-numeric file or directory to / tmp / test directory;
        CP -a / etc / m * [^ 0-9] / tmp / test
    5, copy / etc directory to the end of the file or directory .d /tmp/test.com to a directory of all the
        CP -a /etc/*.d$ /tmp/test.com
    . 6, copy / etc directory, All end .conf, and at the beginning of the file or directory to /tmp/test.com mnrp directory
        cp -a /etc/[mnrp]*.conf /tmp/test.com
        
       

Guess you like

Origin www.cnblogs.com/jklp-1234/p/11311440.html
Recommended