Bash:如何对具有特定扩展名的文件使用 'find',但它也会给出其先前的目录
Bash: How to use 'find' for a file with specific extension but that it would also give its previous directory
我被一段代码困住了,我必须使用 'find' 来定位所有具有特定扩展名的文件,但输出也会给出特定文件所在的特定目录.
例如:
find . -name "*.exe" -o -name "*.bat" -type f
我使用此代码查找扩展名为 .exe
和 .bat
的所有文件,它给我的输出是:
./test/test1/test2/hello.exe
我的问题是命令是否可能只给我这样的输出:
test2/hello.exe
仅在文件所在的目录中。
非常感谢!
试试这个:
find . -name "*.exe" -o -name "*.bat" -type f | grep -Po '[^/]*?/[^/]+$'
我被一段代码困住了,我必须使用 'find' 来定位所有具有特定扩展名的文件,但输出也会给出特定文件所在的特定目录. 例如:
find . -name "*.exe" -o -name "*.bat" -type f
我使用此代码查找扩展名为 .exe
和 .bat
的所有文件,它给我的输出是:
./test/test1/test2/hello.exe
我的问题是命令是否可能只给我这样的输出:
test2/hello.exe
仅在文件所在的目录中。
非常感谢!
试试这个:
find . -name "*.exe" -o -name "*.bat" -type f | grep -Po '[^/]*?/[^/]+$'