About “ls” , how can I just show directories only

2019-07-23 11:39发布

I meet some problem about "ls" this command

I want to print just only directory without hidden or linked

but I use man ls to look the explanation , but I didn't found

if there is a flag that I can do what I want ...

thanks

below is the question I am going to solve ...

 4. Display the visible exits

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.

标签: linux shell unix
2条回答
叛逆
2楼-- · 2019-07-23 12:16

Use ls -d */. The */ is a wildcard that expands to all directories in current directory (directories end in /). -d tells ls to list the names of directories given as arguments and not their content.

查看更多
放我归山
3楼-- · 2019-07-23 12:23

You should look into the stat command. Something like:

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

There's also find

find . -maxdepth 1 -type d -print

Find will show you hidden directories (including . the current directory)

查看更多
登录 后发表回答