相关疑难解决方法(0)

如果命令 find -exec

我只是想列出当前目录下的所有目录和文件,并使用以下命令写入文件或目录:

find -exec echo `echo {} : ;if [ -f {} ]; then echo file; else echo directory;fi` \;
Run Code Online (Sandbox Code Playgroud)

我知道这是一个愚蠢的命令,我可以使用其他东西,例如-type for -type d,但我想了解为什么那段代码没有按我预期的那样工作。它只是将目录打印到所有这些。例如 while 的输出find是:

.
./dir
./dir/file
Run Code Online (Sandbox Code Playgroud)

我的代码的输出是:

. : directory
./dir : directory
./dir/file : directory
Run Code Online (Sandbox Code Playgroud)

和输出

echo `echo dir/file : ;if [ -f dir/file ]; then echo file; else echo directory;fi`
Run Code Online (Sandbox Code Playgroud)

dir/file : file
Run Code Online (Sandbox Code Playgroud)

我正在研究Ubuntu 14.10和使用find (GNU findutils) 4.4.2

shell bash find command-substitution

12
推荐指数
2
解决办法
2万
查看次数

标签 统计

bash ×1

command-substitution ×1

find ×1

shell ×1