linux寻找所有的A前缀的文件夹

linux寻找所有的A*前缀的文件夹

linux打印出来所有以AAAA为开头的文件夹路径

参考资料

https://blog.csdn.net/m0_37568814/article/details/82753281

find ./ -type d -name 'AAA'    

含义是在./文件夹汇总,打印出来文件夹名中包含AAA的所有文件夹路径

参考资料:

https://blog.csdn.net/qq_35246620/article/details/79104520

image-20221009220800645

-type c : 文件类型是 c 的文件。

d: 目录

c: 字型装置文件

b: 区块装置文件

p: 具名贮列

f: 一般文件

l: 符号连结

s: socket


find /(查找范围) -type d -name 'A*'

含义是在./文件夹汇总,打印出来文件夹名字中包含AAA的所有文件夹路径


find /tmp/cg/testLinux -name "*.txt"

在/testLinux目录下查找以.txt结尾的文件名


/**
 * 组合查找语法:
 * -a        与(取交集)
 * -o        或(取并集)
 * -not      非(同 !)
 * !         非(同 not)
 */

find . -name "file1*" -a -name "file2*"
find . -name "file1*" -o -name "file2*"
find . -name "file1*" -not -name "file2*"
find . -name "file1*" ! -name "file2*"

组合查找文件名以file1开头(与、或、非)file2开头的文件


/**
 * 查找当前目录及所有子目录下的普通文件
 */

find . -type f

根据文件类型进行搜索


/**
 * 限制最大深度为 3
 */

find . -maxdepth 3 -type f

/**
 * 限制最大深度为 2
 */

find . -maxdepth 2 -type f

基于目录深度进行搜索


/**
 * 搜索权限为 777 的文件
 */

find . -type f -perm 777

/**
 * 搜索 .txt 格式且权限不为 777 的文件
 */

find . -type f -name "*.txt" ! -perm 777

基于文件权限进行搜索


find . -type f -name "*.txt" -exec printf "File: %s\n" {} \;

借助-exec命令,将当前目录及子目录下所有.txt格式的文件以File:文件名的形式打印出来


find . -type f -mtime +3 -name "*.txt" -exec cp {} old \;

借助-exec命令,将当前目录及子目录下所有 3 天前的.txt格式的文件复制一份到old目录

posted @ 2022-10-11 16:10  bH1pJ  阅读(361)  评论(0编辑  收藏  举报