The basic characteristics of bash

  1. Command History

Role: Before using the View command

File on the command history

Under each user's home directory .bash_history , it will automatically shut down when the write-once ( History - r The memory write command history file)

(User write password)

chroot switching root file system

About command history (environment) variable

env viewing environment variable

set view a more detailed environmental variable parameters

HISTSIZE = 1000     Number 1000

= Of ignoredups of the HISTCONTROL     (three values ignoredups ignorespace ignoreboth)

HISTFILE=/root/.bash_history

HISTFILESIZE=1000

history common operations

! + Number: View numbered line command history

! + string match last string

! ! The previous command

! $ = (Shortcut key esc +. ) The last argument of the previous command

Common options

-a historical command buffer write command history file

-d Delete

-c Clear History command

history # Show last # command line

path is an environment variable

  1. Command Completion

tab key (role: prompt, auto-complete)

Expansion: the Tab key is a tab    \ t = four spaces

  1. Directory completion

tab key (role: Tips and auto-completion)

  1. Command to expand

data command

{,}

Linux directory to follow FHS directory rules

Attribute 1   Attribute 2

  a      1

b      2

mkdir - pv / var / {a, b} - {1,2}

date    based on date created directory command

date +

% F date

% H Hour

% M minutes

% m month

% S becomes seconds

% T minutes and seconds

% D Year Month Day

% Y Year

Exercise : through for creation statements month cycle log files: .log 2019-08-6.http.log

touch‘date +%F’.http.log

at and crontab

 

for i in {1...30};do

touch  ‘date+%Y -%m-$i’.http.log;

done

Compression tools: gzip bzip2 the xz

Tar archives (compression and decompression) zcat not unzip files compressed package look

Compression can only manipulate files and directories can not be operated, the archive can be operated directory

Common parameters

-j bzip2

The xz -J (most efficient)

-z gzip

-c creat create

-x extrect decompression tool can not specify unzipped

-f specify the file name

-v Show Details

-t not view the contents of decompression, and zcat as

tar cjvf 2019-08.http.log.bz2 2019-08 -. * http.log (* wildcard )

tar xvf 2018-08.http.log.bz2 -C abc

Exercise : write a script, every day 02:20 backup / etc / all files in the directory, the name is today's date and save the file as a compressed file

crontab -e -- 20 2 * * * /root/xxx.sh  

vim xxx.sh

#!/bin/bash

#

tar cJvf  /var/’date +%F’ .xz /etc/

chmod +x xxx.sh

supplement:

clock / wclock: Check the hardware clock (if the hardware clock synchronized with the system clock)

cal Calendar

  1. Execution status of the command

 In Linux after the implementation of each command will have two results: the content itself back in command, the command execution result status

 $? Variables stored command execution state variable 0 indicates success 1-255 indicates a failure

127 command not found

2 file or directory does not exist

13 do not have permission

.

.

Available program execution exit manually specify the status code returned return a return code specified in the function

[$? -eq ] &&exit || exit 1

  1. Shortcuts command

ctrl + l

   + C to stop the process

   + U Delete the character before the cursor

   + k delete characters after the cursor

   + A jump cursor head

   + E under cursor tail

   + w a space-delimited files to delete

+ z lock screen

+ r to enter a command interactive search page recently used (to be input string)

  1. alias alias

Read the special file system startup sequence

Global configuration file:

/ etc / Profile : define environment variables (for all users)

/ etc / bashrc : define local variables ( Alias all users)

In the user's home directory, use their own after the restart still valid:

~ / .bash_profile : definition of environment variables (user specified)

~ / .bashrc : define local variables (user specified)

export HISTCONTROL = xxx    introduced into an environment variable (by sources / etc / profile or . / etc / profile introduction)

 

cdnet = Alias " CD / etc / sysconfig / Network-scripts / " (= No white spaces )

Only in the current shell execution

File wildcard --globbing

Not a regular expression wildcard file

? Any single character

* Any character of any length

[] Any one character in the specified range

^ 1 , the beginning of what

2, [^] any character other than a specified range

The specified character class [^ 0-9A-Za-z]

Specify character classes :

[:alnum:], [:alpha:], [:cntrl:], [:digit:], [:graph:], [:lower:], [:print:],

        [:punct:], [:space:], [:upper:], and [:xdigit:]

 

^ [[: Space:]] * $ // There spacebar blank line (regular expression)

 

9, exercise

1 , the display / var in all directory a beginning and ending with a lowercase letter, and had at least one intermediate digital files or directories;

ls / var / 1 * [0-9] * [az]

2 , display / etc directory, start with any digit, and ending in a non-digital file or directory

ls /etc/[0-9]*[^0-9]

3 , the display / etc directory, start with a non-letter followed by other letters and a document of any length or any character directory

ls /etc/[^[:alpha:]][[:alpha:]]*

4 , copy / etc directory, all to m the beginning to the end of a non-numeric file or directory to / tmp / test directory;

cp -a /etc/m*[^0-9]  /tmp/test

5 , copy / etc directory, all to .d end of the file or directory to /tmp/test.com directory

cp -a /etc/*.d$ /tmp/test.com

6 , copy / etc directory, all .conf end, and with mnrp beginning of the file or directory to /tmp/test.com directory

cp -a /etc/[mnrp]*.conf /tmp/test.com

Guess you like

Origin www.cnblogs.com/bishuyu/p/11313094.html
Recommended