是否可以运行 ls 或通过 stat 查找和管道它?

let*_*tda 7 ls bash find stat

有没有办法运行 ls 或 find 来获取目录中的文件列表,然后运行 ​​stat 来获取所有特定信息(即文件组、文件名、文件所有者、文件大小(以 K、M 等显示) .) & Permissions? 我正在尝试以下方面的内容:

find .content/media -type f | stat
ls -l .content/media | stat
Run Code Online (Sandbox Code Playgroud)

回答:

    find ./content/"subdirectory name"/ -type f -exec stat -c '%n : %U : %A : %G : %s' {} +
Run Code Online (Sandbox Code Playgroud)

hee*_*ayl 13

用于stat以下-exec动作find

find .content/media/ -type f -exec stat -c '%n : %U : %G : %s' {} +
Run Code Online (Sandbox Code Playgroud)

更改格式序列stat以满足您的需要。

  • @lettda `-exec` 是 `find` 的一个动作..你可以用它来运行一些其他程序来处理 `find` 的结果 ..check `man find` (2认同)

jor*_*anm 12

如果你有 GNU find,你可以使用-printf

find content/media/ -type f -printf '%p : %u : %g : %k'
Run Code Online (Sandbox Code Playgroud)


Hen*_*ity 6

xargs混进去。例如:

ls | xargs stat
Run Code Online (Sandbox Code Playgroud)

  • 要处理换行符或空格,您可以使用:`find -print0 | xargs -0 统计`。 (3认同)