About "ls" , how can I just show directories only (except linked directories and hidden directories)
10,130
Solution 1
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.
Solution 2
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)
Author by
Admin
Updated on July 02, 2022Comments
-
Admin almost 2 years
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.
-
Etan Reisner about 9 yearsIf all the OP needs is the name then
ls
serves no purpose here andecho
would work just as well. -
Etan Reisner about 9 yearsGiven the wording in the question this may also not be enough (no hidden directories). That being said the
sorted
bit of the question confuses me as does the bit about the.
at the end and the current directory. -
Admin about 9 yearsbut using ls -d */. print the link directory as usual QQ , I don't want to print the link directory