You are not logged in.

#1 Yesterday 10:08:31

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 3,106

[solved]Find file content

Using find I try to display the occurrence of "cairo_xlib" in a directory.

These commands work well, with the drawback of outputting a large number of paths:

find /media/DATEN/Conky -type f -exec grep -il "cairo_xlib" {} \;
find /media/DATEN/Conky -type f xargs grep -il "cairo_xlib"

or with grep

grep -ilR "cairo_xlib" /media/DATEN/Conky

I only want the NUMBER of files found that contain 'cairo_xlib' (!).  wink  Can anyone help?

Last edited by unklar (Yesterday 14:59:42)

Offline

#2 Yesterday 10:43:31

brontosaurusrex
Senior Associate, Middle Office
Registered: 2015-09-29
Posts: 2,819
Website

Re: [solved]Find file content

With ripgrep

rg cairo_xlib --stats | grep 'files contained matches'

and I'am sure there is a version of this that doesn't need grep.

edit: or

grep -ilR "cairo_xlib" /media/DATEN/Conky | wc -l

Offline

#3 Yesterday 14:58:31

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 3,106

Re: [solved]Find file content

brontosaurusrex wrote:

With ripgrep

rg cairo_xlib --stats | grep 'files contained matches'

and I'am sure there is a version of this that doesn't need grep.

edit: or

grep -ilR "cairo_xlib" /media/DATEN/Conky | wc -l

BINGO!
Thank you, @bronto

ripgrep is not installed, but

grep -ilR "cairo_xlib" /media/DATEN/Conky | wc -l

satisfies me.  wink

Offline

#4 Yesterday 15:07:45

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,429

Re: [solved]Find file content

brontosaurusrex wrote:

With ripgrep

rg cairo_xlib --stats | grep 'files contained matches'

and I'am sure there is a version of this that doesn't need grep.

edit: or

grep -ilR "cairo_xlib" /media/DATEN/Conky | wc -l

I get different results:


2026·09·30 @ 10:56:17 /media/5/Conky
   $ rg cairo_xlib --stats /media/5/Conky | grep 'files contained matches'
420 files contained matches
 
 2026·09·30 @ 11:46:18 /media/5/Conky
   $ 

↑↑ 420 files vs ↓↓ 425 (THE WINNER) ↓↓

 2026·09·30 @ 10:54:19 ~
   $ grep -ilR "cairo_xlib" /media/5/Conky | wc -l
425

So I stripped out the "wc -l"  and put them in a file ...

 2026·09·30 @ 11:46:37 ~
   $ grep -ilR "cairo_xlib" /media/5/Conky>cairo.txt

Then did a sort | removing any duplicates:
]776717325_260930-120317.webp

425 is the winner


Debian 13 Beardog hosted by SoxDog
Still a Conky 1.9er at heart.

Offline

#5 Today 07:47:26

brontosaurusrex
Senior Associate, Middle Office
Registered: 2015-09-29
Posts: 2,819
Website

Re: [solved]Find file content

For behavior closer to grep -ilR, including hidden/ignored files, symlinks and binary files:

rg -il --hidden --no-ignore --follow --text 'cairo_xlib' /media/DATEN/Conky | wc -l

ai says:

--hidden — include hidden files and directories, such as .config.
--no-ignore — search files even when .gitignore, .ignore, or similar rules exclude them.
--follow — follow symbolic links and search their targets.
--text — treat binary files as text and search their contents too.

Offline

#6 Today 17:05:48

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,429

Re: [solved]Find file content

Rabbit hole getting deeper.   smile


Debian 13 Beardog hosted by SoxDog
Still a Conky 1.9er at heart.

Offline

Board footer

Powered by FluxBB