# 1, command history
Effect: Commands used before the investigation
File on the command history
Each user's home directory below .bash_history when the shutdown will automatically write-once (history -r command history will be written in the memory file)
About command history variables (environment variables)
Check the environment variable env //
set // often see a more detailed environment variable parameter
HISTSIZE = 1000 number
HISTCONTROL = ignoredups ignored repeated commands
Common operating history of
View command history
! # # Indicates that the command value, execution of line #
! string matches a string of recent
! ! The previous command
*! The last argument of the previous command $ *
ls /etc
ls! $
Esc+.
Common options:
-a
-d
-c
Recent history # # command line
# 2, command completion
tab
1. Tip 2. autocomplete
Extended: Tab \ t four spaces
# 3, directory completion
tab
1. Tip 2. autocomplete
# 4, the command expand --data command
{}
Linux directories need to follow any rules? - -FHS Listing Rules
Attribute Attribute 1 2 A 1 B 2
mkdir -pv / var / {A, B} - {1,2}
date command to create a directory based on date
date +%F-%H:%M:%S 2019-08-06-22:29:08
%F CCYY-MM-dd
%T hh:MM:ss
%D mm/dd/YY
%H hh
%M MM
%S ss
%Y CCYY
tar
compression tools
gzip
bZIP
the xz
zcat // view compressed files without decompression
[compression can only compress the file, but can not operate on the directory]
common parameters of tar:
tar archiving tool can operate on [directory]
-j bzip2
- the xz J
the -z gzip
- c the Create
-x Extract // can not know decompression tool
- f specify the filename
- v show Details
-t not view the contents and unpack zcat as
# Exercise: to write scripts, 02:20 daily backups / etc / directory of all files named today's date; and save the file as a compressed file
crontab -- 20 2 * * * /root/xxx.sh vim xxx.sh #!/bin/bash # tar cJvf /var/`date +%F`.xz /etc/ chmod +x xxx.sh 补存: clock / hwclock 查看硬件始终(如果同步系统时钟与硬件时钟) cal 日历
#5、命令的执行状态
在Linux中,每一条命令执行后都会有俩个结果:1)命令本身放回的内容
2)其次,命令执行的结果状态
$? 变量,就是用来存放命令执行状态的变量:0 表示成功状态(与Python正好相反)
1~255 表示失败状态
#6、命令的快捷键
ctrl + l ctrl + c ctrl + u //删除光标前的字符 ctrl + k //删除光标后的字符 ctrl + a ctrl + e ctrl + w //以空格为分隔符,去删除文件 ctrl + r //进入一个交互界面,搜索最近一次使用的命令(要输入string)
#7、alias别名
系统启动时读取一些特殊文件的顺序;
alias cdnet="cd /etc/sysconfig/network-scripts" //这种方式定义alias只能在当前shell生效;
/etc/profile : 定义环境变量(所有用户)
/etc/bashrc :定义本地变量-- alias(所有用户)
~/.bash_profile:定义环境变量(指定用户)
~/.bashrc:定义本地变量--alias(指定用户)
sources /etc/profile 或者 . /etc/profile 生效修改内容
#8、文件通配符--globbing
【文件通配符不是正则表达式】
? 任意单个字符
* 任意长度的任意字符
[] 指定范围内的任意一个字符
[0-9A-Za-z]
[0-9][a-z][A-Z][a-zA-Z]
指定字符类:
[:alnum:] 匹配任意一个字母或数字
[:alpha:] 匹配任意一个字母
[:digit:] 匹配任意一个数字
[:lower:] 匹配任意一个小写字母
[:upper:] 匹配任意一个大写字母
一般常用的匹配:
模式 匹配对象 * 所有文件 p* 文件名以“p”开头的文件 r*.txt 以”r” 开头,中间有零个或任意多个字符,并以”.txt” 结尾的文件 Data??? 以“Data”开头,其后紧接着 3 个字符的文件 [abc]* 文件名以”a”,”b”, 或”c” 开头的文件 BACKUP.[0-9][0-9][0-9] 以”BACKUP.” 开头,并紧接着 3 个数字的文件 [[:upper:]]* 以大写字母开头的文件 [![:digit:]]* 不以数字开头的文件 *[[:lower:]123] 文件名以小写字母结尾,或以“1”,“2”,或“3”结尾的文件