find a file containing some text

TL;DW


<span style="color:#323232;"># find with grep
</span><span style="color:#323232;"># + concatinates results and runs the command once, faster
</span><span style="color:#323232;">find . -name "*.txt" -exec grep -l "somename" '{}' '+'
</span><span style="color:#323232;">
</span><span style="color:#323232;"># run a command for each result individually
</span><span style="color:#323232;">find . -name "*.txt" -exec basename '{}' ';' |  column
</span><span style="color:#323232;">
</span><span style="color:#323232;"># case insensitive
</span><span style="color:#323232;">find -iname "SoMeNaMe.TxT
</span><span style="color:#323232;">
</span><span style="color:#323232;"># file or dir
</span><span style="color:#323232;">find -type f
</span><span style="color:#323232;">find -type d
</span><span style="color:#323232;">
</span><span style="color:#323232;"># define file owner
</span><span style="color:#323232;">find -user Bob
</span><span style="color:#323232;">
</span><span style="color:#323232;"># define file group
</span><span style="color:#323232;">find -group wheel
</span><span style="color:#323232;">
</span><span style="color:#323232;"># by permission
</span><span style="color:#323232;">find -perm 777
</span><span style="color:#323232;">
</span><span style="color:#323232;"># find by size
</span><span style="color:#323232;">find -size +1G
</span>
leadore,
leadore avatar

I prefer to watch videos via peertube, not youtube, whenever possible. She has a peertube channel so here is the same video there: https://tinkerbetter.tube/w/g8K2zBgwwwE1xukkT6EmSo

boredsquirrel,

It is important to have backups for when Youtube blocks clients, but I just watch it over a VPN and Freetube or Grayjay. Not leeching any resources when avoidable, just costing big brother money.

lord_ryvan,

You’re giving all your data to your VPN company, though

boredsquirrel,

True. But I pay them via Monero

lord_ryvan,

And give no personal information? Like Mullvad? That is an improvement.

boredsquirrel, (edited )

Yup. Also their VPN app on Linux is better than what KDE and GNOME have. Poorly. They hook into it very intensely, early boot blocking via a systemd service and all.

davetapley,

Forgive me for only TLDW and not watching, but was ack mentioned?

I’ve never looked back.

____,

Thank you for the TL;dw. Sincerely appreciated.

toastal,

She’s done such a good job with this channel. I understand most of the content, but I always pick up a nugget of new as well as being able to better explain after a topic she ELI5’d

scrion, (edited )

Just for the sake of completeness:

github.com/BurntSushi/ripgrep

github.com/ggreer/the_silver_searcher

It’s useful to be able to do this without additional tools (and there are more applications for the general command setup discussed in the video), but in practice, ease of use and performance often make a difference.

boredsquirrel,

I have rg installed but only used it for basic grep replacement

qjkxbmwvz,

I kinda prefer xargs to the -exec option — just feels more UNIXy to me (do one one job well).

But as another comment said, for grep I just use -r and –include. So clearly I’m not very consistent…

z3rOR0ne,
@z3rOR0ne@lemmy.ml avatar

Her presentations are fun. Thanks! Great watch.

vvv,

grep -r exists and is even more faster and doesn’t require passing around file names.


<span style="color:#323232;">grep -r --include='*.txt' 'somename' .
</span>
fmstrat, (edited )

Or use strings if you want clean binary results. (Grep can probably do this, too)

Edit: Yes, with -b, also -R follows symlinks unlike -r

joyjoy, (edited )

If you have a very large directory, find will check each individual file, even when -path doesn’t match, which makes it take longer to complete. Combine -o and -prune to omit them entirely.


<span style="color:#323232;">find . -path '**/node_modules/**' -prune -o -type f -name '*.js' -exec grep 'import' {} +
</span>
dohpaz42,
@dohpaz42@lemmy.world avatar

When using both {} and ;, it’s safer to use single quotes to escape the current argument and ending delimiter; eg ’{}’ and ’;’, respectively.

Retiring,
@Retiring@lemmy.ml avatar

This does not need to be a 8 minute video. Read your tldw instead. Thanks, OP.

Twitches,

Better than the video thank you, I didn’t watch the video

boredsquirrel,

Then you dont know how the video is :D

some_guy,

Not the person above, but I know that written explanations of command line tools are always preferred by myself.

eveninghere,

No, no, you just need to seek through the time and copy & paste the text in the video!

some_guy,

Why didn’t I think of that? This is a game changer!

Blizzard,

I know it’s 8 minutes long.

boredsquirrel,

Skip to 2:46 how she also mentioned in the description

  • All
  • Subscribed
  • Moderated
  • Favorites
  • linux@lemmy.ml
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • megavids
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • provamag3
  • JUstTest
  • All magazines