:: Re: [DNG] Using find to find all oc…
Kezdőlap
Delete this message
Reply to this message
Szerző: Olaf Meeuwissen
Dátum:  
Címzett: R A Montante, Ph.D.
CC: dng
Tárgy: Re: [DNG] Using find to find all occurences of a file(text string) in a tree.
Hi,

Forgive me for nitpicking but ...
"R A Montante, Ph.D. via Dng" <dng@???> writes:

> You need one or more tests ("predicates") for which files you want. I
> typically use "-name" or "-iname", "-type", or occasionally "-regex".
> Some examples:
>
> Find all filenames with a "~" tilde at the end (vim backup files):
>
>    find  /home/me/Documents  -iname  "*~"


This also finds directories, symbolic links, socket, etc., not just
files. For just files, add `-type f`.
BTW, the pattern passed to -iname is already case insensitive ;-)

> Discard all filenames with a "~" tilde at the end:
>
>     find  /home/me/Documents  -iname  "*~"  -exec rm {} \;


Because this suffers from the same as the previous, the -exec {} \; will
fail on matching directories. Use -delete instead.

> Change permissions on everything that isn't a directory:
>
>    find /home/me/Documents  ! -type d  -exec chmod -x {} \;

>
> Look for ".h" files in directory paths that include "include" somewhere :
>
>     find /usr  -regex ".*include.*\.h"  -ls


For clarity's sake, the "somewhere" is in the pathname, not the content
of the pathname.

> The "-iname" predicate is just a case-insensitve version of "-name".
> The "!" operator reverses the sense of the following predicate. The
> "-exec" predicate lets me do what I want with anything that matches;
> it must be terminated with the "\;" token.


And, for completeness' sake, the {} is replaced by the pathname that
matched the conditions.

> (If my colors come through, then green is the root/starting-point, red
> is your specific information.
>
> -Bob
>
> On 11/8/24 07:00, dng-request@??? wrote:
>
>  Date: Fri, 8 Nov 2024 15:00:02 +1100
> From: terryc <terryc@???>
> To: dng@???
> Subject: [DNG] Using find to find all occurences of a file(text
>     string) in a tree.
> Message-ID: <20241108150002.68b04a4b@???>
> Content-Type: text/plain; charset=US-ASCII

>
> Hopefully just suffering brain fade here
> man find basically give
>
> find [starting point] [expression]
>
> is taken as two starting points.
>
> Example find /media/raid0/file /proc
> results in dumping everyfile under /media/raid0/file then /proc
>
> [...]


Hope this helps,
--
Olaf Meeuwissen