测试技术学习分享软件测试技术干货

软件测试:三分钟掌握Linux命令之find&g

2018-01-29  本文已影响64人  爱学技术的小仙女酱

目录

1.文件和目录操作命令

2.用户和用户组操作命令

3.vim编辑器操作命令

4.打包和解压操作命令

5.系统操作命令

这是总的目录的,软件测试人员需要掌握的Linux命令会分成多个章节来写。

find ---文件搜索

格式:find [搜索范围][匹配条件]

find命令

1.根据name来搜索(经常用)

a.精确搜索

[root@localhost test]# find /etc -name services

b.模糊搜索init开头的文件和目录

[root@localhost test]# find /etc -name init*

c.模糊搜索init结尾的文件和目录

[root@localhost test]# find /etc -name *init

d.模糊搜索包含init的文件和目录

[root@localhost test]# find /etc -name *init*

e.模糊搜索以init开头的后面只有三个字符串的文件或目录

* 代表一组字符串

? 代表一个字符

[root@localhost test]# find /etc -name init???

linux对大小很敏感,而且空格也敏感

[root@localhost test]# find /etc -name INIT???

f.根据name搜索时,不区分大小写用选项 -iname

[root@localhost test]# find /etc -iname INIT???

/etc/inittab

[root@localhost test]# find /etc -name INIT???

没有搜索出任何数据

find命令不区分大小写

2.根据文件大小搜索

a.大于4096的文件 +4096

[root@localhost test]# find /etc -size +4096

b.小于4096的文件 -4096

[root@localhost test]# find /etc -size -4096

c.等于4096的文件

[root@localhost test]# find /etc -size 4096

d.大于4096同时小于641020的文件 -a

[root@localhost test]# find /etc -size +4096 -a -size -641020

e.大于4096或者小于641020的文件

[root@localhost test]# find /etc -size +4096 -o -size -641020

3.根据文件所有者去搜索

[root@localhost test]# find /home/test -user test

[root@localhost test]# find -user test

如果不写搜索范围,默认搜索从当前目录开始,搜索下面匹配的文件和目录

4.根据文件属性搜索

a.搜索5分钟之内内容被修改的文件

[root@localhost test]# find . -mmin -5

文件内容被修改的同时,文件属性也会被修改

b.搜索3分钟之内文件属性被修改的文件

[root@localhost test]# find . -cmin -3

amin cmin mmin后面接分钟

atime ctime mtime后面接小时

5.根据文件类型来搜索

- 二进制文件f d 目录 l 软链接

1.搜索目录---文件类型为d

[root@localhost test]# find . -type d

2.搜索当前目录下文件类型为文件 f

[root@localhost test]# find . -type - ---错误

find: -type 的参数未知: -

[root@localhost test]# find . -type f ---正确

3.搜索当前目录下的文件类型为软链接 l

[root@localhost test]# find . -type l

4.在根目录下搜索文件名称为services的文件

[root@localhost test]# find / -name services -type f

grep --搜索文件的内容

1.搜索test.log这个文件中包含qwer字符串的行

[root@localhost test]# grep qwer ./test.log

2.不区分大小写进行搜索 选项 -i

[root@localhost test]# grep -i test test.log

3.搜索不包含123的文件内容

[root@localhost test]# grep -v 123 test.log

4.搜索不包含test的文件内容,不区分大小写

[root@localhost test]# grep -iv test test.log

5.搜索不是以1开头的文件内容

[root@localhost test]# grep -v ^1 test.log

6.搜索以1开头的行

[root@localhost test]# grep ^1 test.log

^ 表示以什么开头

在shell脚本 #表示注释

7.屏蔽掉注释行 --

[root@localhost test]# grep -v ^# sysctl.conf

8.经常使用的一种方法---管道 |

[root@localhost test]# ps -ef |grep java

ps -ef 查询进程

|管道符 command1 | command2

将command1的输出作为command2的输入

[root@localhost test]# ls -l |grep test

ln --链接命令

链接分为软链接和硬链接

1.给目录创建软链接 -s

[root@localhost tmp]# ln -s /tmp/test/test12/test ./test1

lrwxrwxrwx. 1 root root 21 Apr 14 21:06 test1 -> /tmp/test/test12/test

软链接的大小非常小,只是一个链接

软链接相当于windows下面的快捷方式

2.给文件创建软链接

[root@localhost tmp]# ln -s /tmp/test/test12/test/tw.log .

软链接的目标文件和原文件的i节点不同

3.给文件创建一个硬链接

[root@localhost tmp]# ln /tmp/test/test12/test/tw.log ./tw1.log

硬链接的i节点相同

[root@localhost tmp]# ln /tmp/test/test12/test ./test_dir

ln: `/tmp/test/test12/test': hard link not allowed for directory'

硬链接不能针对目录使用,只能对文件使用

find命令和grep命令是软件测试人员经常使用的命令,一定要多练习。

软件测试技术交流群:

上一篇下一篇

猜你喜欢

热点阅读