Minimalism vs. Memes on the Command Line

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right what's up everyone so I don't have my webcam today hopefully you can pay attention I'm a work so I don't have it but I want to illustrate the difference between minimalism and me minimalism because there is a difference and I do not endorse memes I endorse doing things efficiently this is sort of a response to a response video of mine there's a video by this channel distro tube and he says why use category can use awk and this all go ahead and say the video that this video is a response to is something that I said it a little bit ago I said that I see so many people doing something silly like this catting files and then piping them into other programs like grep so for example catting this file config typing it into grep to search for the sequence i 3 ok now that works but that is not the correct way to do it you crap eggs yeah you grew up directly on the file searching for i3 the results are the same but this first one is less efficient it is not only you know more characters in your script as this as if anyone cares but you're running an extra program and cat is a small program but it makes a big difference and I'm gonna show you exactly how big that differences in this video now I will say I'll make one rejoinder to some things that people said I have no problem if you are on the command line and you have just cat it out a file and you want to grep it now and so you go back up and add grep at the end I'm ok with that what I will made this original video for is for when you're writing in scripts you should always always always do it this way because there is no reason for you to have that extra program running it is pointless okay now distro tube I don't want to say he misunderstood our video is not bad I'm not I'm not downplaying it because he does talk about some of the useful things you can do with awk and said and stuff like that but I think it is replying it's missing the point of my original video because my original point is things getting done with maximal computational efficiency not running through things you know it's not about avoiding programs because what he says as well if you can avoid cat you can easily avoid grep as well cuz you can grep with a program like awk you can do something like this and that produces the same output now of course grep has extra features like you can you know highlight what whatever the matches but awk can do pretty much everything grep does now here is my rejoinder to that awk is not as efficient in terms of you know CPU usage or time or anything at grepping grep is the best program to grep worth said is not good for grepping either use grep for grepping so let me show you first I'll show you well here's what we're gonna do I'm gonna say 4x in sequence a thousand so here's what I'm gonna do I'm gonna run a thousand times the the example I just gave you a second ago first let's cat the config file into I integrate to search for a sequence oops I did not mean to actually run that so we'll cat that into that let's actually make it you know not zsh so other people can follow along so if we do that actually let me silence the output to so it's not messy because that's a big mess so we'll make whit grep quiet and I'm gonna run the command time on this entire sequence so we're gonna see how long it takes for all this to run ok waiting for a second a couple seconds okay so this ran this command 1000 times and you'll see that it took 4.2 seconds here's our CPU usage etc etc so again this is the wrong way to run it let's run at the correct way okay so we will get rid of cat and we'll run grep directly on the file let's see how long that takes ok so the original is 4.2 this is around 3.2 so that's about a second less and I think if you ran it a couple more times it would be you know still around 3 seconds I ran it a little beforehand and I think the average was close to 3 seconds whereas this was closer to 4 so basically running cat in terms of efficiency is you know 33% more time ok that's an annoyance and let me show you now distro tube does say you can grab with awk so if you're just avoiding programs you shouldn't use grandfather but that's not what I care about I care about efficiency so let's see how long it takes let's Ock this file and you know we're grepping with awk here and we'll send that to Deb no I don't know how to silence the output off the top well you could add extra options to awk I guess we'll see how this works so you'll see here this is closer to four seconds it looks actually that awk happened to be faster than catting but it is still not close to as good as grep actually just to compare apples to apples let's let's grep this to dev null I don't think it'll actually make a difference but you know whatever that's what we did with ox so that's what we should do with grep see how long this takes yep so this is actually under a little bit so you can see that they're comparable if we grep directly on a file a thousand times it takes three seconds if we do something silly like akut or you know you grep via awk or you know cat integra it takes a full second more and again that's 33% more and you know we're talking about again this is a minor optimisation I wasn't trying to say that if you run scripts with cat catting and grep it's in to the world but this one of the things you have to keep your mind on now the same thing applies to using awk this is why you grep with grep and not awk awk is a lot less efficient awk is a very nice program it has lots of great things and disor tube shows some of the things that it can do same thing is true of said but it is not if you just want to grab something do not lock it's silly and I will say there's one other thing that he mentions in this video I sort of skipped through it and it's a meme on to my channel and I want to be sure that this is not minimalism this is me minimalism ok some people based on a meme and my channel will do this said 11q a file instead of running head on it ok or capital Q whatever and the idea is this is built on the same idea oh well if you want to avoid files you can just said 11 Q basically you know set 11 Q basically says when you get to 11 quit and don't print anything out okay now you should use head instead of said 11 Q realistically speaking because I mean you can do the time yourself and you'll see pretty much every time that set 11q is gonna be it's a bigger program it takes longer pretty much all the time no it's a very small amount here but if you run a bajillion of times let's do it let's go back up here we'll say said 11 Q on config I'll put it to dev null so we don't have to see it see how long that takes taking a little bit of time that takes a look at that took three seconds now let's run head on config send it to dev Knoll see what happens now to see that took less than a second set 11 Q is incredibly stupid butt butt butt-butt-butt there are times where you want to keep in mind the fact that you can run set 11 Q or that you can grep with awk and that is if you're already running an arc command you know if you're already doing something and I get out of this if you're already running some kind of aunt command you might as well if you're gonna grep into that awk command you might as well grep with awk if you're already running awk for something you might as well do that same thing with set 11 Q don't read don't run set 11 Q in a script it's just a meme it's a joke on my channel don't do it but if you're already running set on a file and you want some equivalent of head you might as well you know tell it to quit after a certain number of lines you know quit after 20 lines or something like that so anyway this is just a minor again I just I just wanted to be clear I know some things on this channel are memes they're very funny we laugh at them but the recommendations I gave in telling people not to cat and grep that's a serious thing it's a big waste to run an extra program even if it's a small program on something it makes your scripts a lot I want you to be mindful of the scripts you're writing and think about efficiency at all times and efficiency often is avoiding using programs that are less efficient like awk that again can do more things and using programs like grep that again do one thing and do one thing only and they do it well and they do it efficiently they're written to be that way arc has a bunch of other stuff you don't need it anyway that's about it I'll see you guys next time just wanted to make that stuff clear
Info
Channel: Luke Smith
Views: 83,330
Rating: undefined out of 5
Keywords: minimal, software, linux, terminal, command, line, prompt, sed, awk, tutorial, head, cat, grep, core, utils, unix, macos, efficient, efficiency, code, program, memes, suckless, cpu, time
Id: 4bezl5gXAcg
Channel Id: undefined
Length: 8min 56sec (536 seconds)
Published: Wed Dec 04 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.