递归遍历Samba共享?

发布于 2024-07-27 20:04:54 字数 83 浏览 5 评论 0原文

使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

叫嚣ゝ 2024-08-03 20:04:54

CIFS 共享挂载看起来像 Linux shell 中的常规目录树。
因此,根据需要进行搜索的命令是通用的。
从基本目录,

find . -type f -exec ls -lsrt {} \; > file.txt

好吧,这不会为您提供文件类型详细信息;
这可以通过每个文件上的 -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,

find . -type f -exec ls -lsrt {} \; > file.txt

Ok, this does not give you the file-type detail;
that can be done with a -exec file filename on each file.

笨笨の傻瓜 2024-08-03 20:04:54
mount -v | grep smbfs | awk '{print $3}' | xargs ls -lsR

您可以将其重定向到文件。

mount -v | grep smbfs | awk '{print $3}' | xargs ls -lsR

which you can redirect to a file.

风为裳 2024-08-03 20:04:54
mount -v | awk '/smbfs/{
    cmd="ls -lsR "$3
    while((cmd | getline d)>0){
        print d "->file "$3
    }   
    close(cmd)
}'
mount -v | awk '/smbfs/{
    cmd="ls -lsR "$3
    while((cmd | getline d)>0){
        print d "->file "$3
    }   
    close(cmd)
}'
兮颜 2024-08-03 20:04:54
find $(mount -t smbfs | awk '{print $3}') -mount -type f -ls -execdir file {} \;
...
33597911    4 -rw-rw-r--   2 peter    peter           5 Dec  6 00:09 ./test.d\ ir/base
./base: ASCII text
  3662    4 -rw-rw-r--   2 peter    peter           4 Dec  6 02:26 ./test.txt...
./test.txt...: ASCII text
  3661    0 -rw-rw-r--   2 peter    peter           0 Dec  6 02:45 ./foo.txt
./foo.txt: empty
...

如果您使用 -exec file {} +,它将使用多个参数运行 file 一次,但输出不会与 find 的 -ls 输出很好地交错。 (GNU find 的 -execdir {} + 当前的行为与 -execdir {} \; 相同,因为 错误解决方法。如果您想要文件中的完整路径,请使用-exec file {} \; code> 输出以及上面的 -ls 输出与

ls -l 输出并不完全相同,因为。它包括 inode 和许多块作为前两个字段。

find $(mount -t smbfs | awk '{print $3}') -mount -type f -ls -execdir file {} \;
...
33597911    4 -rw-rw-r--   2 peter    peter           5 Dec  6 00:09 ./test.d\ ir/base
./base: ASCII text
  3662    4 -rw-rw-r--   2 peter    peter           4 Dec  6 02:26 ./test.txt...
./test.txt...: ASCII text
  3661    0 -rw-rw-r--   2 peter    peter           0 Dec  6 02:45 ./foo.txt
./foo.txt: empty
...

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 the file output as well as in the -ls output above it.

find -ls output is not quite the same as ls -l, since it includes inode an number of blocks as the first two fields.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文