1

使用 linux 上的 bash,我将如何编写一个命令来递归遍历挂载的共享,并在每个文件上运行命令,以获取文件类型和大小、权限等,然后将所有这些输出到文件中?

4

4 回答 4

1

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

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

好的,这不会为您提供文件类型的详细信息;
这可以-exec file filename在每个文件上使用 a 来完成。

于 2009-07-22T04:21:31.867 回答
0
mount -v | awk '/smbfs/{
    cmd="ls -lsR "$3
    while((cmd | getline d)>0){
        print d "->file "$3
    }   
    close(cmd)
}'
于 2009-07-22T05:48:49.743 回答
0
mount -v | grep smbfs | awk '{print $3}' | xargs ls -lsR

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

于 2009-07-22T05:33:07.607 回答
0
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 {} +,它将使用多个参数运行文件一次,但输出不会与 find 的-ls输出很好地交错。(GNU find 的-execdir {} +当前行为与 相同-execdir {} \;,由于错误解决方法-exec file {} \;如果您希望输出中的完整路径file以及其-ls上方的输出中的完整路径,请使用。

find -ls输出与 不完全相同ls -l,因为它包含 inode 多个块作为前两个字段。

于 2009-12-09T20:47:10.533 回答