我想获取具有权限的文件名列表以及目录名。
ls -ltrR <folder name>| egrep -v '\.:|total'| sed '/^$d'
命令获取列表。但我得到的输出为:
<folder name>:
permison filename 1
permission filename 2
<folder name>:
<folder name>:
permission filename1
permission filename2
我想将其添加<folder name>
到文件名中,如下所示。
<folder name> permission filename 1
<folder name> permission filename 2
<folder name>
<folder name> permission filename1
<folder name> permission filename2
答案1
如果你有 GNU find
(至少有 findutils >= 4.2.5),你应该能够做类似的事情
find path/to/folder -type f -printf '%h %M %f\n'
从man find
:
%h Leading directories of file's name (all but the last ele‐
ment). If the file name contains no slashes (since it is
in the current directory) the %h specifier expands to
".".
%M File's permissions (in symbolic form, as for ls). This
directive is supported in findutils 4.2.5 and later.
%f File's name with any leading directories removed (only
the last element).