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.
do you have to specify a location for find? or will it search the whole file system by default?
also...do you use find...or is there a better tool
i know of
whereis (good for binary files,man pages,source code)
which (good for finding executable's)
locate
find
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881
Rep:
Quote:
Originally Posted by sigint-ninja
hi guys
do you have to specify a location for find? or will it search the whole file system by default?
also...do you use find...or is there a better tool
i know of
whereis (good for binary files,man pages,source code)
which (good for finding executable's)
locate
find
If you don't specify a search path, find will search the working directory To search everything, you'd use "find /".
Many years ago, I looked at the man pages for find and locate and decided to stick to the search tool in the GUI. For me, the CLI on a PC is a backup or special-purpose tool; using it as a replacement for the GUI is keeping a dog and barking yourself.
I would suggest you to read the man page (of find) or look for examples on the net. All the answers to your questions are already available (except the last one).
Quote:
Originally Posted by sigint-ninja
is there a better tool i dont know about?
There is no best tool (in general), this question has no meaning. There should be first a goal to reach and next you can look for a tool to achieve that. Sometimes find is a good choice, but there are a lot of other possibilities. For example ls, or you can use the -r (or -R) options of some utilities, like grep to make a recursive search, or use perl/python with their libraries....
Please be more specific if you wish to get better (not-so-general) help.
I agree with many others, and a lot with pan64, which is to read and become familiar with the man page for find, as well as reading man pages in general.
Over the years, I've honed my internal debugging so that I rarely do have to ask a question. Any why? Because I realized that many of my answers are already documented and if I had taken the time to look; not only would I have found my answer, but also I may have found additional answers. Meanwhile, reading, sometimes responding too, threads like these, I've learned a few things over time as well.
My personal viewpoint, right or wrong about find is:
"the command" - find
"where to go from" - I always tend to say "." - which means "starting here!", but do know I can say "/tmp", or "/", which usually reminds me to do sudo because it will involve system directories my typical username can't access.
"pattern" - what to search for
"action" - what to do. Sorry, but my default find always includes -print even though you long have not needed it. About 99% of the time I do a final find, I use -exec. I say "final find" because really the statistics are 50%. I will find -print to validate my search finds what I want, and then I code the -exec to "do" what I want. However just about 100% of the time I invoke a find, I'm intending to find files and do something to them further.
I have also learned a GREAT DEAL about grep, just reading the man page and since I used grep a lot in some bash scripts, this learning was important to discern between <0 or != 0 or explicit non-zero outcomes.
Distribution: Cinnamon Mint 20.1 (Laptop) and 20.2 (Desktop)
Posts: 1,633
Rep:
Quote:
I'd use locate instead, heaps better!
If I remember rightly you have to run the command
Code:
# updatedb
first before using locate.
It scans your disk for files and generates an index file which is used by locate hence it's quicker. With new files written to disk you'll have to run updatedb periodically to keep the index file current.
find has to scan your whole disk for each search. Big disk... Big wait.
Find has a somewhat obscure syntax and its power isn't really revealed with simple usage like find . -name 'foobar' - even though it does that well.
In fact, if you're comparing find with locate, you're missing the point. It's not meant (in my opinion) to compete with locate. I never think "locate or find?" They're two separate tools, even if their functionality might blend.
I use locate to locate mostly static files. keyfiles, binaries, configuration files, etc. I don't care about how old the mysql my.cnf file is, I just don't know where it is.
On the other hand, find is better suited for more dynamic files, or to profile some common property of files. For example, finding executables in a directory after ./configure && make , finding old logs to delete or even better, discovering where new logs are being created (have you ever read in a gui, "view log for details" but you cannot find out WHERE? Use finds -mmin to see what was modified in the last few minutes!
find will recursively search the directory given. If you use ".", "." means the current directory.
After that are tests. Note they are used left to right. So -type f -iname 'foo*' is faster then -iname 'foo*' -type f
find is also useful with combination with other tools like parallel, process substitution or while read loops.
An example of the first two
Code:
# In parallel, convert all *.flac files to ogg with ffmpeg using files in /musicfiles discovered by find
parallel -0 ffmpeg -i {} {.}.ogg :::: <(find /musicfiles -type f -iname \*.flac -print0)
do you have to specify a location for find? or will it search the whole file system by default?
also...do you use find...or is there a better tool
...
I say, please do read the man pages for find.
For my part, I use find, as it is very powerful, though it is difficult to master. Even after lots of experience I often open the find man page in order to construct my command properly. But it is very very powerful; read the man page, you'll understand what I mean.
locate is also very good but the system has to keep an up-to-date database in order for it to work.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.