Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About "ls" , how can I just show directories only (except linked directories and hidden directories)

Tags:

linux

shell

unix

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.
like image 944
user3590617 Avatar asked Nov 30 '22 00:11

user3590617


2 Answers

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.

like image 93
Teyras Avatar answered Dec 04 '22 05:12

Teyras


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)

like image 25
glenn jackman Avatar answered Dec 04 '22 05:12

glenn jackman