You are not logged in.

#1 2026-09-30 10:08:31

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

[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 (2026-09-30 14:59:42)

Offline

#2 2026-09-30 10:43:31

brontosaurusrex
Senior Associate, Middle Office
Registered: 2015-09-29
Posts: 2,820
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 2026-09-30 14:58:31

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

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 2026-09-30 15:07:45

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

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 Yesterday 07:47:26

brontosaurusrex
Senior Associate, Middle Office
Registered: 2015-09-29
Posts: 2,820
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 Yesterday 17:05:48

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

Re: [solved]Find file content

Rabbit hole getting deeper.   smile


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

Offline

#7 Today 01:16:08

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 13,491
Website

Re: [solved]Find file content

brontosaurusrex wrote:

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.

So, what advantages does ripgrep have over that grep command?


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky and Mastodon, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#8 Today 05:28:43

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

Re: [solved]Find file content

https://ripgrep.dev/vs/grep/

For me, better defaults and speed.

Offline

#9 Today 07:05:17

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 13,491
Website

Re: [solved]Find file content

^Look like improvements, yes. Thanks for finding it, although I'll probably stay with grep for now - even grepping the whole set of BL debian package source repos doesn't take all that long.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky and Mastodon, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#10 Today 19:36:49

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

Re: [solved]Find file content

brontosaurusrex wrote:

https://ripgrep.dev/vs/grep/

For me, better defaults and speed.

Thanks for the link.


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

Offline

Board footer

Powered by FluxBB