关于“ls”,我怎么才能只显示目录(链接目录和隐藏目录除外)

时间:2015-03-25 19:19:31

标签: linux shell unix

我遇到一些关于“ls”这个命令的问题

我只想打印没有隐藏或链接的目录

但我用man ls查看解释,但我没找到

如果有一面我可以做我想要的旗帜......

感谢

下面是我要解决的问题......

4.显示可见退出

This is two commands: The first command prints "Visible exits: "
-> It must not advance the cursor to the next line.
The second command displays the visible exits and then a period (.).
-> To prevent the linked directories contents from also displaying, you 
will need a flag.
-> Several wildcard patterns will be needed.
-> The period will be the last of these patterns.
   The period means the current directory. But here it will seem, to
   the user, to be a period at the end of a sentence listing visible
   exits.
-> You will need to use a flag to keep the output from being
   sorted (otherwise the period will not stay at the end).
-> With several patterns to search, some may have no matches. That
   is OK, but we don't want to see warning messages. Redirect these.

2 个答案:

答案 0 :(得分:8)

使用ls -d */*/是一个通配符,可扩展到当前目录中的所有目录(目录以/结尾)。 -d告诉ls列出作为参数而不是其内容的目录名称。

答案 1 :(得分:1)

您应该查看stat命令。类似的东西:

stat -c '%F %n' * | sed -n '/^directory /s///p'

还有find

find . -maxdepth 1 -type d -print

查找将显示隐藏目录(包括.当前目录)