递归遍历Samba共享?
使用Linux上的bash,我将如何编写一个命令来递归地遍历安装的共享,并对每个文件运行命令,以获取文件类型和大小、权限等,然后将所有这些输出到文件中?
With bash on linux, how would I write a command to recursively traverse shares mounted, and run commands on each file, to get the file type and size, permissions etc, and then output all of this to a file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
CIFS 共享挂载看起来像 Linux shell 中的常规目录树。
因此,根据需要进行搜索的命令是通用的。
从基本目录,
好吧,这不会为您提供文件类型详细信息;
这可以通过每个文件上的
-exec file filename
来完成。A CIFS share mount would look like a regular directory tree in the linux shell.
The command to search as you need is therefore generic.
From the base directory,
Ok, this does not give you the file-type detail;
that can be done with a
-exec file filename
on each file.您可以将其重定向到文件。
which you can redirect to a file.
如果您使用 -exec file {} +,它将使用多个参数运行 file 一次,但输出不会与 find 的
-ls
输出很好地交错。 (GNU find 的-execdir {} +
当前的行为与-execdir {} \;
相同,因为 错误解决方法。如果您想要文件中的完整路径
,请使用-exec file {} \;
code> 输出以及上面的-ls
输出与ls -l
输出并不完全相同,因为。它包括 inode 和许多块作为前两个字段。If you used -exec file {} +, it would run file once with multiple arguments, but then the output wouldn't be nicely interleaved with find's
-ls
output. (GNU find's-execdir {} +
currently behaves the same as-execdir {} \;
, due to a bug workaround. Use-exec file {} \;
if you want the full path in thefile
output as well as in the-ls
output above it.find -ls
output is not quite the same asls -l
, since it includes inode an number of blocks as the first two fields.