ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
find - 查找文件的复杂方式 locate 程序只能依据文件名来查找文件,而 find 程序能基于各种各样的属性, 搜索一个给定目录(以及它的子目录),来查找文件。我们将要花费大量的时间学习 find 命令,因为 它有许多有趣的特性,当我们开始在随后的章节里面讨论编程概念的时候,我们将会重复看到这些特性。 find 命令的最简单使用是,搜索一个或多个目录。例如,输出我们的家目录列表。 [me@linuxbox ~]$ find ~ 对于最活跃的用户帐号,这将产生一张很大的列表。因为这张列表被发送到标准输出, 我们可以把这个列表管道到其它的程序中。让我们使用 wc 程序来计算出文件的数量: [me@linuxbox ~]$ find ~ | wc -l xargs 这个 xargs 命令会执行一个有趣的函数。它从标准输入接受输入,并把输入转换为一个特定命令的 参数列表。对于我们的例子,我们可以这样使用它: [root@localhost www.qq.com]# find ./ -type f -name '*.txt' -print|xargs ls -l -rw-r--r--. 1 root root 2192309 Jan 25 18:00 ./a.txt -rw-r--r--. 1 root root 8 Jan 22 21:53 ./b.txt -rw-r--r--. 1 root root 1480 Jan 25 00:14 ./cat.txt -rw-r--r--. 1 root root 112 Jan 24 23:42 ./c.txt -rwxrwxr-x. 1 gjw gjw 60 Dec 19 00:30 ./hash.txt [root@localhost www.qq.com]# !1049 find ./ -type f -name '*.txt' -print ./b.txt ./c.txt ./a.txt ./hash.txt ./cat.txt