 Hello, and welcome to the story from filmsbychrist.com. That's Chris Decay, link in the description. Last video I showed you some examples of progress bars that can be used in your shell scripts. Today we're gonna be going over some of those progress bars and seeing how they work. You can get the scripts from today's video and from the next few videos at my GitLab page that's gitlab.com forward slash metalx1000 and to search for my project bashell progress bars. Once you've downloaded those, move into that directory and today we're gonna be looking at using PVs. So let's look at our two examples again. So we have one with no ETA, which is just giving you a count of what we've gone through. And then we have one with an ETA, which we'll calculate out the number of files, give you an estimated time, blah, blah, blah. Let's look at that first option with no ETA. Again, to get an estimated time and actual percentage, you need to have a total of what you're going to, what your goal is, how many megabytes you're moving, how many files you're moving, some sort of count. But if you don't know, you can still give the user some sort of visual output so they know what's going on that something is moving and things haven't just frozen. So let's look at this. There's actually two examples in here. So if I come in here and in fact, I'm gonna put a little read command in here to stop that. Now I'm gonna run that command again. So the first one runs, it doesn't take very long. You know, it says 87 megabytes and it took two seconds and then it was done. If I hit enter now, it will start with the next one. And I basically broke this up into two things to show you. It's actually doing the same thing. I just slowed one down so that we have a longer progress to look at just as a better example. So I'll hit control C to stop that and I'll go back into here. So what are we doing here? Well here we're running the find command and I'm searching basically listing out every file on my computer that my user has permission to read. We're gonna dump any errors into Dev and O so they don't come out and we're just passing it to PV. So basically you pass any information to PV and it's gonna start just giving you a progress of how much information has been passed. And then I'm actually dumping all that to a file. So I'm catting that into a file. So basically we're listing all the files, we're putting them in a log file. That is our process. We wanna get a list of all the files on our computer and PV is just giving us, you know, a progress that things are moving. But again, that happens pretty quickly. So as another example, I put the same thing into a for loop, or a find a while loop, find the for loop, a while loop. So again, we're still just listing out forward slash our every file on our directory dumping all errors Dev and O. But instead of finding it directly into PV I'm echoing out each line into PV in a loop and putting in the cat and dumping into file. So I'm doing the same exact thing but in a much less efficient way. This is also a very good example about how if you can avoid loops sometimes it's a good idea to avoid loops because it takes a lot longer for it to loop through all this and cat it out and have all those breaks and whatnot in there. But I did this on purpose just to show the progress bar. Otherwise it just happened so fast you don't really even get a chance to enjoy it. So like this is the first progress bar. It's done already. It's gonna do the same exact thing but slow it way down just so we have time to enjoy our progress bar. So that is an example of using PV when you don't have a total count. Now again, when you're counting with PV you can count out a percentage. You can count out, or count out percentage, we can count out how many megabytes are moved if we know the total number of megabytes or whatever size the files are. Or we can give a count if we know that we have 200 files we can then count each file up to 200. So let's look at our second example here, PV with ETA. So here I'm sourcing, I have a source directory which it has a bunch of photos in it. Then we have a target directory where we're gonna copy stuff to. Now again, to get some sort of percentage bar I need to know the total number of what we're moving. In this case instead of calculating out megabytes I'm calculating out the number of files. So I'm taking our source directory and I'm listing all the files and I'm using WC to list how many files are. So we'll get a count of how many files are. I think there's an example on my machine there's 174 in this directory. Okay, then I'm gonna make a target directory. I'm using dash P to make sure I don't get any errors if the file already exists or if I need to create multiple subdirectories. And then I'm just gonna echo out just so the user knows that we're copying this many files, our count from our source directory to our target directory, okay? This is our main thing. So all we really need in here is we need our total, our count and then we're going to copy from our directory to our source directory. We're using the V command here. So the V command is verbose. That means it's going to list out each file that's being copied as it's being copied, okay? Then PV, what PV is doing, we're saying dash L that means count the lines, okay? So every time a new line comes in, so every time a new file is copied, count that line. And then dash S, we're saying this is our total. And then PV does the math for you and will give you a percentage as it's going. So let's go ahead and run that and it says 104 files and you see it didn't take very long and it copied some files. Now, why did it not get to 100% and that is probably because some of those directories already existed. Let's go ahead and delete our directory that we're copying to, run it again and see what happens. There we go, we got to 100% that time. That's because I was copying and some of the files or folders didn't need to be created because they already existed. So, but still we got that. We got, we see how many seconds it took. We see the total number of files copied. We were able to see as it was going, you can see the count going 100, 128 and then we get to 100% when we're done unless, again, my example, we copied a second time so some files already existed so things didn't get copied. But we get that output there. You may wanna make sure, take into account that because I'm like, oh, why did it stop at 95% so I didn't realize I was gonna do that till I started recording this and I ran through the command twice. But those are two examples of using PV to get a progress bar, whether it's just giving you a visual of what something's happening or giving you an actual count down with a percentage. So again, you can get these scripts, gitlab.com forward slash metalx1000 and the project is called Bash Shell Progress Bars. If you go to filmsbychris.com there's a link in the description, that's Chris of the K. You can also go to my software section and there's links there to my GitLab, to my notes on Pastebin and some other places where I post stuff that you guys can download and play with. I thank you for watching and please visit filmsbychris.com and I hope that you have a great day.