 Welcome in the last video. We did a short little video on shuffling files and their contents using the shuff command. And you can pass anything to it. So I can say, you know, I should be able to say, this is one, backslash new line, this is two, backslash new line, this is three, backslash new line. And I can pipe that into shuff, and it will shuffle those, the output there, including the blank line at the end that I put in for some reason. So you can shuffle anything, but right now we're looking at shuffling the contents of files and file names, and mainly looking at file names. So let's say you have the list of files like I have. So I have a couple of ones that are .txt and without .txt all numbered so we can know when the orders are getting shuffled easily. And we can obviously, if we wanted to do something to a number of those files, we could pipe them into different commands, different ways. We're going to look at three different options here, or really two options, but different techniques. Anyway, we're going to say the shuff command, which again should be in your repositories, probably not installed by default, I can do dash en. So the e says we're looking at the file names, not the contents of the files. And n is the number of outputs. So we're going to limit it to four. So we're going to shuffle up the names of these files. We're going to say every file in this directory. But we're only going to look at four of them. So it's going to shuffle them all up and give us four as the output. So let's say we want to run that through a command. And right now I'm just going to echo up the name, which is going to give us basically the same results. But you can again put these into any command you want. I'm just using the echo command as an example. So we're going to say, but we're going to use a while loop here first. I'm going to say while read and then we're going to create a variable. Hopefully you know how while loops work at this point if you're watching this tutorial. If not, basically it's going to loop through each line. So we're going to have four lines going to loop through. And it's going to take the each line and put it into the variable F. And then at this point, we're just going to say echo. Oops, hit enter instead of quotation mark, dollar sign, F. And I'm just using F as the variable. It can be anything you want within reason. And I'm just saying F because it's the file name. Done. So, oh, forgot the do command. Sorry, do. No, where am I? I'm sorry. I'm messing this all up. The do command goes after the while. So let's explain this since I've just totally confused you. We're shuffling up all the file names and outputting for them. We're going to put them through a while loop. And each line is going to put a variable called F. And each time it loops, it's going to do this. It's going to echo the file name, then done. And we get this, which looks a lot like the other results. But like I said, you can use any command in here that you want or group of commands. But we can say we can do something like the blank file is selected. So now, instead of just getting the names of the file, we're actually putting it in a sentence. So we're using the echo command. But again, this is just an example. So the while loop works. But while loops can be used a little more processor than you need. You can also use a program called xargs, which I've talked about in the past. And xargs is spelled like that. And then what we're going to do is we're going to do dash capital I, percent. And I'm going to say echo. I'm going to say file selected. Well, and then we'll say, in this case, percent. So basically what we're saying here is we're going to pipe each line, the four lines that were output into xargs. And then we're going to take each one of those, put them into basically this percent symbol is going to be our variable instead of our dollar sign f as in up here. And we're going to be passing that to our echo command. So it should print out four lines there. There we go. And we didn't have to loop through it. xargs took care of that for us. It just ran that process four times. And depends on what you're doing. If you're running a lot of things with it, you might want to run it through a loop with multiple lines or even better yet, in some cases, create a function and then use xargs to pass it to the function or external command in the script that you wrote. But let's look at another way of doing this. Let's say we wanted to move four of these files. So we have all of these files. How many files is it? We'll count it out here. We have eight files. Let's move half of them. Let's move four of them to a new directory. Let's do this. We're going to make a directory. Let's move them all to a directory. We'll call this one start. And we'll call this one done. And right now, we'll move all of these into start. Sorry. That's straight. So now if we list out, I've got two directories here. And if we list out what's in start, we can see all our files. And let's randomly move half of them from start into done. So we'll use our Chef command. We'll do dash e saying we're looking at the file names, not the file contents. We're going to say dash n that we want for output. We're going to say we want you to look in the start folder at all the files in there. If we do that now, you can see we're just randomly listing out four files from that directory. So now I'll pipe that into x args, not z args, x args. And we're going to do dash 0. And we're going to say move dash t. And then our destination will say done. So if I want to randomly move four files from the start directory into our done directory, I did something wrong. Apparently, my notes are wrong. Let's try just using the method we used before for echoing it out. So let's just change this. Before we use the capital I, which takes the string and converts it over into whatever we're about to pass. It will say percent in this. That's just how I learned how to do it. But I'm pretty sure you can use any character you want there. We'll look at that in a moment. Percent done. So here we're echoing out each line, randomly shuffling for them. x args is taking each line, converting it to putting in a variable called percent in this case, moving percent to done. No errors, list, done. If I do that again, it's going to move the last four files. So we'll do that. List and all four files are in there. So let's move everything from done into start again. So we're back to how we were if we list out there's nothing in done. And then there is something in start. Let's run that command again. And again, what we're doing here, x arg dash i is taking the string. So I'm pretty sure let me do something like this. This is commonly used as well. Basically, it's saying the next string we give it is what we're creating the variable called. If we list done, now there's four random files. Doesn't seem very random in this particular case. Let's move. Yeah, let's do that again. Pretty sure that's just coincidental. Do that. There we go. It is random. It would just happen to move the first four files like that over. And if we do it again, let's go ahead. We should be able to actually, let's see if this works. I'm not sure if this will work. Yeah, no, that didn't work. We're just testing out, testing stuff while doing its role. Not a great idea. There. Now all our files have been moved over to here. So to explain it again, we are shuffling dash e is saying we're looking at the file names. We're looking at all the files in this directory. And four is saying we only want four output. Then we're passing that to XR. We're using the dash i option, capital i, in XRs, to say each line is put into a variable now called percent. Then we are moving one at a time percent into the folder done. I shouldn't have called it done because now that looks like it's part of command. But that's it. And it's giving us an error now because we've already moved all the files out of that directory. Anyway, I hope I didn't confuse you too much. I hope you found this useful. And I hope that you have a great day. Please visit filmsbychrist.com, Chris the K, link in the description.