十九 文本操作——文件查找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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Linux系统中的 find 命令在查找文件时非常有用而且方便。它可以根据不同的条件来查找文件,例如权限、拥有者、...
    piziyang12138阅读 3,474评论 0 0
  • Linux系统中的 find 命令在查找文件时非常有用而且方便。它可以根据不同的条件来查找文件,例如权限、拥有者、...
    Arroganter阅读 1,522评论 0 0
  • Linux find命令用来在指定目录下查找文件。find命令功能强大,选项比较多,能够记住的选项就那么几个,正好...
    dshowing阅读 3,909评论 0 0
  • Linux系统中的 find 命令在查找文件时非常有用而且方便。它可以根据不同的条件来查找文件,例如权限、拥有者、...
    数据萌新阅读 3,582评论 0 2
  • Linux系统中的 find 命令在查找文件时非常有用而且方便。它可以根据不同的条件来查找文件,例如权限、拥有者、...
    小猪Harry阅读 3,982评论 0 1

友情链接更多精彩内容