15个实用的Linux find命令示例(2)

你可以在你想对那些像上面一样的糟糕命名的文件做某些操作时使用这一技术。例如,名为file?.txt的文件名字中有一个特殊字符。若你想执行“rm file?.txt”,下面所示的所有三个文件都会被删除。所以,采用下面的步骤来删除"file?.txt"文件。

ls

file1.txt file2.txt file?.txt

找到每一个文件的inode编号。

ls -i1

804178 file1.txt

804179 file2.txt

804180 file?.txt

如下所示: 使用inode编号来删除那些具有特殊符号的文件名。

find -inum 804180 -exec rm {} \;

# ls

file1.txt file2.txt

[Note: The file with name "file?.txt" is now removed]

7. 根据文件权限查找文件

下面的操作时合理的:

找到具有指定权限的文件

忽略其他权限位,检查是否和指定权限匹配

根据给定的八进制/符号表达的权限搜索

此例中,假设目录包含以下文件。注意这些文件的权限不同。

ls -l

total 0

-rwxrwxrwx 1 root root 0 2009-02-19 20:31 all_for_all

-rw-r--r-- 1 root root 0 2009-02-19 20:30 everybody_read

---------- 1 root root 0 2009-02-19 20:31 no_for_all

-rw------- 1 root root 0 2009-02-19 20:29 ordinary_file

-rw-r----- 1 root root 0 2009-02-19 20:27 others_can_also_read

----r----- 1 root root 0 2009-02-19 20:27 others_can_only_read

找到具有组读权限的文件。使用下面的命令来找到当前目录下对同组用户具有读权限的文件,忽略该文件的其他权限。

find . -perm -g=r -type f -exec ls -l {} \;

-rw-r--r-- 1 root root 0 2009-02-19 20:30 ./everybody_read

-rwxrwxrwx 1 root root 0 2009-02-19 20:31 ./all_for_all

----r----- 1 root root 0 2009-02-19 20:27 ./others_can_only_read

-rw-r----- 1 root root 0 2009-02-19 20:27 ./others_can_also_read

找到对组用户具有只读权限的文件。

find . -perm g=r -type f -exec ls -l {} \;

----r----- 1 root root 0 2009-02-19 20:27 ./others_can_only_read

找到对组用户具有只读权限的文件(使用八进制权限形式)。

find . -perm 040 -type f -exec ls -l {} \;

----r----- 1 root root 0 2009-02-19 20:27 ./others_can_only_read

8. 找到home目录及子目录下所有的空文件(0字节文件)

下面命令的输出文件绝大多数都是锁定文件盒其他程序创建的place hoders

find ~ -empty

只列出你home目录里的空文件。

find . -maxdepth 1 -empty

只列出当年目录下的非隐藏空文件。

find . -maxdepth 1 -empty -not -name ".*"

相关阅读

Linux中强大且常用命令:find、grep 

Linux系统文件查找命令find的基本使用及其高级用法

Linux运维利器--find命令

Linux中find常见用法示例

Linux find 命令详解

Linux学习---find命令使用技巧

find的基本使用命令

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/19183.html