如何“ls”仅一层深?
我有很多包含数据的子目录,并且我想要一个我拥有的作业(子目录)的简短列表。我对以下命令不满意。
$ ls H2*
H2a:
energy.dat overlap.dat
norm.dat zdip.dat ...
(much more)
H2b:
energy.dat overlap.dat
norm.dat zdip.dat ...
(much more)
这种不必要的混乱违背了通配符的目的(限制输出)。如何将输出限制为一层深度?我想看到以下输出
H2a/ H2b/ H2z/
感谢您的帮助, 缺口
I have lots subdirectories containing data, and I want a short list of which jobs (subdirectories) I have. I'm not happy with the following command.
$ ls H2*
H2a:
energy.dat overlap.dat
norm.dat zdip.dat ...
(much more)
H2b:
energy.dat overlap.dat
norm.dat zdip.dat ...
(much more)
This needless clutter defeats the purpose of the wildcard (limiting the output). How can I limit the output to one level deep? I'd like to see the following output
H2a/ H2b/ H2z/
Thanks for your help,
Nick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
试试这个
-d
选项应该列出“仅目录”,但它本身只是列出我个人觉得有点奇怪的。需要通配符才能获取实际的目录列表。
更新:正如@Philipp指出的,你可以更简洁地做到这一点,而无需离开bash,说
差异在于
ls
将在单独的行上打印项目,这是通常对于通过管道传输到其他功能很有用。Try this
The
-d
option is supposed to list "directories only", but by itself just listswhich I personally find kind of strange. The wildcard is needed to get an actual list of directories.
UPDATE: As @Philipp points out, you can do this even more concisely and without leaving bash by saying
The difference is that
ls
will print the items on separate lines, which is often useful for piping to other functions.您应该考虑使用 find,如下所示:
注意:在“-max深度 1”之前放置“-type d”会导致 Debian Linux 上出现警告(“find:警告:您已在参数后指定了全局选项 -maxdepth”) -type,但全局选项不是位置性的,即 -max深度 会影响在其之前指定的测试以及在其之后指定的测试。请在其他参数之前指定全局选项。”)Mac 上不会发出此类警告。
You should consider using find, like this:
NOTE: Putting "-type d" before "-maxdepth 1" results in a warning on Debian Linux ("find: warning: you have specified the global option -maxdepth after the argument -type, but global options are not positional, i.e., -maxdepth affects tests specified before it as well as those specified after it. Please specify global options before other arguments.") No such warning is issued on Mac.
由 Bash 进行扩展,因此您甚至不需要
ls
。如果您同时拥有以
H2
开头的文件和目录,则可以附加斜杠以将 glob 限制为目录:It's Bash who does the expansion, so you don't even need
ls
.Should you have both files and directories starting with
H2
, you can append a slash to restrict the glob to directories:使用 Steve Baker 的
tree
,网址为 http://mama.indstate.edu /用户/冰/树/它填补了
ls
中缺少的许多内容。要列出一层深的目录:
Use
tree
by Steve Baker at http://mama.indstate.edu/users/ice/tree/It fills in for a lot of things that are missing from
ls
.To list directories one layer deep:
也许这就是您正在寻找的?
Perhaps this is what you are looking for?