Demystifying "find" and "find -exec" ...Lil' Linux Lesson!

Поділитися
Вставка
  • Опубліковано 5 лип 2024
  • Has the internet told you Linux' "find" command is too scary to use? Well, they're wrong. Linux' "find" command - also found in lots of other *NIX systems - is a critical tool to learn.
    In today's Lil' Linux Lesson, I'll be demystifying the "find" command, and covering how it works with the "-exec" option, and the superpower differences between using "+" and using ";", which I promise will make your life easier as a sysadmin, Linux user, or just any nerd who likes to play with the terminal.
    Lastly, this video wouldn't be possible without my monthly sustaining supporters on Patreon and Ko-Fi. Members get a bunch of cool perks- if my unsponsored videos help you, I appreciate your consideration!
    / veronicaexplains
    ko-fi.com/VeronicaExplains
    0:00 I say "greetings" and tell you why the find command is important
    1:24 Basic use of find, both GNU and BSD variants!
    2:46 Performing magic in the terminal with find -exec
    4:56 Some other parameters for find: -iname, -type, -user, -group, -perm, -size
    6:53 Why does find -exec end with a plus?
    #linux #homelab #terminal
  • Наука та технологія

КОМЕНТАРІ • 590

  • @VeronicaExplains
    @VeronicaExplains  Місяць тому +52

    Some of you commenters are pointing out, accurately, that `grep` can recursively search files on its own, without `find`. Of course it can! But remember, grepping was just the example I was using to illustrate `-exec`. Your options between `-exec` and `{} +` are practically limitless.
    Also, to those of you about to voice your displeasure with "needing the terminal to find lost files", your assignment is this word problem: "Susie has a VPS running a web server, and her server daemon has crashed due to a malformed configuration file. How can Susie identify and resolve the problem using only GUI tools and no terminal commands?"

  • @greendblink182
    @greendblink182 Місяць тому +112

    Keeping up with the Commodore would be a reality show I would actually watch

  • @Andoresu96
    @Andoresu96 Місяць тому +90

    I like the part where veronica says "its explaining time" and explains all over the place

  • @robbylock1741
    @robbylock1741 Місяць тому +152

    I'm a retired UNIX/Linux System Administrator (30+ years) and I find your content refreshing and more to the point very useful! Yeah there are newer and perhaps simpler commands, but knowing the basics is still very important. People would ask me why learn vi when there is nano for example. Because from AIX to (name your Linux distro) etc, you'll always have vi :) Thanks again for your hard work and keep keep doing what you're doing!

    • @illegalsmirf
      @illegalsmirf Місяць тому +1

      @@occamraiser Not quite sure how to handle this, but are you aware of the fact vim has more features than nano does? Of course, if you haven't taken the time to learn vim then you won't be aware of that fact and if the pitiful nano is all you need then it's fine. But it is shite for handling text files of any non-trivial degree of length or complexity.

    • @DavidSchmitt
      @DavidSchmitt Місяць тому +1

      Ha, I learned vi on AIX 3.2 in '97

    • @saszab
      @saszab Місяць тому +1

      mc (Midnight Commander) has been around for 30 years. Why people are still using find, vi, nano and so on? I understand that there are some cases when there's no other choice (for example, to run certain command with all the found files), but they are very rare.

    • @DavidSchmitt
      @DavidSchmitt Місяць тому +4

      @saszab mc is great for interactive use but extremely unhelpful for shell programming.

    • @saszab
      @saszab Місяць тому +1

      @@DavidSchmitt Sure, but these are vary rare cases. Vast majority of the Linux users never write scripts.

  • @chadcordero1618
    @chadcordero1618 Місяць тому +122

    In my 30 years as a sysadmin, I've never heard of the +. I've always used the \; when using -exec. Thanks.

    • @Lordie
      @Lordie Місяць тому +12

      37 years for me. I can't wait to soup up my automation scripts with + lol

    • @guss77
      @guss77 Місяць тому +10

      Only 28 years here, and I also just learned about + from Veronica. ✌️

    • @FishKungfu
      @FishKungfu Місяць тому +5

      Only 25 years here, and I always used \; too. I'll be trying the + now. Thanks, Veronica!

    • @knucklecorn
      @knucklecorn Місяць тому +2

      hah, wait until you hear about -execdir

    • @KeithBoehler
      @KeithBoehler Місяць тому +6

      I decided at one point to never skip an intro to a subject for reasons like this. Sometimes you just learn something new and that is awesome!

  • @ducksauz
    @ducksauz Місяць тому +30

    Holy Crap! 30+ years in this business and I *just* learned about '+' as an argument to find.
    How much of my life have I wasted to \; ?!
    Thanks Veronica! You're frickin' awesome!

    • @uthamal
      @uthamal Місяць тому +1

      Same here, I always tended to use -print0 and pipe it to xargs -0. Thanks Veronica!

  • @jefflsmith616
    @jefflsmith616 Місяць тому +20

    This was a real "+" for a topic. I use "find" nearly every day and did not know it has alternate endings \; Thanks.

  • @d00kieC
    @d00kieC Місяць тому +23

    As someone who was "cool" in the mid-nineties, I appreciate the spacehog based puns.

    • @VeronicaExplains
      @VeronicaExplains  Місяць тому +4

      I figured there was only a few who would get it.

  • @zantetsu8674
    @zantetsu8674 Місяць тому +36

    I prefer `find | xargs grep` because it executes grep one time across all the found files instead of executing a separate grep for each file as find -exec would do. find | xargs grep is often an order of magnitude faster when grepping a lot of files.
    EDIT: OK I wrote the above before I finished watching the video! And I see the the '+' form of exec does effectively the same thing. Wow I learned something new after using find daily for about 25 years. Thanks!

    • @VeronicaExplains
      @VeronicaExplains  Місяць тому +15

      The + in my command executes once though.

    • @dingokidneys
      @dingokidneys Місяць тому +5

      @@VeronicaExplains I also learned this trick for the first time after using xargs for years. I gotta RTFM a bit more. 😁

    • @Rudxain
      @Rudxain Місяць тому +2

      I want to mention GNU `parallel`, which is similar to `xargs` but distributes the load across all logical cores. The only bad thing is that it requires a Perl interpreter (and many other Perl dependencies)

    • @gedeonducloitre-delavarenn8106
      @gedeonducloitre-delavarenn8106 Місяць тому +5

      the xarg approach is an antipattern: it's broken with filenames containing quotes or newlines. The cure is to use GNU's versions with the -print0 predicate to find, and the -0 (or --null) option to xarg. But this is not portable, and is very awkward. -exec (or even -execdir) with + is the correct approach

    • @billeterk
      @billeterk Місяць тому +1

      I believe neither ‘+’ nor xargs necessarily put all the files as arguments to the command but parcel them up with respect to MAXARGS.

  • @Richthofen80
    @Richthofen80 Місяць тому +49

    It's a good day when there's a new video from Veronica!

  • @Aura_Mancer
    @Aura_Mancer Місяць тому +7

    Thank you! Because honestly, even as a somewhat experienced Linux user, learning these types of tools is hard, because you only use it when you needed by looking at the long documentation, then you never touch it again so you forget. Then when you needed it once more, it's the same tedious process. A fun video like this is perfect to master a tool like this!

  • @petermayes8764
    @petermayes8764 Місяць тому +22

    Started using Unix on a VAX 11/780 in the '80s before you were born!! But you're never too old to learn something new! Been using "\;" since then, and only just now learned about "+"! Thank you.

  • @ftolead
    @ftolead Місяць тому +12

    The find command can be insanely powerful. I just learned the (+) versus the (;). Thank you for that. I had always used ; and didn't know about the +

  • @MrG0CE
    @MrG0CE Місяць тому +6

    SHE'S A LIGHT IN THE LINUX COMUNITY !
    LIKE THE GUY FROM "THE LINUX EXPERIMENT".

  • @UnwalledGarden
    @UnwalledGarden Місяць тому +24

    Your no nonsense explanations are great!

  • @andrewlankford9634
    @andrewlankford9634 Місяць тому +2

    Never knew Gilda Radner was so into Linux. And still alive for that matter.

  • @CurrentlyVince
    @CurrentlyVince Місяць тому +3

    I love these videos -- if I ever have any kind of "virtual assistant" on a Linux machine, I want the voice to be Veronica Explains in 8th grade math teacher mode.

  • @paul.j.macdonald
    @paul.j.macdonald Місяць тому +3

    Been a Linux user for 20+ years. Love your videos and how you extend your knowledge to newer users. Keep it up.

  • @flapjack9495
    @flapjack9495 Місяць тому +2

    I've been a professional Linux sysadmin since the 90s and use the find command all the damn time. This intro was perfect, and it taught me something I didn't know - ending the command with a plus instead of a semicolon. That's super useful in many contexts - thanks for that!

  • @thekidneystoner6183
    @thekidneystoner6183 Місяць тому +8

    Linux has been my development platform for work for nearly a decade, but I still watch these videos because of how fun they are. And speaking of keeping up with the Commodore, I haven't written a BASIC program in years, I realised I miss it.

    • @paulsander5433
      @paulsander5433 Місяць тому +1

      Ah, but would you admit that on a CV? Right after knowing how to configure sendmail, without the help of m4?

  • @remi6801
    @remi6801 Місяць тому +8

    Are you keeping up with the Commodore?
    Love your channel ! Very informative and entertaining !

    • @VeronicaExplains
      @VeronicaExplains  Місяць тому +4

      Thank you! I have it on good authority that the Commodore is keeping up with us.

  • @xcalibur839
    @xcalibur839 Місяць тому +10

    Great video, looking forward to the grep episode as well. Are you keeping up with the Commodore?

  • @octopusonfire100
    @octopusonfire100 Місяць тому +4

    The moment I learnt how to use find, I felt like I had unlocked a superpower.

  • @bargainbincatgirl6698
    @bargainbincatgirl6698 Місяць тому +1

    This is what I need to start my weekend, a quick explanation of how to use a command tool older than me....
    And I'm 40 years old.

  • @DavidSchmitt
    @DavidSchmitt Місяць тому +1

    Been using find for 25 years and still learned something new (+). Thanks!

  • @user-vr2rq5hl6l
    @user-vr2rq5hl6l Місяць тому +1

    Using “find” with -exec is so powerful! I’ve been using it since I first discovered it in a Unix manual in 1985. Whew!

  • @drfrancintosh
    @drfrancintosh 13 днів тому

    Seriously - you're doing "god's" work. All software engineers should know the Unix shell. Linux runs the internet. I can't tell you how many professional programmers I know who cannot use BASH. It baffles me. Keep doing what you do!

  • @Irenethemeanbean
    @Irenethemeanbean Місяць тому +2

    Thank you, Veronica! I’m finally taking my first steps into Linux and you’re helping me ‘find’ things along the way!

  • @matthewrease2376
    @matthewrease2376 Місяць тому +7

    "Have you played Atari today!"
    (No commodore because I'm a rebel. "

    • @saszab
      @saszab Місяць тому

      ZX Spectrum rulez!

  • @mausmalone
    @mausmalone Місяць тому +1

    'cause the Commodore is keeping up with you! Loved how simple this was, and especially the explanation of the exec parameter termination and curly braces. I've seen so many "here's how you use find to ..." tutorials and never understood what was going on with those.

  • @user-hc6uo5fp8n
    @user-hc6uo5fp8n Місяць тому +2

    Thank you for doing these Lil' Linux Lesson and concentrating on the commands that builtin rather than the newer that are not always in the repo's.

  • @zrodger2296
    @zrodger2296 Місяць тому +2

    I need to try out a few examples tomorrow on my system, it's been awhile since I used this sequence of commands. I always used to use find then xargs then grep. Great timely video!

  • @kevinrineer5356
    @kevinrineer5356 Місяць тому +3

    thanks for the different between the + and \; !
    I know I had read that at one point, but forgot the difference a long while ago.

  • @FP_95
    @FP_95 29 днів тому

    Your teaching skills are GOD tier. Thanks for all your hard work!

  • @s.i.n4985
    @s.i.n4985 23 дні тому

    Wow, i actually think this is pretty cool that you are keep going through years! there is not so many youtubers that discuss linux and this nerd stuff, i believe in you!🥰😍

  • @klemmr3233
    @klemmr3233 Місяць тому

    Our late cat loved my C64. He was always a keyboard walker, but this was his favourite. I'm keeping up with my Commodore now, as it's safe to plug it in again.

  • @dunkinDoge
    @dunkinDoge Місяць тому +1

    saw the video couple of days ago, ended up needing this today.
    You saved me a loooooot of time and troubles. you're awesome

  • @joseoncrack
    @joseoncrack Місяць тому +1

    Useful and to the point. No annoying sponsorship. 👍

  • @zach9799
    @zach9799 Місяць тому +1

    I love your videos. So information-dense! Great point about using fundamental built-in commands on systems that you can't install unnecessary packages on.

  • @ouilogique
    @ouilogique Місяць тому

    👍 for the “+” tip.
    If you need absolute paths use "`pwd`" instead of .
    And if you want one line per result use “find” a second time instead of “echo”
    find "`pwd`" -type f -exec find {} +

  • @tuxthedev3470
    @tuxthedev3470 Місяць тому

    This video format is amazing!

  • @bruck2723
    @bruck2723 Місяць тому +5

    | column is the coolest thing i learned today.

    • @saszab
      @saszab Місяць тому

      It's called pipe.

    • @bruck2723
      @bruck2723 Місяць тому +1

      @@saszab | this is pipe, that i know . i didn't know you could column like that.

  • @kellybmackenzie
    @kellybmackenzie Місяць тому

    I adore your content so much! I always learn so much with your videos, thanks a lot!

  • @DouglasJenkins
    @DouglasJenkins Місяць тому +3

    Are you keeping up with the Commodore?
    I lol'd at "all the patience of a substitute 8th grade math teacher."

  • @dewildtvanreenen4358
    @dewildtvanreenen4358 Місяць тому

    This was quite serendipitous two days after watching your video I needed to delete a bunch of svg’s and I would not have thought of find if not for your video

  • @donaldwilliams6821
    @donaldwilliams6821 Місяць тому +1

    Great video Yes, there are newer and faster utils but at work I have much older Linux servers without access to them So knowing how to do it the "old fashioned " way is important. Plus if your scripts use them it's more portable to any system. You can always check for the presence of FD, etc and use "classic" FIND as a backup

  • @kumar_prabhat
    @kumar_prabhat Місяць тому +5

    love it, keep 'em coming

  • @jay_wright_thats_right
    @jay_wright_thats_right Місяць тому

    I love your damn videos. I can't wait to see where this channel is at this time, next year. No pressure, though!

  • @neuralmodulator
    @neuralmodulator Місяць тому +5

    Spacehog references = definite win

  • @MichaelMossmanNZ
    @MichaelMossmanNZ Місяць тому +1

    Thanks for another great vid! I'm keeping up with the Commodore ... the Holden Commodore automobile that is, formerly manufactured by GM Australia. Greetings from down-under =)

  • @ViewtifulSam
    @ViewtifulSam Місяць тому

    As to the point @ around 1:11, I'm really glad you made a video about find because the simpler stuff such as fd doesn't require much explanation and the deep uses of find seem really really useful!

    • @VeronicaExplains
      @VeronicaExplains  Місяць тому +1

      As of this moment, fd is unlikely to be in your baseline distro, container, or enterprise approved tools list. Find will be though!

  • @VexisMorlock
    @VexisMorlock Місяць тому +2

    I feel like we should mention that you shouldn't try to get to fancy with -exec; It can often lead to unwanted results. ie don't use this to rename or manipulate files on your system, but this kind of thing is fine. Also if you have not covered xargs its one of my favs.

    • @eDoc2020
      @eDoc2020 Місяць тому

      Whenever I do potentially dangerous actions with scripting I always do a "dry run" with echo before the actual command name.

  • @GoWithAndy-cp8tz
    @GoWithAndy-cp8tz Місяць тому

    Hi Veronica. I'm amazed by your passion for computers! I really appreciate your videos. Cheers!

  • @Getoverhere666
    @Getoverhere666 Місяць тому +1

    Veronica, your are the miracle!

  • @guilherme1556
    @guilherme1556 Місяць тому

    Awesome video Veronica, I loved this type of video with a specific linux topic!

    • @VeronicaExplains
      @VeronicaExplains  Місяць тому

      Thank you for the support! More videos like this are on the way!

  • @skelebro9999
    @skelebro9999 15 днів тому +1

    I really like the editing of this video!

  • @henriquepicanco97
    @henriquepicanco97 Місяць тому

    I never understood the find command... Until now! Thanks, Veronica!

  • @derekr54
    @derekr54 Місяць тому

    Great video as usual,thanks Veronica

  • @speakerbench
    @speakerbench Місяць тому

    Excellent little tutorial and I look forward to the others. I've been using Linux a bit, on-and-off since 2005, and used find regularly, but consider myself a novice.

  • @frighteningenius
    @frighteningenius Місяць тому

    yayy new linux video!!
    edit: also, congrats on the 100k :)

  • @user-ng8cx3fj5p
    @user-ng8cx3fj5p 25 днів тому

    I heard about this channel on Mastodon. I like your videos very much, thank you for your work!

  • @TechnologyJunkie
    @TechnologyJunkie Місяць тому +1

    Hard to believe it has been 30 years since the demise of C=. My A-3000 still rocks, and my C= 128 is still great.

  • @KoopstaKlicca
    @KoopstaKlicca Місяць тому

    Very useful video, thank you!

  • @ImL8
    @ImL8 Місяць тому +4

    Thanks for another entertaining video!

  • @jrpsims
    @jrpsims Місяць тому

    Nice video, and I’m happy to see people still using find.
    Be careful with quotes! The double quotes you used around *.txt will still allow the shell to expand the wildcard instead of passing it to find. You need to use single quotes, or put \ in front of the *.
    Your example passed into find a list of filenames, not the pattern *.txt

  • @Hinipe
    @Hinipe Місяць тому

    I find your explanations easy to follow. :)

  • @BryonLape
    @BryonLape 29 днів тому

    I've been using find like this for nearly 30 years. I remember when -print was required to see the filename. I didn't know it was mystery.

  • @PaulHeffner
    @PaulHeffner Місяць тому

    I've been using 'find' since the early '80s but I'm too aware how even the earliest commands "evolve" over time so I had a look. This is a nice overview of the basic command (like others, I didn't know about the '+' delimiter, that was worth the watch by itself. One explanation that would help is how the predicates of find act as a left-to-right execution queue, meaning you can list the conditions and each will be tested and if it succeeds, find will move on to the next test. This allows really useful sets of tests where you can do things like "files owned by fred larger than 1gb whose name begins with 'p'. A really nice video, thanks! (Keeping up with the Commodore)

  • @thatflutterdev
    @thatflutterdev Місяць тому

    Thanks for making this useful video, I didn't know the find command existed until now

  • @ya64
    @ya64 Місяць тому

    Didn't know about the file size option. Very useful!

  • @wingflanagan
    @wingflanagan Місяць тому

    Veronica, you are my spirit animal!

  • @careymcmanus
    @careymcmanus Місяць тому

    Recent Linux convert that"s keeping up with the commodore. Finding these videos super helpful for making my transition easier

  • @octaviolopez9966
    @octaviolopez9966 Місяць тому

    As a linux user my self, i welcome more ways to do tasks in linux wether it is with a gui or cli, the same for browsers, i don't mind using chromium or opera, firefox for websites, TRULLY NICE WORK, CHEERS FROM TIJUANA MEXICO!

  • @michaelwright2986
    @michaelwright2986 Місяць тому

    I feel I may be going back to the command line, thanks to this sort of thing. Also, at 1:30 I liked the undertaking to treat comments with all the patience of a substitute 8th grad maths teacher. That should be an ANSI standard.

  • @jameskemman5892
    @jameskemman5892 Місяць тому +4

    going straight on my to watch list :)

  • @sansmojo
    @sansmojo Місяць тому

    find is one of my most used commands. Great video.

  • @zachh1000
    @zachh1000 Місяць тому

    Hilariously I’ve just started to use find for more things since being forced onto wall, terminal is all I’ve got. Now I’ve got some more trick, thanks!

  • @jamescoulter9659
    @jamescoulter9659 Місяць тому

    Brilliant using find to find space hogs! (In the meantime, you can also find space hogs on The Muppet Show ; )

  • @ccf_1004
    @ccf_1004 Місяць тому

    "Are you keeping up with the commedore? Because the Commedore is keeping up with you!"

  • @mcatower
    @mcatower Місяць тому

    Great video! Do more useful command explainers like these please ❤

  • @cristianseres1353
    @cristianseres1353 Місяць тому

    I still have my C64, 1541 and a lot of floppies at my brother's place. Blue Max, Castles of Dr Creep etc, lots of memories.

  • @MallocArray
    @MallocArray Місяць тому

    Love these little tidbits. Easier to commit then to memory when it isn't one of 10+ all presented at once.
    Looking forward to grep

  • @ryanlemere4212
    @ryanlemere4212 Місяць тому

    Super awesome love the jams! Great info! Are you keeping up with the commodore?

  • @kid_scarlet
    @kid_scarlet Місяць тому

    great video! thanks! i'm a novice/intermediate linux user, & while man is helpful, sometimes a video that explains a command can be waaaay better than text on a screen. so thanks again!

    • @kid_scarlet
      @kid_scarlet Місяць тому

      oh, and, are you keeping up with the commodore?

  • @GeoffintheGarage
    @GeoffintheGarage Місяць тому

    Such a useful info-dense video! I just started a network tech class with a Linux portion, so these videos are super helpful and well-timed for me. Looking forward to the grep lil' Linux lesson too. Are you keeping up with the Commodore?!

  • @tomkelley4119
    @tomkelley4119 Місяць тому +2

    This is a good series.
    Also, are you keeping up with the Commodore?

  • @StMidium
    @StMidium Місяць тому

    At work, we use git quite a lot, and manually making sure to run 'git pull' before I start working on a repo gets old pretty quick, so I wrote a quick find one liner that searches recursively for the .git folder, and executes 'git pull' if it finds it. This script is set as a cron job to run every morning just before I start work. Works great!

  • @pjcpspn670
    @pjcpspn670 Місяць тому +1

    Love the humor, do the thing that makes the thing tell you when I publish the thing hahaha, Nice Vid.

  • @ericpayne2846
    @ericpayne2846 Місяць тому

    Hi Veronica! I have been subscribed and watching your videos for about a year now, and I just wanted to comment that they are very entertaining, and my favorite are the "Lil' Linux Lesson!" variety, because I have A LOT to learn and I really love it when I learn something new and useful by the time the video ends (like this one!) Thanks for making these, and I hope to see more "Lil' Linux Lesson!" videos in the near future. by the way, are you keeping up with the Commodore?

  • @MikeWood
    @MikeWood Місяць тому

    As Indiana Jones learned in the Library while questing for the grail, + does actually mark the spot. :) Never knew that.

  • @nicozica
    @nicozica Місяць тому

    Are you keeping up with the Commodore?? I understand very little of this part of the Linux world.. But your videos are always a joy to watch.. Cheers Veronica!! You're as awesome as Linux 😀🤗

  • @MrAnish310
    @MrAnish310 Місяць тому

    Great explanation in 8 minutes especially exec +

    • @VeronicaExplains
      @VeronicaExplains  Місяць тому

      Thanks! That's my goal with these, trying to keep them under 10 minutes and still thorough.

  • @malfunction5448
    @malfunction5448 Місяць тому

    are you keeping up with the Commodore? Great video! I always learn some new nuance I'm not familiar with in these lil' linux lessons 😁

  • @woritsez
    @woritsez Місяць тому

    i'm a know nothing who often struggles to find things. thank you. i'll be saving this and coming back to it for years. presuming i don't forget where i saved it.

  • @mattnik
    @mattnik Місяць тому

    Thanks so much for posting this! 🙂

  • @gyorgybereg6916
    @gyorgybereg6916 Місяць тому

    Keep up the commodore and the vids!

  • @DerekLippold
    @DerekLippold Місяць тому

    This is the kind of content I need being I have no idea how to do many basic Linux stuff

  • @HackspoilerDe
    @HackspoilerDe Місяць тому

    I find that "xargs" is more flexible and can be more powerful with options like “--max-procs (-P)” and “--max-args (n)” especially with many files and environments where a lot of control is needed

  • @andrukthegreat
    @andrukthegreat Місяць тому

    Did anyone notice the directory in which the script for this video was in, is spelled "Scirpts" good you didn 't look for the Scripts Directory. / :) . You're Awesome Veronica!

  • @moetocafe
    @moetocafe Місяць тому

    Very useful, thank you!
    Now I can list all files, bigger than say 100 MB in my Downloads folder, to easily spot the potential candidates for deletion, if running low on space:
    find Downloads/ -size +100M
    (with -ls at the end you get some additional details of the found files)