 Learning the command line is one of the most important things you can do as a Linux user. Today I'm going to cover five command line utilities. All five of these programs are actually part of the GNU core utilities that is installed on practically every GNU slash Linux distribution. And these five utilities I'm going to talk about today, they are hostname, uname, basename, dearname, and logname. So let me switch over to my desktop and I've opened up a terminal here and zoomed in so you guys can see this. Now let's start with uname. Now uname all of these programs end in name in the title. So I've got uname, hostname, basename, dearname, and logname. Now the name implies that we're going out and finding the name of certain things on our system. Certain file names, directory names, in this case uname prints out various system information stuff. Uname with no other argument, it gets me what kernel is installed on this operating system and the kernel I'm using is just the generic Linux kernel. So naturally uname with no other argument just returns Linux. Now typically what you want to do with uname is you want to get all the information available through uname and you do unamespace-a for all and it gives you much more information. We get the Linux kernel return. We also get my distribution, arco-linux. Then we get the actual version number of the Linux kernel. In this case I'm using 5.15.34 LTS, I'm using the LTS kernel. Then we get a date and time here and that is the release of that particular version of the kernel, x8664 of course is the architecture for the CPU. And then finally gnu slash Linux is the type of operating system we are running. So I'm on a gnu slash Linux distribution. Now one of the most common uses for uname is simply getting the version of the kernel currently installed on your system. And that's done with uname-r and you see it strips out everything else from the uname command. It just returns 5.15.34 yada yada yada dash LTS, it gives me the kernel version. And this is really important for scripting and for customizing certain things. For example in my tiling window managers a lot of times I like to put the version of the kernel that I'm on right here in the panel. And how do I achieve that? All this widget here in the panel that has the little ping one out to the side of it and tells me 5.15.34 dash LTS, all that widget is doing, it's running this command here. Uname-r, right? It's just a simple shell script and it's a one line shell script essentially. It just runs uname-r for me. And you can strip out any bit of information from this command. And if you want more information on uname just do a man on uname and you can see there are all the flags. There's about eight or ten flags that will strip out each individual part from the full uname command. So that is uname, very simple command. And it's something, again, the most common use of it is simply to get the current version of the kernel that you're currently using on your system. Let's move on to hostname. If I run hostname, my hostname on my computer is ArcoLinux. That's just what I assigned as the hostname when I ran through an installation of ArcoLinux on this machine. So if you're new to Linux or you're just unsure exactly what a hostname is, a hostname is basically it identifies your computer. So these days, many computers are part of a network. And imagine that you have a local network that has a dozen different computers. How do you know which computer is which? Well, each computer should have its own unique hostname. That way you always know which computer you're working on, on the network. So that's why when you're installing your GNU slash Linux distributions, you typically, you have to create a user for your account. So when I installed ArcoLinux, I told Arco that my username would be DT. That's the username on my system. And then I gave it a hostname because you always have to enter a hostname for your computers during installation. And I called this machine ArcoLinux for a hostname. Because most of my equipment, I'll have different GNU slash Linux distributions installed. So if I remote into this machine using SSH, because maybe I'm at my home computer and maybe it's running Ubuntu, and I SSH into this machine, the prompt will actually say DT at ArcoLinux. That way I know the commands I'm executing are actually executing on this machine, where the home machine maybe that I was running Ubuntu on will say DT at Ubuntu, assuming I assigned that machine the hostname Ubuntu. And most of the time, your shell prompts will actually be in this form. I just typed out user at host. So your username at hostname. And where is the hostname actually set on your system? Those of you that have done minimal Linux installations, like on Arch or Gen2, things like that. Typically you have to manually set your hostname. And how you do that is that's done through just typing a hostname in a file. So if I open with VM slash Etsy slash hostname, this file here, you see I have one line here, one word, ArcoLinux. That sets the hostname for this computer. So that is in slash Etsy slash hostname. And because sometimes you need to get a hostname for our computer you're working on, especially when scripting. Now we have this core utility that you can add to a script and immediately get the hostname for whatever computer that script is being executed on. There's really not much else to the hostname command. If I do a man hostname, let's get the man page. It does have some flags and some options. I have never used any of these flags or options with hostname. The only thing I've ever done with hostname other than just doing hostname to get the hostname of a machine is sometimes you want to change temporarily the hostname of a machine. So you can actually do hostname and then name it something. I'll just something here. And that will temporarily change the hostname of this machine. So I'll no longer be DT at ArcoLinux. If I execute this command, my hostname will be DT at something. If I hit enter, it says operation not permitted because you need sudo privileges to make this change. So let me go ahead and do that. And now when I run the hostname command, you will see the hostname of this computer is no longer ArcoLinux. Now it is something. Now here's the problem. This is temporary. When I reboot the computer, my hostname will still be ArcoLinux. So this is a temporary change of the hostname. If I do VM slash Etsy slash hostname, you see this file still says ArcoLinux because that's really what the hostname is again. So when you change it using the hostname command, that's just a temporary thing. As soon as you reboot the computer, your old hostname will actually be in effect because that is the one that's actually saved in the slash Etsy slash hostname file. Now let me clear the screen. Now let's get into some of the more interesting stuff I found especially useful for scripting. And let's start with base name. What does base name do? Base name strips a file name from a lengthy file path. For example, if I did, I don't know, base name. Well, let's just fill out this. This exists on my system slash on slash dt slash download slash 100k YouTube ping. That was the thumbnail for my 100k subscriber video. If I hit enter on that, you will see exactly what base name does. That is the name of file, right? It stripped the name of the file from this lengthy file path. And that is extremely useful when you're scripting. Some other things you can do with base name. If I give base name a path, instead of giving it a path that actually ends in a file or whatever, I can give it a path that is actually the path to a directory and watch what happens. It still strips out the very last field, in this case downloads, which is a directory name. So you can give it a path to a directory. It'll still work. You can give it a path to a file that will work as well. One other really neat thing you can do with base name is you can actually get rid of the extension of the file name. And that is something extremely useful. How many times do you need to strip out a file name in a script? And you want to get rid of the extension, the dot txt, or in my case here, this dot png. Well, I can just tack on at the very end, space dot png, meaning strip that out. That's a suffix I want removed from the file name. And now you see, now it just returns 100k dash YouTube without the dot png at the end. A utility similar to base name is dear name. So I can give dear name a path. I can give it, well, if I can type slash home slash dt slash downloads. Watch what happens here. So instead of printing the last field, like base name does, dear name prints out everything but the last field. So it's the path all the way up to the parent directory. This particular core utility, I don't think I've ever really used that much. I mean, I know it exists, but it doesn't really have any flags or options. I mean, what I just showed you is pretty much it with dear name. The final utility I want to cover is log name. Let me run log name, and it returns my username. Essentially, log name returns the name of the user that logged into the system. Typically, to get your username, you will typically do something like echo dollar sign user. You know, what user is a shill variable, it's always defined. It should return your user. So what is the difference between log name and then just echoing dollar sign user? Well, they're slightly different. Again, log name is the user that you're logged in as. So anytime I run log name on this computer after I've logged in as dt, that will always return dt, which is really important in scripting. Because user is the user ID that you're working under, that you're currently working under, which I can change users on my system, right? I could switch users. I could switch over to the root user, for example. And, you know, echoing the user might be different if I'm switching to different users on a system where log name, if I log in as dt, log name should always return dt. And if I do a man on log name, if I can spell it right, there really is nothing else to see with log name. There's no real flags or options with it. The only thing you can do with it is simply type the word log name. And again, it should just return the user that logged into the system. So five really simple GNU core utilities, host name, you name, base name, dear name, log name. There's not much to them, but you will find them immensely useful, especially once you start getting into shell scripting. Now, before I go, I need to thank a few special people. I need to thank the producers of this episode. Devon Gabe James, Maxim, Matt, Michael, Mitchell, Paul, Scott, Wes, Alan, Armoredragon, Chuck, Commander, Reggie, Diokai, Dylan, George, Lee, Lennox, Ninja, Mike, Erion, Alexander, Peace, Argent, Fedor, Polytech, Riala, Teets for Lutz, Red Prophet, Steven, and Willie. These guys, they're my highest tiered patrons over on Patreon, well, these guys, this episode would not have been possible. The show is also brought to you by each and every one of these fine ladies and gentlemen. All these names you're seeing on the screen right now, these are all my supporters over on Patreon because I don't have any corporate sponsors. It's just me and you guys, the community, if you like my work and want to see more videos about Lennox, free and open source software, core utilities, subscribe to DistroTube over on Patreon. Peace, guys.