 Let's learn the basic commands for looking at and finding file information and stuff like that and playing around with text files on, you know, macOS, Linux, any Unix-based operating system. You know, the magic of a Unix-based operating system is supposed to be everything is supposed to be text streams. Just in case you don't know, I don't know, maybe I should explain. All of your system config files, if you go to your config folder, you'll have a lot of directories for the different programs you run, all of the system information is actually stored in text files. The real interface of your operating system is actually text. It's not, you know, the little graphical environments you click on and it's nice to be able to start modifying those and learning the principles of how you play around with files and text files specifically. So let's do that. All right. Let's start at a basic level. So here I am on the command line. You probably know there are some commands, you know, like LSL that can show you some file information. So for example, you know, here's the files in my home directory when they were modified, their approximate size, you know, their permissions and stuff like that. Let's say we want to do a little bit more than that though, okay? One command that's very basic is the command file. Probably does exactly what you might think. It actually tells you basic info about any particular file. Let's say I run it on this PNG file, rss.png. What does that do? It actually tells you some stuff about it. It tells you, okay, this is definitely PNG data. It doesn't just know that from the PNG extension, but also how the file, you know, what it is inside. It tells you how big it is. It's resolution. It tells you some other data as well. You can run file on text files. So for example, this text file, it'll tell you how it's encoded. It also tells you some particular information like, oh, it has very long lines. That can actually be important for some commands, for some, you know, for different things. I'll just say that. Or this one happens to be an ASCII text file. It's an HTML document. Or we can run it on the screencast file that I'm currently recording. And you'll see some information about that or even this audio file will tell you what audio information. Now the use of file is, of course, now you can look in the manual file as well and you'll learn other options. For example, B is a good option. It doesn't show. So if you just run file, it'll show the file name. If you run it with B, it won't. And there are other options. Check the manual on file for all of them that gives you, you know, gives you very specific information or only parts of it. Just to be clear, the use of this is if you're modifying something in a script or on the command line, file can tell you, you know, let's say you need to know how big your image files are and to decide what to do with them. Okay. Well, you can use file or similar program to get that information. So that's very handy. All right. So that's file. We're looking at text files in particular. So the command you usually learn at the beginning is cat because cat can, you run it on a text file and it outputs all of it to the command line. Now technically what cat is supposed to do is concatenate files. So you could run it on multiple files at the same time. Let's say this and then that file and then do I have any other, I don't know, I'll just run that. So that will put the output of both files out here, okay? Now cat is usually used for looking at files but as you can see, oh man, there's just so much junk everywhere. That's not very readable by me, a human. So you might actually prefer using less, okay? So less will take either a text stream or a file and it will let, if less is called a pager, it lets you go through a file, you can go up and down with Vim keys or arrow keys and you can actually read the content of the file and this is handy for very big files. You can also use it on output as well. So just as an example, let me get a bunch of file output. I'm going to run the locate command and I'm going to look for a CSV file or a file that has CSV somewhere in it. So if I run that, it's going to go through all of my files, actually it should be clear if it didn't do anything, if you ran locate, run this command update db and basically what locate is, it is update db, actually update db, makes a little index of all the files on your computer and then locate allows you to search through them very quickly. So again, let's say we're looking for a CSV file, oh that's too much to go through, I don't want to have to page up and page down on my terminal. I can actually pipe that into less and piping, we're going to be doing a lot of. Piping is like the true power of any Unix-based operating system but right now it just seems sort of arbitrary but just know you can pipe it into less and you will be able to page through it, okay? Now actually I'll show you even more basic piping, let's say specifically, I know that there's a file, I know that there's a file called Domain CSV somewhere in here. Another thing you can do is you can pipe it to the program grep and you can give grep a sequence to look for, let's say domain and it will take the output of CSV or locate CSV and it will search only for the lines that have that match in them and it will return it, return only them to us. So if you only want a sliver of information, grep is the best thing to do with this. Or even, you know, grep can be run on any command, you know, let's say we have df which shows us all of our file, you know, our mounted devices and stuff like that. Let's say I'm only looking for the one on media, just hypothetically, there are other ways to do this within df but I can just run it like that and it'll only give me the lines with media in it, okay? But anyway, so let's go back here and let's say I want this file, okay? So I'm going to copy this and I'm going to say copy that file and if I want to move it to my current directory, I just press period and that moves a file to my current directory. Notice if you are just watching from my previous videos, notice I have this weird output going on now. Like it's telling me what's happening. Usually by default it does not have, you know, if you copy a file it's just going to copy it silently. The reason I have that is because I have set up an alias to copy where I automatically have these options in it, okay? That's what, in v is the option that says, you know, b verbose always tell me what's happening and I do this with other commands as well. I just like it. I don't know, why not? So anyway, now we have this domains file here. Now the reason I brought this here is I actually want to do, I want to play around with the command cut, okay? This is another excellent command, not just for looking at text, but it also, okay, in this case, you know, our file here, domains.csv, let's look at it. It's actually a CSV file, meaning it's sort of like a big spreadsheet where each of the cells are separated by commas. So here, for example, each of these is an email address or like an email domain and then the second column is its IMAP server, then its IMAP port, then its SMTP port and, or server and port. IMAP is basically, you know, storing and downloading mail. SMTP is sending mail, basically. So let's play around with this. Let's say I'm running a script and I only want the IMAP server and the IMAP port. Those will be the second and third columns in this file here. Well, I can use the cut command and what I can tell the cut command is this. I can say, okay, use the delimiter column or comma, that is, I'm saying it's not, you know, separated by tabs or semicolons, it's separated by commas. So use the delimiter comma and print out the second and the third columns. And if you do that, oh yeah, gotta actually give it a file. If you run that on domain CSV, you'll actually see that it finds only the second and the third column. So that's a nice programmatic way. If you're in a script or even if you're just on the command line, if you want to just look at particular parts of a CSV file, you can do that easily with cut. All right, let's play around a little more. Now you could do this cut is usually for looking at files separated by, you know, some kind of delimiter. But let's look at this other file that I printed out earlier, this thesis file. This is one of my friend's theses that I'm formatting for him in LaTeX. But this is the plain text file. So we can also play around with this. Like, you know, we can cat this. And I mentioned piping, you can pipe things to other programs. Now his thesis is on, you know, it's basically on the Gospel of John. So there's biblical stuff in here. So let's look for a term that we know that's gonna be in there. Let's say we grep for the sequence Jesus, okay? Now that is gonna output only the lines that have Jesus in it, okay? Again, we're piping again. So this is a nice way if you wanna find some instances of some kind of sequence or something like that. Or we can even pipe this. Let's say we wanna be able to scroll through all of those in less. We can actually pipe this into less. And now we're looking at the text, but only the lines that have Jesus in them, okay? So that's another little thing you can do. Let's play around with this even more. Let's play around with the tr command, okay? Let's say I want to make this thesis look like it was written by an old boomer who always uses caps or something like that, okay? One nice thing you can do. This is just a general text modification command. You can use the translate command. And translate doesn't translate languages. It translates characters or series of characters. For example, let's say we output this file generally. Let's say I wanna replace every w with a j or something like that. You could do something like this, tr w with j, okay? So now this guy witherington is now jitherington, okay? You can also do something like this. You can say let's replace every lower case character with its uppercase equivalent. That's what this little thing is saying. Now if I run that, it's actually gonna make the entire thing uppercase, all right? That's just another little thing. Again, all we're doing is we're piping all the output cat into this file here, which is tr. Now in tr's case, tr has the take standard input. But in grep's case, now notice that I catted, you know, when I was looking for Jesus, I catted that into grep. Now you guys know, if you watch my channel, this is actually not the way that you should do this because grep can actually just run directly on files. So you can do this. You can, you know, basically give grep the argument Jesus and then tell it to search this file. You don't actually need to cat into it. It's not a big deal if you do that on the command line, but when you're writing scripts, it's very important to economize, like, not using more programs than you need to. Even though cat is gonna run very quickly, you'll want to grep directly on this file. Okay. So I think that's about it. We're just sort of looking at files. We'll do more writing to files. Actually, you know what? Maybe we should write to, well, yeah, we'll write to files. Why not? All right. So let's do a little bit more. As I showed you, you can output all of this stuff. You can get all the lines with Jesus in them. Let's say I want to put those into a file. So I'm gonna put these in a file called, you know, Jesus log. So now there's actually a file called Jesus log on my computer. And that just lists out the, again, those lines from that output. So that's a way of writing to files. Additionally, now there is a difference. Let's say I want to do, you can do that with any command, I should say. So let's say I want to write the output of ls to a file. Well, I can run ls and then I can put it in a file ls.log. Now notice I did something different here. In this case, I used one bracket thing in it. And in this case, I used two. Let's find out what the difference between these are. So if I cat out the content of this, it seems, okay, that's exactly what I output it to this file. But if I rerun it again, if I output ls once again to this file, it will actually now have two instances of it, okay? And that is whenever you run, if whenever you output a command with two of these little brackets, it seems weird to call them brackets when they don't have a friend on the other side, but if you, whenever you out something with two brackets, it will output that content to the end of the file, okay? Because let's say you do this, let's say you echo, you know, just Jesus with only one carrot thingy to, you know, the Jesus log. What does it do there? Now Jesus log a second ago just had all of that content in it. But now if we look at the content of Jesus log, it actually only has Jesus. That is if you use this, if you use only one bracket to output to a file, it actually, instead of writing at the end of the file, it writes at the beginning of the file. And that causes everything else to be deleted, basically, okay? So that's the difference between, you know, using one bracket and two brackets. Now you might say, oh no, that's scary, dangerous, because I might accidentally totally delete file content and stuff like that. And I mean, yes, that could happen, but really this is, this is very useful if you're, let's say you're running some command that gets output from the internet and you want to put it, you want to store that in a file and you need to update every once in a while. You always want to output it with the single bracket because you want it to, you know, erase previous data. That goes for a lot of things, but if you want a constant log of information and errors and stuff like that, you want to have two, two little brackets. All right, so I think that's about enough. I think it's about time for us to get into hardcore piping. So I think that's what we'll do in the next video, what maybe said, maybe even AUK. I don't know if I'll do AUK yet, but, you know, said and stuff like that. So see you guys next time.