2 unit 6
来源:互联网 发布:自己的淘宝账号怎么看 编辑:程序博客网 时间:2024/06/06 23:50
###unit6.shell脚本命令###
###1.diff
diff file file1##
比较两个文件的不同
diff -c ##显示周围的行
diff
-u ##按照格式统一输出生成的补丁
diff -r
##比较两个目录文件的不同
patch
patch
file file.path ##打补丁
patch -b ##备份原文
件
###2.grep
grep 关键字符 文件|目录 ##在文件或目录中查
找含有关键字的行
grep -i ##忽略大小写
grep
-n ##显示关键字所在行
grep -c
##显示过滤结果的个数
grep -v ##反向过滤
grep -E "关键字1|关键字2"##过滤多个关键字
grep -r 关键字 目录##在目录中查找含有关键字的文件
注意
:^关键字 ##以关键字开头
关键字$
##以关键字结尾
###3.cut
cut ##
截取字符
cut -d 分隔符 ##指定分隔符
cut -f 1,7
##显示指定的列
cyt -c 1-4 ##显示指定
的字符
只显示ifconfig eth0中的ip地址
[root@localhost ~]# ifconfig
eth0 | grep inet | grep inet6 -v | cut -d " " -f 10
[root@localhost
~]# ifconfig eth0 | grep inet | grep inet6 -v | awk -F " " '{print
$2}'
###4.sort
sort ##排序
sort -n
##纯数字排序
sort -u ##
去冗余(去除重复的)
sort |uniq -c ##去除冗余并统计冗
余次数
sort -t ##指定分隔符
sort -k
##指定列
###5.uniq
sort file | uniq -c ##
去掉冗余并统计冗余的次数
sort file | uniq -d ##显示冗余
行
sort file | uniq -u ##显示唯一行
###6.sed
sed 's/原字符/
替换字符/g' file
sed -e '策略1' -e '策略2' file
sed -i file
##把转换后的内容输入到指定文件
sed '3,5s/原字符/替换字符/g'
file ##3—5行替换
sed xd ##屏蔽指定行
sed xp
##复制指定行
sed -n xp ##
只显示指定行
sed -f 策略文件 file ##表示指定策略文件
###脚本
userfile
westos1
westos2
westos3
passwdfile
redhat1
redhat2
redhat3
user_create.sh
#!/bin/bash
MAX=$( wc -l $1 | cut -d " " -f 1 )
for NUM
in $( seq 1 $MAX )
do
USERNAME=$( sed -n ${NUM}p $1)
PASSWD=$( sed -n ${NUM}p $2)
useradd $USERNAME
echo
$PASSWD | passwd --stdin $USERNAME
done
测试
[root@desktop18 mnt]# sh
user_create.sh userfile passwdfile
Changing password for user
westos1.
passwd: all authentication tokens updated successfully.
Changing password for user westos2.
passwd: all authentication
tokens updated successfully.
Changing password for user westos3.
passwd: all authentication tokens updated successfully.
###tr
[root@desktop2 mnt]# cat file
a
a
a
a
a
[root@desktop2 mnt]# tr 'a-z'
'A-Z' < file
A
A
A
A
A
[root@desktop2 mnt]# tr 'a' 'Z' < file
Z
Z
Z
Z
Z
###1.diff
diff file file1##
比较两个文件的不同
diff -c ##显示周围的行
diff
-u ##按照格式统一输出生成的补丁
diff -r
##比较两个目录文件的不同
patch
patch
file file.path ##打补丁
patch -b ##备份原文
件
###2.grep
grep 关键字符 文件|目录 ##在文件或目录中查
找含有关键字的行
grep -i ##忽略大小写
grep
-n ##显示关键字所在行
grep -c
##显示过滤结果的个数
grep -v ##反向过滤
grep -E "关键字1|关键字2"##过滤多个关键字
grep -r 关键字 目录##在目录中查找含有关键字的文件
注意
:^关键字 ##以关键字开头
关键字$
##以关键字结尾
###3.cut
cut ##
截取字符
cut -d 分隔符 ##指定分隔符
cut -f 1,7
##显示指定的列
cyt -c 1-4 ##显示指定
的字符
只显示ifconfig eth0中的ip地址
[root@localhost ~]# ifconfig
eth0 | grep inet | grep inet6 -v | cut -d " " -f 10
[root@localhost
~]# ifconfig eth0 | grep inet | grep inet6 -v | awk -F " " '{print
$2}'
###4.sort
sort ##排序
sort -n
##纯数字排序
sort -u ##
去冗余(去除重复的)
sort |uniq -c ##去除冗余并统计冗
余次数
sort -t ##指定分隔符
sort -k
##指定列
###5.uniq
sort file | uniq -c ##
去掉冗余并统计冗余的次数
sort file | uniq -d ##显示冗余
行
sort file | uniq -u ##显示唯一行
###6.sed
sed 's/原字符/
替换字符/g' file
sed -e '策略1' -e '策略2' file
sed -i file
##把转换后的内容输入到指定文件
sed '3,5s/原字符/替换字符/g'
file ##3—5行替换
sed xd ##屏蔽指定行
sed xp
##复制指定行
sed -n xp ##
只显示指定行
sed -f 策略文件 file ##表示指定策略文件
###脚本
userfile
westos1
westos2
westos3
passwdfile
redhat1
redhat2
redhat3
user_create.sh
#!/bin/bash
MAX=$( wc -l $1 | cut -d " " -f 1 )
for NUM
in $( seq 1 $MAX )
do
USERNAME=$( sed -n ${NUM}p $1)
PASSWD=$( sed -n ${NUM}p $2)
useradd $USERNAME
echo
$PASSWD | passwd --stdin $USERNAME
done
测试
[root@desktop18 mnt]# sh
user_create.sh userfile passwdfile
Changing password for user
westos1.
passwd: all authentication tokens updated successfully.
Changing password for user westos2.
passwd: all authentication
tokens updated successfully.
Changing password for user westos3.
passwd: all authentication tokens updated successfully.
###tr
[root@desktop2 mnt]# cat file
a
a
a
a
a
[root@desktop2 mnt]# tr 'a-z'
'A-Z' < file
A
A
A
A
A
[root@desktop2 mnt]# tr 'a' 'Z' < file
Z
Z
Z
Z
Z
0 0
- 2 unit 6
- unit 6
- unit 6
- unit 6
- Unit 6
- unit 2
- Unit 2
- unit 2
- unit 4-6 作业
- unit 4-6笔记
- [ Vocabulary Building ]Unit 2
- Unit 命令2
- unit 2 page56 E4
- Unit 2: Pronouns
- Unit 2: Adjectives
- Unit 2: Verbs
- Unit 2: Adverbs
- Unit 2: Prepositions
- pv lv vg代表的意义
- 产品三部互联网工程系OA系统项目功能SQL功能总结文档
- linux grep命令
- @synchronized()的用法
- UML之类图
- 2 unit 6
- 正则表达式验证
- 自定义多选 dialog
- 分页标签中totalCountExp的几种用法
- OverFeat:Integrated Recognition, Localization and Detection using Convolutional Networks
- STL string 析构异常原因分析
- javascript编程笔记
- Python学习之Django(2)
- MAC OS X下配置PHP开发、调试环境