Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
-name pattern
...
The metacharacters (`*', `?', and `[]')
match a `.' at the start of the base
name (this is a change in findutils-4.2.2;
see section STANDARDS CONFORMANCE below).
...
STANDARDS CONFORMANCE
...
-name This option is supported, but
POSIX conformance depends on the
POSIX conformance of the system's
fnmatch(3) library function.
As of findutils-4.2.2, shell
metacharacters (`*', `?' or `[]' for example)
will match a leading `.', because
IEEE PASC interpretation 126 requires this.
This is a change from previous
versions of findutils.
...
So it appears you can use metacharacters wildcard
for -name option.
I am trying to get the equivalent of
these combined commands
of listing ALL directories in
current directories using
find commmand:
Code:
> ls -dl */
> ls -dl .*/
BTW, can you use ls to display both
hidden and visible directories ONLY
(excluding files) in a single command?
Here is the find command I tried with no success:
Code:
find . -maxdepths 0 -type d -name *
Which gives an error
"find: paths must precede expression: ..... "
Thank you.
I obviously misunderstood -maxdepth description in man page.
I still did not understand why option, -name *,
produces an error.
The asterisk * is not quote or escaped, thus it is exposed raw to the shell which interprets it for you before passing it to find. See it in the context of a for loop using your default shell (which is probably bash)
Code:
for i in *;do echo "$i"; done
for i in '*';do echo "$i"; done
The asterisk * is not quote or escaped, thus it is exposed raw to the shell which interprets it for you before passing it to find. See it in the context of a for loop using your default shell (which is probably bash)
Code:
for i in *;do echo "$i"; done
for i in '*';do echo "$i"; done
Thank you.
This works now.
Code:
find . -type d -name "*"
OR
find . -type d -name '*'
Reminder to self:
Add quotes if you want to prevent current shell
from globbing arguments to command or its options.
By the way, you can use it to find directories with pattern name:
find . -type d -name 'pattern*pattern2'
or must be to dont show directories with a pattern name:
find . -type d -prune 'pattern1*pattern2'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.