LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find command fear and loathing (https://www.linuxquestions.org/questions/linux-newbie-8/find-command-fear-and-loathing-4175531123/)

greatbear 01-15-2015 01:05 PM

find command fear and loathing
 
Its plentiful documentation fails to explain how to use it. After googling all over the world and hunting down examples, it turns out they don't work as the man page indicates if you alter them in the slightest. In fact I know what I want to find, where it is, how to describe it; but the problem is getting find to list that file or those files and moreover making sense of its horrid documentation. It lists too many things. It ignores -prune. It either does nothing or too much. Its a horrible, horrible program, and you are expected to make up the difference by experimentation.

Its so complicated as to make it more worthwhile just to list every file and filter them out with other utilities. Honestly, why go through so much trouble to learn about a command that is as obfuscated as a heartpump?

Sure its great for listing all the files and directories in one subdir, but if you want to exclude multiple dirs or files forget it. Pipe it through grep.

linosaurusroot 01-16-2015 06:48 AM

Enoquestion

business_kid 01-16-2015 07:21 AM

Yů're right. I find the -path option broken - sad but true.

Use it this way:
From search top dir <find -name '*name*'> and both asterisks may not be necessary
For case insensitive <find -iname '*name*'>

or for file type
<find -type l' all the types work.

The atime & ctime also leave me desiring accommodation in a home for the bewildered. Continuing the good tradition of pppd, vim, emacs and such worth candidates for a total rewrite.

J Martin Rushton 01-16-2015 07:53 AM

Running on CentOS 6:
Code:

# find /usr -path find
# find /usr -path \*find
/usr/src/kernels/2.6.32-431.el6.x86_64/include/config/generic/find
/usr/src/kernels/2.6.32-358.el6.x86_64/include/config/generic/find
/usr/bin/oldfind
/usr/bin/find
/usr/bin/gnatfind
/usr/bin/gst-typefind

which is exactly as documented.

Code:

# find /usr/* -prune
/usr/bin
/usr/etc
/usr/games
/usr/include
/usr/lib
/usr/lib64
/usr/libexec
/usr/local
/usr/lpp
/usr/sbin
/usr/share
/usr/src
/usr/tmp

These are all directories (except tmp which is a link), so find does not descend into them, exactly as documented.

-{a,c,m}time can be a bit of fun, consider using -daystart to force the interpretation of time to run from 00:00:00 today. -daystart -mtime +1 is then always earlier than yesterday.

As regards to listing all files and filtering them, find will be more efficient and do it with less image activations. Not a problem for a few hundred files, but significant for a few hundred thousand.

Like many venerable programs the syntax can be a bit funny, but then it tries to accommodate various historic flavours of UNIX as well as modern Linux systems. ps is another fundamental program that suffers from the same option bloat. In practice I find you end up knowing the half dozen or so options you use and ignoring the rest until you stumble across them in a script.


All times are GMT -5. The time now is 11:58 PM.