有没有办法用 ls + 获取路径/到/文件awk、sed、grep 或类似的工具?
我想递归地搜索一个目录,并输出:
文件名 日期 路径大小
我得到了除了路径之外的所有内容...这是一个 $$$$buster....
到目前为止,这是我的命令:
ls -lThR {DIRECTORY_NAME_HERE} | awk '/^-/ {print $10 " " $6 " " $7 " " $8 " " $5}'
我希望有一种方法将该命令与: 结合使用:
find ./{DIRECTORY_NAME_HERE} -type f
它只显示 /path/to/filename 本身...没有其他元数据据我所知。
有什么想法......希望不需要编程语言吗?
编辑:假设文件为 5 个字节,这是我正在寻找的确切输出:
myfile.txt Dec 2 10:58 /path 5
更新:这是我最终使用的命令:
find ./{DIRECTORY_NAME_HERE} -type f -ls |
while read f1 blocks perms blocks owner group size mon day third file;
do echo `basename $file` `ls -lrt $file | tr -s " " | cut -d" " -f6-8` `dirname $file` `ls -lrt $file | tr -s " " | cut -d" " -f-5`; done
如果有人可以改进它,那就太好了,但这可行......
I'd like to recursively search a directory, and output:
Filename Date Path Size
I got everything but Path...which is a $$$$buster....
Here's my command so far:
ls -lThR {DIRECTORY_NAME_HERE} | awk '/^-/ {print $10 " " $6 " " $7 " " $8 " " $5}'
I wish there was a way to combine that command with:
find ./{DIRECTORY_NAME_HERE} -type f
which just shows /path/to/filename itself...no other metadata afaik.
Any ideas...hopefully without needing a programming language?
EDIT: Here's the exact output I was looking for assuming file is 5 bytes:
myfile.txt Dec 2 10:58 /path 5
UPDATE: Here's the command I wound up with:
find ./{DIRECTORY_NAME_HERE} -type f -ls |
while read f1 blocks perms blocks owner group size mon day third file;
do echo `basename $file` `ls -lrt $file | tr -s " " | cut -d" " -f6-8` `dirname $file` `ls -lrt $file | tr -s " " | cut -d" " -f-5`; done
If someone can improve it, that'd be great, but this works...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将使用 Perl 来完成此任务:
I'd use Perl for this task:
您是否尝试过
find ./delete -type f -ls
(注意-ls
- 这是关键:-))?然后,您应该能够通过awk
通过管道传输结果来过滤出您想要的字段。编辑...
另一种方法是使用 while 循环,例如:
并将所需的位添加到其中。
Have you tried
find ./delete -type f -ls
(note the-ls
-- that's the key :-) )? You should then be able to pipe the results throughawk
to filter out the fields you want.Edit...
Another way you could do it is with a while loop, e.g.:
and add the bits you need into that.
您还可以使用 find 的 -printf 功能来显示所需文件的正确属性:
我得到如下结果:
You can also use the -printf feature of find to show just the right properties of a file that you want:
I get results like this: