c语言 文件操作 find,十九、文本操作——文件查找find

文件查找命令find

find 路径 查找条件[补充条件]

在目录当中找到指定的文件

(1)知道文件的完整名称,进行查找

user1@SC02ZRC4KMD6N /etc % find passwd

passwd

(2) 查找某路径以及子路径是否包含文件

user1@SC02ZRC4KMD6N / % find etc/ -name passwd

etc//pam.d/passwd

etc//passwd

(3)使用通配符进行模糊匹配

user1@SC02ZRC4KMD6N / % find etc/ -name pass*

(4)使用正则表达式进行模糊匹配

user1@SC02ZRC4KMD6N / % find etc/ -regex .*wd

(5)查找指定的文件类型

user1@SC02ZRC4KMD6N / % find etc/ -type f -regex .*wd

(6)按照时间来查找文件

user1@SC02ZRC4KMD6N / % find etc/ -ctime xx

user1@SC02ZRC4KMD6N / % stat test.txt

File: 'test.txt'

Size: 42 Blocks: 8 IO Block: 4096 regular file

Device: 804h/2052d Inode: 59158038 Links: 1

Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)

Access: 2020-04-06 12:53:33.659773937 +0800

Modify: 2020-04-06 12:53:28.651706463 +0800

Change: 2020-04-06 12:53:28.651706463 +0800

Birth: -

atime指文件的访问时间,ctime文件的i节点时间,mtime指文件内容发生变化的时间

(7)查找文件,删除文件

user1@SC02ZRC4KMD6N tmp % touch {1..9}.txt

user1@SC02ZRC4KMD6N tmp % ls -l

total 0

-rw-r--r-- 1 user1 staff 0 4 6 15:11 1.txt

-rw-r--r-- 1 user1 staff 0 4 6 15:11 2.txt

-rw-r--r-- 1 user1 staff 0 4 6 15:11 3.txt

-rw-r--r-- 1 user1 staff 0 4 6 15:11 4.txt

-rw-r--r-- 1 user1 staff 0 4 6 15:11 5.txt

-rw-r--r-- 1 user1 staff 0 4 6 15:11 6.txt

-rw-r--r-- 1 user1 staff 0 4 6 15:11 7.txt

-rw-r--r-- 1 user1 staff 0 4 6 15:11 8.txt

-rw-r--r-- 1 user1 staff 0 4 6 15:11 9.txt

user1@SC02ZRC4KMD6N tmp % find *txt -exec rm -v {} \;

1.txt

2.txt

3.txt

4.txt

5.txt

6.txt

7.txt

8.txt

9.txt

user1@SC02ZRC4KMD6N tmp % ls -l

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值