【发布时间】:2020-10-06 22:58:31
【问题描述】:
假设我有一个名为test 的工作目录。在这个文件夹中,我有许多子目录:
$ ls */*
00/0a:
file1.txt
01/0b:
file2.txt
02/0c:
file3.txt
现在我想得到相同的结果,但使用这样的 xargs:
$ ls | xargs -I {} ls {}/*
ls: cannot access 00/*: No such file or directory
ls: cannot access 01/*: No such file or directory
ls: cannot access 02/*: No such file or directory
我不明白为什么使用* 不起作用。
有替代品吗?
【问题讨论】:
-
解析
ls的输出为usually a bad idea。使用find通常是更好的选择 -
在另一个 StackExchange 站点上有一个答案:superuser.com/questions/519008/…TLDR; =>
ls | xargs -I {} sh -c 'ls {}/*'。同时,@Aserre 评论仍然有效。