This command lists directories in the current path: ls -d */
What exactly does the pattern */
do?
And how can we give the absolute path in the above command (e.g. ls -d /home/alice/Documents
) for listing only directories in that path?
This command lists directories in the current path: ls -d */
What exactly does the pattern */
do?
And how can we give the absolute path in the above command (e.g. ls -d /home/alice/Documents
) for listing only directories in that path?
Test whether the item is a directory with
test -d
:FYI, if you want to print all the files in multi-line, you can do a
ls -1
which will print each file in a separate line. file1 file2 file3I use:
This creates a single column with no trailing slash - useful in scripts.
My two cents.
I partially solved with :
Well , this reduce to me , the mayor part :)
In case you're wondering why output from 'ls -d */' gives you two trailing slashes, like:
it's probably because somewhere your shell or session config files alias the ls command to a version of ls that includes the -F flag. That flag appends a character to each output name (that's not a plain file) indicating the kind of thing it is. So one slash is the from matching the pattern '*/', and the other slash is the appended type indicator.
To get rid of this issue, you could of course define a different alias for ls. However, to temporarily not invoke the alias, you can prepend the command with backslash:
\ls -d */
If hidden directory is not needed to be listed, I offer:
And if hidden directories is needed to be listed, use:
OR