The basic framework of the shell:
the basic characteristics of 1.bash
shortcuts and basic information 2.io redirection pipe character and 3. Programming basis: Principles of Programming procedure: a piece of code to perform a certain function program data + instruction + = (logic) command + variable 4.grep and regular expressions ************ Linux Three Musketeers pattrn "model" logical relationship 5. statement - variable Linux Three Musketeers 1.sed (stream edit d?) switch between modes 2.awk (report generator) he is a unique programming language function: a code block for a fixed function array: a list of tuples, the dictionary string: string processing is repeated: the same must be continuous and data, go first sorting weight - cycle: IF, for (the advantage is not easy to enter an infinite loop, the program put into circulation for a list) while-- loop condition is true when entering the loop
until (cycling) into the circulation loop condition is false
case-- "write Linux startup script"
- break the cycle
BREAK
the Continue
Exit - to exit the current state, the return value of the specified program execution
read == input () input
echo == print () output
exercise:
1. whether Analyzing / etc / inittab files larger than 100 lines, if a large file is larger than the display, the display is less than small files
#! / bin / the bash
Line WC = `-l / ECT / inittab | Cut -d '' -f1`
IF $ Line Test -gt 100; the then
echo" / etc / inittab IS A Big File. "
the else
ehco" / etc / IS A Small File inittab. "
------------------------------------------- -------------------------------------------------- ----------
bash basic characteristics
1. command history
function: command previously used to view
files on the command history of
each user's home directory .bash_history
When turned off, it will automatically write-once (history -r command stored in the memory within the file)
variable on the command history (environment variables)
env // View environment variables
set // view a more detailed environmental variable parameters
HISTSIZE = 1000 number
of the HISTCONTROL of ignoredups = HISTFILE The = / the root / .bash_history the HISTFILESIZE = 1000
the basic characteristics of 1.bash
shortcuts and basic information 2.io redirection pipe character and 3. Programming basis: Principles of Programming procedure: a piece of code to perform a certain function program data + instruction + = (logic) command + variable 4.grep and regular expressions ************ Linux Three Musketeers pattrn "model" logical relationship 5. statement - variable Linux Three Musketeers 1.sed (stream edit d?) switch between modes 2.awk (report generator) he is a unique programming language function: a code block for a fixed function array: a list of tuples, the dictionary string: string processing is repeated: the same must be continuous and data, go first sorting weight - cycle: IF, for (the advantage is not easy to enter an infinite loop, the program put into circulation for a list) while-- loop condition is true when entering the loop
until (cycling) into the circulation loop condition is false
case-- "write Linux startup script"
- break the cycle
BREAK
the Continue
Exit - to exit the current state, the return value of the specified program execution
read == input () input
echo == print () output
exercise:
1. whether Analyzing / etc / inittab files larger than 100 lines, if a large file is larger than the display, the display is less than small files
#! / bin / the bash
Line WC = `-l / ECT / inittab | Cut -d '' -f1`
IF $ Line Test -gt 100; the then
echo" / etc / inittab IS A Big File. "
the else
ehco" / etc / IS A Small File inittab. "
------------------------------------------- -------------------------------------------------- ----------
bash basic characteristics
1. command history
function: command previously used to view
files on the command history of
each user's home directory .bash_history
When turned off, it will automatically write-once (history -r command stored in the memory within the file)
variable on the command history (environment variables)
env // View environment variables
set // view a more detailed environmental variable parameters
HISTSIZE = 1000 number
of the HISTCONTROL of ignoredups = HISTFILE The = / the root / .bash_history the HISTFILESIZE = 1000
history 的常见操作
1.查看命令历史
2.!+数字
3.!+字符串 匹配最近一次的字符串
4.!!上一条命令
5.!$上一条命令的最后一个参数:ls /etc ls !$
ls ESC.
6.常见的选项:
-a
-d 行号 删除对应命令
-c 清空历史命令
history 【数字】 显示最近数字行的命令
2.命令补全
Tab键 1.提示 2.自动补全
扩展:制表符 \t 是个空格
3.目录补全
Tab键 1.提示 2.自动补全
4.命令展开 ---date
{,}
Linux的目录需要遵循什么规则?--FHS目录规则
makdir -pv /var/{a,b}-{1,2}
date 基于data命令来创建目录
%F 年-月-日
%T 小时-分钟-秒
%D 月 - 日 - 年
%H 小时
%M 分钟
%S 秒
%Y 年
练习:通过for语句循环创建一个月的日志文件
for i in {1..30};do (do是执行这个程序)
touch `date +%Y-%m-$i`.http.log;done($i是调用i)
tar
*******压缩这个操作只能针对文件,不能针对目录
压缩工具:
gzip
bzip2
xz
tar的常见参数:
tar 归档工具【可以对目录进行操作】
-j bzip2
-J xz
-z gzip
-c 创建
-x 解压
-f 指定文件名
-v 显示详细信息
g-t 不解压查看内容和zcatu一样
练习:编写脚本,每天两点20备份/etc/目录中所有文件,名称为当天日期,且保存文件
crontab -->20 2 * * * /root/xxx.sh
vim xxx.sh
#!bin/bash
#
tar cjvf /var/`date +%F`.xz /etc
chmod +x xxx.sh
补充:
clock /hwclock 常看硬件时钟
5.命令的执行状态
在Linux中,每一条命令执行后都会有两个结果:
命令本身放回的内容
其次,命令执行的结果状态
$?变量,就i是用来存放命令执行状态的变量;
0 表示成功
1-255表示失败
6.命令的快捷键
ctrl + l
ctrl +c
ctrl +u 删除光标前的字符
ctrl +k 删除光标后的字符
ctrl +a
ctrl +e
ctrl +w 以空格为分割符,删除文件
ctrl +r 进入一个交互界面,搜索最近一次使用的命令(要输入string)
7.alisa别名
系统启动时读取一些特殊文件的顺序
alias
alias cdnet ="命令"这种只能在当前shell生效;
/etc/profile 定义环境变量(所有用户) -- EXPORT HISTCONTROL=XXX
/etc/bashrc 定义本地变量--alias(所有用户)
1.查看命令历史
2.!+数字
3.!+字符串 匹配最近一次的字符串
4.!!上一条命令
5.!$上一条命令的最后一个参数:ls /etc ls !$
ls ESC.
6.常见的选项:
-a
-d 行号 删除对应命令
-c 清空历史命令
history 【数字】 显示最近数字行的命令
2.命令补全
Tab键 1.提示 2.自动补全
扩展:制表符 \t 是个空格
3.目录补全
Tab键 1.提示 2.自动补全
4.命令展开 ---date
{,}
Linux的目录需要遵循什么规则?--FHS目录规则
makdir -pv /var/{a,b}-{1,2}
date 基于data命令来创建目录
%F 年-月-日
%T 小时-分钟-秒
%D 月 - 日 - 年
%H 小时
%M 分钟
%S 秒
%Y 年
练习:通过for语句循环创建一个月的日志文件
for i in {1..30};do (do是执行这个程序)
touch `date +%Y-%m-$i`.http.log;done($i是调用i)
tar
*******压缩这个操作只能针对文件,不能针对目录
压缩工具:
gzip
bzip2
xz
tar的常见参数:
tar 归档工具【可以对目录进行操作】
-j bzip2
-J xz
-z gzip
-c 创建
-x 解压
-f 指定文件名
-v 显示详细信息
g-t 不解压查看内容和zcatu一样
练习:编写脚本,每天两点20备份/etc/目录中所有文件,名称为当天日期,且保存文件
crontab -->20 2 * * * /root/xxx.sh
vim xxx.sh
#!bin/bash
#
tar cjvf /var/`date +%F`.xz /etc
chmod +x xxx.sh
补充:
clock /hwclock 常看硬件时钟
5.命令的执行状态
在Linux中,每一条命令执行后都会有两个结果:
命令本身放回的内容
其次,命令执行的结果状态
$?变量,就i是用来存放命令执行状态的变量;
0 表示成功
1-255表示失败
6.命令的快捷键
ctrl + l
ctrl +c
ctrl +u 删除光标前的字符
ctrl +k 删除光标后的字符
ctrl +a
ctrl +e
ctrl +w 以空格为分割符,删除文件
ctrl +r 进入一个交互界面,搜索最近一次使用的命令(要输入string)
7.alisa别名
系统启动时读取一些特殊文件的顺序
alias
alias cdnet ="命令"这种只能在当前shell生效;
/etc/profile 定义环境变量(所有用户) -- EXPORT HISTCONTROL=XXX
/etc/bashrc 定义本地变量--alias(所有用户)
~/.bash_profile 定义环境变量(指定用户)
~/.bashrc 定义本地变量(指定用户)
手动写入后 sources /etc/profile 或者 . /etc/profile
8.文件通配符 [文件通配符不是正则表达式]
?任意单个字符
* 任意长度的任意字符
[] 指定范围内的任意一个字符
1.[^]指定范围以外的任意字符
指定字符类[^0-9a-zA-Z]是指定符号
[:digit:]
任意数字, 相当于0-9
[:lower]
任意小写字母
[upper:]
任意大写字母
[alpha:]
任意大小写字母
[:alnum:]
任意数字或字母
[:blank:]|
水平空白字符
[:space:]
水平或垂直空白字符
[punct:]
标点符号
[print:]
可打印字符
[:cntrl:]
控制(非打印)字符
[:graph:]
图形字符
[xdigit:]
十六进制字符
~/.bashrc 定义本地变量(指定用户)
手动写入后 sources /etc/profile 或者 . /etc/profile
8.文件通配符 [文件通配符不是正则表达式]
?任意单个字符
* 任意长度的任意字符
[] 指定范围内的任意一个字符
1.[^]指定范围以外的任意字符
指定字符类[^0-9a-zA-Z]是指定符号
[:digit:]
任意数字, 相当于0-9
[:lower]
任意小写字母
[upper:]
任意大写字母
[alpha:]
任意大小写字母
[:alnum:]
任意数字或字母
[:blank:]|
水平空白字符
[:space:]
水平或垂直空白字符
[punct:]
标点符号
[print:]
可打印字符
[:cntrl:]
控制(非打印)字符
[:graph:]
图形字符
[xdigit:]
十六进制字符