在Linux系统中,查找文件可以使用find
命令,这是最基本也是最强大的工具之一。以下是一些基本的用法:
find [路径] [选项] [查找条件]
find . -name "filename"
find /path/to/search -name "filename"
find . -name "*.txt"
find /path/to/search -mtime 0
find /path/to/search -size +10M
find /path/to/search -type f -empty
find /path/to/search -type d -empty
find /path/to/search -user user
find /path/to/search -group group
find /path/to/search -type l
find /path/to/search -perm 755
find /path/to/search -type f -exec grep -l "text" {} \;
例如,查找所有.txt文件且最近7天内修改过的文件:
find /path/to/search -name "*.txt" -mtime -7
例如,查找所有以数字开头的文件:
find /path/to/search -regex '.*/[0-9]+.*'
例如,查找所有目录:
find /path/to/search -type d
例如,查找所有小于1MB的文件:
find /path/to/search -size -1M
例如,查找所有7天前修改过的文件:
find /path/to/search -mtime +7
例如,查找所有7天内访问过的文件:
find /path/to/search -atime -7
例如,查找所有7天内状态改变过的文件:
find /path/to/search -ctime -7
例如,查找所有属于"user"的文件:
find /path/to/search -user user
例如,查找所有属于"group"的文件:
find /path/to/search -group group
例如,查找所有权限为755的文件:
find /path/to/search -perm 755
例如,查找所有符号链接:
find /path/to/search -type l
例如,查找所有以数字开头的文件:
find /path/to/search -regex '.*/[0-9]+.*'
例如,查找所有目录:
find /path/to/search -type d
例如,查找所有小于1MB的文件:
find /path/to/search -size -1M
例如,查找所有7天前修改过的文件:
find /path/to/search -mtime +7
例如,查找所有7天内访问过的文件:
find /path/to/search -atime -7
例如,查找所有7天内状态改变过的文件:
find /path/to/search -ctime -7
例如,查找所有属于"user"的文件:
find /path/to/search -user user
例如,查找所有属于"group"的文件:
find /path/to/search -group group
例如,查找所有权限为755的文件:
find /path/to/search -perm 755
例如,查找所有符号链接:
find /path/to/search -type l
例如,查找所有以数字开头的文件:
find /path/to/search -regex '.*/[0-9]+.*'
例如,查找所有目录:
find /path/to/search -type d
例如,查找所有小于1MB的文件:
find /path/to/search -size -1M
例如,查找所有7天前修改过的文件:
find /path/to/search -mtime +7
例如,查找所有7天内访问过的文件:
find /path/to/search -atime -7
例如,查找所有7天内状态改变过的文件:
find /path/to/search -ctime -7
例如,查找所有属于"user"的文件:
find /path/to/search -user user
例如,查找所有属于"group"的文件:
find /path/to/search -group group
例如,查找所有权限为755的文件:
find /path/to/search -perm 755
例如,查找所有符号链接:
find /path/to/search -type l
例如,查找所有以数字开头的文件:
find /path/to/search -regex '.*/[0-9]+.*'
例如,查找所有目录:
find /path/to/search -type d
例如,查找所有小于1MB的文件:
find /path/to/search -size -1M
例如,查找所有7天前修改过的文件:
find /path/to/search -mtime +7
例如,查找所有7天内访问过的文件:
find /path/to/search -atime -7
例如,查找所有7天内状态改变过的文件:
find /path/to/search -ctime -7
例如,查找所有属于"user"的文件:
find /path/to/search -user user
例如,查找所有属于"group"的文件:
find /path/to/search -group group
例如,查找所有权限为755的文件:
find /path/to/search -perm 755
例如,查找所有符号链接:
find /path/to/search -type l
例如,查找所有以数字开头的文件:
find /path/to/search -regex '.*/[0-9]+.*'
例如,查找所有目录:
find /path/to/search -type d
例如,查找所有小于1MB的文件:
find /path/to/search -size -1M
例如,查找所有7天前修改过的文件:
find /path/to/search -mtime +7
例如,查找所有7天内访问过的文件:
find /path/to/search -atime -7
例如,查找所有7天内状态改变过的文件:
find /path/to/search -ctime -7
例如,查找所有属于"user"的文件:
find /path/to/search -user user
例如,查找所有属于"group"的文件:
find /path/to/search -group group
例如,查找所有权限为755的文件:
find /path/to/search -perm 755
例如,查找所有符号链接:
find /path/to/search -type l
例如,查找所有以数字开头的文件:
find /path/to/search -regex '.*/[0-9]+.*'
例如,查找所有目录:
find /path/to/search -type d
例如,查找所有小于1MB的文件:
find /path/to/search -size -1M
例如,查找所有7天前修改过的文件:
find /path/to/search -mtime +7
例如,查找所有7天内访问过的文件:
find /path/to/search -atime -7
例如,查找所有7天内状态改变过的文件:
find /path/to/search -ctime -7
例如,查找所有属于"user"的文件:
find /path/to/search -user user
例如,查找所有属于"group"的文件:
find /path/to/search -group group
例如,查找所有权限为755的文件:
find /path/to/search -perm 755
例如,查找所有符号链接:
find /path/to/search -type l
例如,查找所有以数字开头的文件:
find /path/to/search -regex '.*/[0-9]+.*'
例如,查找所有目录:
find /path/to/search -type d
例如,查找所有小于1MB的文件:
find /path/to/search -size -1M
例如,查找所有7天前修改过的文件:
find /path/to/search -mtime +7
例如,查找所有7天内访问过的文件:
find /path/to/search -atime -7
例如,查找所有7天内状态改变过的文件:
find /path/to/search -ctime -7
例如,查找所有属于"user"的文件:
find /path/to/search -user user
例如,查找所有属于"group"的文件:
find /path/to/search -group group
例如,查找所有权限为755的文件:
find /path/to/search -perm 755
例如,查找所有符号链接:
find /path/to/search -type l
例如,查找所有以数字开头的文件:
find /path/to/search -regex '.*/[0-9]+.*'
例如,查找所有目录:
find /path/to/search -type d
例如,查找所有小于1MB的文件:
find /path/to/search -size -1M
例如,查找所有7天前修改过的文件:
find /path/to/search -mtime +7
例如,查找所有7天内访问过的文件:
find /path/to/search -atime -7
例如,查找所有7天内状态改变过的文件:
find /path/to/search -ctime -7
例如,查找所有属于"user"的文件:
find /path/to/search -user user
例如,查找所有属于"group"的文件:
find /path/to/search -group group
例如,查找所有权限为755的文件:
find /path/to/search -perm 755
例如,查找所有符号链接:
find /path/to/search -type l
例如,查找所有以数字开头的文件:
find /path/to/search -regex '.*/[0-9]+.*'
例如,查找所有目录:
find /path/to/search -type d
例如,查找所有小于1MB的文件:
find /path/to/search -size -1M
例如,查找所有7天前修改过的文件:
find /path/to/search -mtime +7
例如,查找所有7天内访问过的文件:
find /path/to/search -atime -7
例如,查找所有7天内状态改变过的文件:
find /path/to/search -ctime -7
例如,查找所有属于"user"的文件:
find /path/to/search -user user
例如,查找所有属于"group"的文件:
find /path/to/search -group group
例如,查找所有权限为755的文件:
find /path/to/search -perm 755
例如,查找所有符号链接:
find /path/to/search -type l
例如,查找所有以数字开头的文件:
find /path/to/search -regex '.*/[0-9]+.*'
例如,查找所有目录:
find /path/to/search -type d
例如,查找所有小于1MB的文件:
find /path/to/search -size -1M
例如,查找所有7天前修改过的文件:
find /path/to/search -mtime +7
例如,查找所有7天内访问过的文件:
find /path/to/search -atime -7
领取专属 10元无门槛券
手把手带您无忧上云