Demystifying "find" and "find -exec" ...Lil' Linux Lesson!
Vložit
- čas přidán 12. 06. 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 - Věda a technologie
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?"
Keeping up with the Commodore would be a reality show I would actually watch
In my 30 years as a sysadmin, I've never heard of the +. I've always used the \; when using -exec. Thanks.
37 years for me. I can't wait to soup up my automation scripts with + lol
Only 28 years here, and I also just learned about + from Veronica. ✌️
Only 25 years here, and I always used \; too. I'll be trying the + now. Thanks, Veronica!
hah, wait until you hear about -execdir
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!
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!
@@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.
Ha, I learned vi on AIX 3.2 in '97
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.
@saszab mc is great for interactive use but extremely unhelpful for shell programming.
@@DavidSchmitt Sure, but these are vary rare cases. Vast majority of the Linux users never write scripts.
I like the part where veronica says "its explaining time" and explains all over the place
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!
Same here, I always tended to use -print0 and pipe it to xargs -0. Thanks Veronica!
This was a real "+" for a topic. I use "find" nearly every day and did not know it has alternate endings \; Thanks.
It's a good day when there's a new video from Veronica!
As someone who was "cool" in the mid-nineties, I appreciate the spacehog based puns.
I figured there was only a few who would get it.
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!
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!
The + in my command executes once though.
@@VeronicaExplains I also learned this trick for the first time after using xargs for years. I gotta RTFM a bit more. 😁
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)
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
I believe neither ‘+’ nor xargs necessarily put all the files as arguments to the command but parcel them up with respect to MAXARGS.
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.
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 +
Been a Linux user for 20+ years. Love your videos and how you extend your knowledge to newer users. Keep it up.
Your no nonsense explanations are great!
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.
SHE'S A LIGHT IN THE LINUX COMUNITY !
LIKE THE GUY FROM "THE LINUX EXPERIMENT".
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!
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.
Ah, but would you admit that on a CV? Right after knowing how to configure sendmail, without the help of m4?
Are you keeping up with the Commodore?
Love your channel ! Very informative and entertaining !
Thank you! I have it on good authority that the Commodore is keeping up with us.
Never knew Gilda Radner was so into Linux. And still alive for that matter.
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!🥰😍
Great video, looking forward to the grep episode as well. Are you keeping up with the Commodore?
I was wondering the same thing!
Been using find for 25 years and still learned something new (+). Thanks!
Thank you, Veronica! I’m finally taking my first steps into Linux and you’re helping me ‘find’ things along the way!
'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.
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.
Your teaching skills are GOD tier. Thanks for all your hard work!
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!
Useful and to the point. No annoying sponsorship. 👍
Using “find” with -exec is so powerful! I’ve been using it since I first discovered it in a Unix manual in 1985. Whew!
thanks for the different between the + and \; !
I know I had read that at one point, but forgot the difference a long while ago.
The moment I learnt how to use find, I felt like I had unlocked a superpower.
saw the video couple of days ago, ended up needing this today.
You saved me a loooooot of time and troubles. you're awesome
This video format is amazing!
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.
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.
👍 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 {} +
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
I adore your content so much! I always learn so much with your videos, thanks a lot!
"Have you played Atari today!"
(No commodore because I'm a rebel. "
ZX Spectrum rulez!
Hi Veronica. I'm amazed by your passion for computers! I really appreciate your videos. Cheers!
Awesome video Veronica, I loved this type of video with a specific linux topic!
Thank you for the support! More videos like this are on the way!
I love your damn videos. I can't wait to see where this channel is at this time, next year. No pressure, though!
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.
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!
As of this moment, fd is unlikely to be in your baseline distro, container, or enterprise approved tools list. Find will be though!
| column is the coolest thing i learned today.
It's called pipe.
@@saszab | this is pipe, that i know . i didn't know you could column like that.
Great video as usual,thanks Veronica
yayy new linux video!!
edit: also, congrats on the 100k :)
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 =)
I heard about this channel on Mastodon. I like your videos very much, thank you for your work!
This is a good series.
Also, are you keeping up with the Commodore?
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
love it, keep 'em coming
Veronica, your are the miracle!
Huge thank you for this, wasn't aware of the "find" command before the video. Really love your Lil' Linux Lessons BTW. -PS Are you keeping up with the Commodore?
I never understood the find command... Until now! Thanks, Veronica!
Very useful video, thank you!
Super awesome love the jams! Great info! Are you keeping up with the commodore?
I find your explanations easy to follow. :)
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
Thanks for another entertaining video!
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.
Spacehog references = definite win
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 😁
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?
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)
Great video! Do more useful command explainers like these please ❤
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?!
When Veronica tells me I'm awesome it makes my day ☺
btw, are you keeping up with the Commodore?
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.
Whenever I do potentially dangerous actions with scripting I always do a "dry run" with echo before the actual command name.
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 😀🤗
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.
Love the humor, do the thing that makes the thing tell you when I publish the thing hahaha, Nice Vid.
Veronica, you are my spirit animal!
Another interesting and informative video. Are you keeping up with the Commodore?
Thanks this is very helpful! I like these Lil' Linux Lessons. Also are you keeping up with the commodore?
Keep up the commodore and the vids!
Great explanation in 8 minutes especially exec +
Thanks! That's my goal with these, trying to keep them under 10 minutes and still thorough.
Awesome explanation! thank u so much! and....Are you keeping up with the Commodore??!
Thanks! A very nice summary of an essential command.
I'm hoping that in a follow up you can find a way to cover options like -mmin and -mtime as I find those very useful when looking for recent changes. Given that like many others I didn't know about the + terminator for -exec I wonder if I'm missing some magic in date and time handling too?
Also, are you keeping up with the Commodore? He's pretty quick for his age, but doesn't get to sea very often these days... ☺
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.
going straight on my to watch list :)
find is one of my most used commands. Great video.
Thanks for making this useful video, I didn't know the find command existed until now
Didn't know about the file size option. Very useful!
Thanks so much for posting this! 🙂
Just what I needed. Thank you so much.
Are you keeping up with the Commodore.
Brilliant! Thank you for the lesson. I'm trying to keep my Music directory tidy, and using the find command you provided helped me to find .MP3 files (which work, but the perfectionist in me doesn't like the all caps file extension).
Are you keeping up with the Commodore?
Great video!
Are you keeping up with the Commodore?
+ vs \; I didn't know, thank you for a great little video, Veronica. I was looking to see if there was CP/M for the c64 the other day, are you keeping up with the commodore?
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!
I absolutely adore your content. As a former *nix admin myself, I really appreciate the perspective. Your teaching style is amazing. Are you keeping up with the Commodore?
Recent Linux convert that"s keeping up with the commodore. Finding these videos super helpful for making my transition easier
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!
Very useful video, love it.
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.
Great video and very handy information I'll actually put to use. And Hey, are you keeping up with the Commodore?
Are you keeping up with the Commodore?! Great stuff, thanks very much!
Brilliant using find to find space hogs! (In the meantime, you can also find space hogs on The Muppet Show ; )