搜索整个文件树终端

时间:2014-08-07 09:32:23

标签: macos bash shell terminal

我不完全确定如何说出问题但是我想在终端中传递一个文件参数来搜索目录,并且每个可能的子目录都在整个文件树中运行。目前,我正在通过~/Classes/**/*,但我不确定它是否正常工作

2 个答案:

答案 0 :(得分:0)

使用find -type d

find ~Classes -type d

如果~代表主目录,则必须在其上添加额外的斜杠(/)。

find ~/Classes -type d

如果使用bash,则需要启用globstar并将/添加到目标目录:

shopt -s globstar
printf '%s\n' ~/Classes/**/*/

答案 1 :(得分:0)

如果你想运行它:

java -jar ~/Downloads/simian-2.3.35/bin/simian-2.3.35.jar files ~/Classes/**/*

你可以这样做:

java -jar ~/Downloads/simian-2.3.35/bin/simian-2.3.35.jar files $(find ....)

原始答案

基本上使用find命令:

find ~/Classes -type f  # find, starting in your "Classes" directory, all files

find ~ -type f  # find, starting in your HOME directory, all files

find ~ -type d  # find, starting in your HOME directory, all directories

find ~ -name "*fred*" -type f # find all files whose name contains "fred" anywhere in them

find ~ -iname "*FRED*" -type f # find all files whose name contains "fred" or "FRED" or "Fred"  anywhere in them