On 23Aug2016 18:00, Markus Schönhaber <fedora-users(a)list-post.mks-mail.de> wrote:
> what is the difference between these two commands ?
> ls /*
> and
> ls /*/
>
> -------------------
> these two commands give me different output:
>
> ls -ld /* =--->list all the files inside the directory (both files and
> subdirectories)
>
> ls -ld /*/ =---> give me the list of only the (subdirectory inside the
> directory)
The difference is not caused by ls but rather by the way the shell does
the filename expansion.
In case it isn't clear, only directories will have stuff inside them (/a/b...)
so /*/ will only match directries.
BTW: If you're using bash, it will by default show you the
expanded list
of filenames that match the pattern if you press Ctrl-X * when the
cursor is positioned directly after the pattern.
And in any shell you can investigate this kind of thing like this:
echo /*
echo /*/
and see exactly what command is dipatched like this:
( set -x ; ls /* )
( set -x ; ls /*/ )
Using a subshell here purely so that the "set -x" applies only to the only
command.
Cheers,
Cameron Simpson <cs(a)zip.com.au>