this post was submitted on 17 May 2024
154 points (93.3% liked)

Linux

56009 readers
1036 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 6 years ago
MODERATORS
 

TL;DW

# find with grep
# + concatinates results and runs the command once, faster
find . -name "*.txt" -exec grep -l "somename" '{}' '+'

# run a command for each result individually
find . -name "*.txt" -exec basename '{}' \';' |  column

# case insensitive
find -iname "SoMeNaMe.TxT

# file or dir
find -type f
find -type d

# define file owner
find -user Bob

# define file group
find -group wheel

# by permission
find -perm 777

# find by size
find -size +1G
all 28 comments
sorted by: hot top controversial new old
[–] vvv@programming.dev 57 points 1 year ago (1 children)

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

grep -r --include='*.txt' 'somename' .
[–] fmstrat@lemmy.nowsci.com 3 points 1 year ago* (last edited 1 year ago)

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

[–] Retiring@lemmy.ml 38 points 1 year ago

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

[–] Twitches@lemm.ee 21 points 1 year ago (1 children)

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

[–] boredsquirrel@slrpnk.net 14 points 1 year ago (2 children)

Then you dont know how the video is :D

[–] some_guy@lemmy.sdf.org 28 points 1 year ago (1 children)

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

[–] eveninghere@beehaw.org 8 points 1 year ago (1 children)

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

[–] some_guy@lemmy.sdf.org 1 points 1 year ago

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

[–] Blizzard@lemmy.zip 9 points 1 year ago (1 children)

I know it's 8 minutes long.

[–] boredsquirrel@slrpnk.net 0 points 1 year ago

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

[–] scrion@lemmy.world 19 points 1 year ago* (last edited 1 year ago) (1 children)

Just for the sake of completeness:

https://github.com/BurntSushi/ripgrep

https://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@slrpnk.net 1 points 1 year ago

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

[–] qjkxbmwvz@startrek.website 11 points 1 year ago

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@lemmy.ml 10 points 1 year ago

Her presentations are fun. Thanks! Great watch.

[–] leadore@kbin.social 10 points 1 year ago (1 children)

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@slrpnk.net 2 points 1 year ago (1 children)

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@ttrpg.network 1 points 1 year ago (1 children)

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

[–] boredsquirrel@slrpnk.net 1 points 1 year ago (1 children)

True. But I pay them via Monero

[–] lord_ryvan@ttrpg.network 1 points 1 year ago (1 children)

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

[–] boredsquirrel@slrpnk.net 1 points 1 year ago* (last edited 1 year ago)

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.

[–] toastal@lemmy.ml 6 points 1 year ago

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

[–] joyjoy@lemm.ee 6 points 1 year ago* (last edited 1 year ago)

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.

find . -path '**/node_modules/**' -prune -o -type f -name '*.js' -exec grep 'import' {} +
[–] davetapley@lemmy.world 5 points 1 year ago

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

I've never looked back.

[–] dohpaz42@lemmy.world 4 points 1 year ago (1 children)

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

[–] murtaza64@programming.dev 3 points 1 year ago

Why? The quotes will be consumed by the shell when you execute the command, unless you do like "'{}'"

[–] PipedLinkBot@feddit.rocks 3 points 1 year ago

Here is an alternative Piped link(s):

https://piped.video/watch?v=FvEoGHFKsKA

Piped is a privacy-respecting open-source alternative frontend to YouTube.

I'm open-source; check me out at GitHub.

[–] ____@infosec.pub 3 points 1 year ago

Thank you for the TL;dw. Sincerely appreciated.