A long lists
- Shell hello
- File pro Toos
- Toos and sed
- Rpm and yum
shell hello
- 格式
- 变量
- 运算
- 条件
- 登录方式与配置文件读取
- 环境
格式
行首:#!/bin/shells
注释:"#" 开头
运行:bash script 、chmod +x script ; 路径 / script
建议:添加脚本的作用,使用方法,参数、变量说明。
变量
Type :string number
命名 :- 关键字、-数字字母下划线、驼峰命名
种类 :
- 局部变量:当前shell内有效
- 环境变量:当前shell、子shell
- 本地变量: funtion
- 位置变量: 参数:123 10 所有,数组
- 特殊变量:
$?:cmd retrun 、也可在script中设置 exit[value] 来控制retrun
$0:script name
$$:当前进程pid
- 只读变量:readonly 变量、declare 变量
运算
- 算数符
+ - * / % let
- 随机函数
$RANDOM 0-32767
- 增强算数符
+= -= *= /= %=
- 自增减
++ --
- 逻辑运算
true false 0 1
& | ! ^ && ||
条件
test 判断
[ 判断 ]
[[ 判断 ]]
read -p "string" -s -n 10 -d "S" -t 30 str
读取一个输入到str中 设置提示:string 不显示输入内容 长度为10 S字符结束 30秒内输入时限
登录方式与配置文件读取
1.生效范围
- 全局:
/etc/profile
/etc/profile.d/*.sh
/etc/bashrc
- 用户:
~/.bash_profile
~/.bashrc
2.登录形式
- 交互式
1 终端输入账号密码登录
“su - UserName” 切换的用户
执行顺序:/etc/profile --> /etc/profile.d/*.sh --> ~/.bash_profile -->
~/.bashrc --> /etc/bashrc
- 非交互式
- Profile
profile类:
为交互式登录的shell提供配置
全局:/etc/profile,/etc/profile.d/*.sh
个人:~/.bash_profile
功用:
(1) 用于定义环境变量
(2) 运行命令或脚本
- Bashrc
为非交互式和交互式登录的shell提供配置
全局:/etc/bashrc
个人:~/.bashrc
功用:
(1) 定义命令别名和函数
(2) 定义本地变量
- 更改配置文件后生效方法:
1重启shell进程
2source 或 . 配置文件名
例 生效全局bashrc: source /bin/bashrc 或 .空格~.bashrc
- 退出后执行
File por toos
- locate
- find
- xargs
- compress uncompress
- gzip zunzip
- bzip2 bunzip2
- xz unxz
- zip unzip
- tar
- cpio
locate
- 非实时查找,用之前需要先创建一下数据库:updatedb,来创建对应文件列表的数据库,速度快是优势,但是构建数据库过程会消耗很多资源
- 语法&使用
locate [option] keyword
-i 不区分大小写
-n 前n个
-r 使用正则
find
- 实时查找,遍历指定路径
- 语法&使用
find [option] [路径] [动作]
深度:max/min depth level
1.文件名:find -name "filename" (支持grop,-i 区分大小写)
2.节点查找:find -inum 节点号(inode)
3.链接数相同:find -link name
4.指定用户:-user
5.指定组:-group
6. uid gid 用户或组id查找
7.取反组与用户 -nouser -nogroup
8.文件类型查找-tpye
-8-1 find tpye -d 目录
-8-2 find tpye -f 路径
-8-3 find tpye -l 符号链接
-8-4 find tpye -b 块结构
-8-5 find tpye -p 管道
9. -empty 空目录或空文件
10.组合条件:-a -o -not ! (与或非)
and day
-
动作
-ls : 相当于执行结果后的 ls-l 效果
-delete:删除找到的文件or目录
-ok cmd {}; 对找到的文件执行cmd 命令需要执行用户确认
-exec cmd{} ; 对找到的文件执行cmd
{}:代指命令查找的文件名称自身
Xargs
- 简介:
由于很多命令不支持管道|来传递参数,xargs用于产生某个命令的参数,xargs
可以读入 stdin 的数据,并且以空格符或回车符将 stdin 的数据分隔成为参数
许多命令不能接受过多参数,命令执行可能会失败,xargs可以解决
注意:文件名或者是其他意义的名词内含有空格符的情况
find和xargs的组合:find | xargs COMMAND
示例
ls | xargs rm 删除当前目录下的大量文件
find /sbin/ -perm +700 | ls -l 这个命令是错误的
find /bin/ -perm /7000 | xargs ls -Sl 查找有特殊权限的文件,并排序
find /bin/ -perm -7000 | xargs ls -Sl 此命令和上面有何区别?
find -type f -name “*.txt” -print0 | xargs -0 rm 以字符nul分隔
部分常用解、压缩、归档工具
未完待续。。。2019-10-14