Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
The find searches recursively the required files.
But can it be made to search only the given path and not the sub-directories ?
For example, i want to search only in /home/san. I don't want to look up in the sub-directories under san.
Is there any workaround ?
man find
-maxdepth levels
Descend at most levels (a non-negative integer) levels of directories below the command line arguments. -maxdepth 0
means only apply the tests and actions to the command line arguments.
Well guys, maxdepth is not POSIX compliant. I used the prune option but of no use :
$ find /home/san -name c++ -prune -ls
How should prune be used then ?
You really could save everyone their valuable time by posting your "requirements" up front.
I have no intention to spoil anybody's time here, so called "busy" boy.
The fact is that i came to know that "maxdepth" is not POSIX compliant after i had posted here. And what was your reply ?
Quote:
Originally Posted by Habitual
"-maxdepth"? is not a "workaround".
So what is the workaround ? Are you not spoiling time of others ?
I have no intention to spoil anybody's time here, so called "busy" boy.
The fact is that i came to know that "maxdepth" is not POSIX compliant after i had posted here.
Our time is valuable.
Our experience invaluable.
The proper answer starts with "Thank you."
Well guys, maxdepth is not POSIX compliant. I used the prune option but of no use :
$ find /home/san -name c++ -prune -ls
How should prune be used then ?
Well guys, maxdepth is not POSIX compliant. I used the prune option but of no use :
$ find /home/san -name c++ -prune -ls
How should prune be used then ?
The position of prune is important because it applies to the preceding argument. Try:
find /home/san/* -prune -name blabla
Note the asterisk because otherwise -prune will also exclude the /home/san directory itself.
Thanks Brian about that info about prune. But when i use it to list all the hidden files and directories under a directory (/home/san) :
[san@Desktop ~]$ find /home/san/* -prune -name ".*"
[san@Desktop ~]$
I am getting blank o/p. Please rectify me where i am going wrong.
Added : But when i am using find without prune, i am able to list all the hidden files and folders, though find behaves recursively :
[san@Desktop ~]$ find /home/san -name ".*"
/home/san/.local
/home/san/test1/.output
/home/san/.esd_auth
/home/san/.ed_cmdhist_script
/home/san/.gnome2_private
/home/san/.vimrc
/home/san/.thumbnails
/home/san/.viminfo
/home/san/.redhat
--------------------- // List is big. Truncating rest.
Sandy
Last edited by techie_san778; 06-20-2016 at 06:05 AM.
What are you looking for? Do you need only the list of entries, or something else too?
I would suggest you to use for example python or perl or similar to open a dir and get list of entries. That will be even faster than the command find. You can also try ls | awk or similar construct.
What are you looking for? Do you need only the list of entries, or something else too?
I wanted to know that whether find command can be made to search non-recursively, i.e.
within a directory only, not inside it's sub-directories.
That having said, i came to know that the "maxdepth" is not POSIX compliant. So, i was trying out the "prune" option, but i am unable to find the hidden files & directories.
Can you suggest a solution ?
I don't know what POSIX compliance has to do with it but , yes maxdepth 1 is used to find non-recursively, and it works too.
Additionally you could use " -type d -o -type f " if there are other types of files in there too (like socket , block , or symbolic link files) to filter to your needs.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.