 One of the most common questions I get from new delinix users is, hey, how can I become a power user? Well, I think the key to becoming a power user is to learn the terminal, learn the terminal commands, and I think one of the keys to becoming more proficient at the terminal is to actually learn the power of bash aliases. So today what I'm going to do is I'm going to take a fresh virtual machine installation of Ubuntu, and what I'm going to do is I'm going to take the Ubuntu default bash config vol, the bash RC, and I'm going to add some aliases that I honestly think every Ubuntu user should be using. So this is Ubuntu running in a virtual machine. So let's go ahead and open the terminal because, I mean, that's what it's all about, becoming a power user and learning the terminal. I'm going to zoom in here so you can see some of the commands. Let's talk about when you're learning the terminal, what are the most common commands that you're going to run? Well, I think on most people's Linux systems, the most common terminal commands that they run involve their package manager, updating the system, right, installing software, removing software. That's probably the most common task that I think new to Linux users first learn is how to use their package manager. So on Ubuntu and any Ubuntu-based distribution or any Debian-based distribution, you're going to use the apt package manager to update your system, install software, remove software. To update your system, you're going to do a sudo apt update and sudo apt upgrade. Now that, you're going to run that command all the time. Anytime you want to update all the packages on your system, you're going to run this command. So it's a common command. So you're going to learn it, but the problem with this command is it's a lengthy command. Let me go ahead and run it. It's going to ask for the sudo password. Let me give it my password. It's going to go ahead and run that update. Then it's going to list out all the packages. Do I really want to install all these updated packages? I'll decline that. Let me clear the screen, but that is too long to type. So I want to go ahead and give me a shorter alias to run that entire command. So let me go ahead and get into the bash rc. So I'm going to open the dot bash rc that is in your home directory. That's your bash config file. I'm going to open that in Vim. Vim is not installed by default on Ubuntu. I installed it so I could use it on this video. Nano is a standard that is installed on Ubuntu. So if you're familiar with the nano text editor, you can open the bash rc in nano. I can't use nano because I find it rather confusing. So I installed Vim just for my sake. So let me go ahead and open the default bash rc. Now if you're like me, you're eventually going to have a million aliases in your bash rc. So I would just create a section and title it aliases in the bash rc. So I'm actually going to go to the very end of the document and I'm going to leave a comment to leave a comment in bash scripting. You use the pound symbol or the hashtag and I'm just going to write aliases. So that is just a comment that's not code that's going to be executed. Now to create an alias, what you want to do, let me create a few new lines here. I'm going to do the word alias and then the name of the alias. I'm going to label this alias apt up and then equals no space between the alias name and the equal sign. That's very important. And then end quotes. This can be double quotes or single quotes. It really doesn't matter. And then the command that you want to run, that would be sudo apt update and end sudo apt upgrade. And then the ending single quote. Now let me go ahead and write and quit out of that. Now apt up is not going to be a command that we can actually run right away because this bash shell that we're in was initialized with the previous version of the bash rc, right? So what you need to do is run this command here source dot bash rc. And now we told the bash shell basically to reinitialize itself using our current bash rc. So now when I do apt up, it runs sudo apt update and end sudo apt upgrade. But now I only have to type five characters instead of that very lengthy command. So that is definitely the first alias I would add to an Ubuntu bash rc. Now sometimes you don't actually want to run both the sudo apt update and the sudo apt upgrade. Sometimes you only want to run one or the other instead of both at the same time. Now that's not terribly common. Typically when you're updating the system, you're also going to upgrade the packages. But occasionally you will not want to do both at the same time. So I do think you should probably go ahead and add an alias. Let me get back into the bash rc here. And let me go ahead and create another alias. So what I'm going to do, actually I'm just going to copy that alias I created a couple of times. I'm going to create a new alias here. And what I'm going to do is I'm going to call this one apt up d for update, because I'm going to make this just sudo apt update. In case, you know, I ever need to just run the update command, which is basically re-syncing the mirrors. And then I'm going to create a new alias here apt up g, and that's just going to run the sudo apt upgrade command. And while we're adding aliases for the apt package manager, I really think you should probably add aliases for installing and removing software as well, because you're going to do that all the time. So I'm going to alias apt in for install equals. And that's going to be a sudo apt install. And of course, you're going to have to add name of package behind the apt in alias when you use that. I'm also going to do a alias for apt rm for remove. And then that's going to equals inside the quote sudo apt remove. And then the ending single quotes. Let me go ahead and write that. And then once again, let's source our dot bash RC, by the way, to get previous commands, I could have just done the up arrow and to get all the previous commands in the shell history. That way I didn't have to retype that, but I went ahead and typed it out. So now when I do a apt in and then name of package, maybe I don't know, did I already install htop? Let's see. Htop is already the newest version. So it's already installed. So there was nothing to do. But you can see our alias works. So your package manager aliases are very important because that's some of the most common commands you'll use other common shell commands that you're going to learn immediately when you first start learning the terminal, the LS command, the list command, this lists all the contents of a directory. The problem is LS by itself with no other flags really doesn't return all the information, right? It only lists the files and directories in this directory that are not hidden, the ones that don't begin with a period, a dot, you see our dot bash RC is not in that LS command. To get that, I would have to do LS space dash a for all the files and directories, including the hidden ones or the ones that begin with a dot. And you see now I actually get all the files and directories listed in the output. Now for me personally, I typically run LS with the following flags, I do LS space dash L for long format. So everything's in one column and it's a long listing format. It gives me a lot of extra information, such as the owner, the group, the size of the file or the directory. Then I'm going to do a because I want all the files and directories, including the hidden files and directories, H for human readable numbers, because some of these files and directories can be very large kilobytes, megabytes, even gigabytes. I don't want those returned in bytes. I actually want human readable numbers. So if something's 1.5 gigabytes, it's going to say 1.5 G and not 1.5 Z, you know, a whole bunch of zeros. Because that's very confusing. It's hard to tell. Is that a gigabyte? Is that a megabyte? You know, human readable numbers are very nice. And then I'm also going to give it this flag here dash dash color equals auto is going to give us a little bit more color, which they're already using color equals auto here. And Ubuntu you see is that we have some different colors for the directories and files on the system. So we want to make sure we add that to our alias and that is my ls command. So that's the one I prefer. You may prefer to use a few different flags but typically when I run ls that's what you're going to see is this version of ls. That's I never want this ls. I will never ever have a need to just do ls with no flags because it's not very useful because it just doesn't return all the stuff in the directory. You know it's kind of a gimp version of ls. So to fix this I'm going to go into the bash rc and the first thing I want to do first let's make sure that ls is not already aliased. So I'm going to search for ls and of course there's a lot of things that are going to include ls as a pattern. Let me search instead for alias ls and you see there is a line here in the ubuntu bash rc alias ls. Their ls is simply ls with the color equals auto flag. Well I want to change that so let me go ahead and get in here. I'll leave their alias where it's at for now and I'm going to get in here and I'm going to add the flags that I wanted which were l a h space color equals auto. So that takes care of that although I'm going to move that and what I'm going to do is I'm going to go ahead and take that down here where we had our other aliases because I want all my aliases in the same spot in the bash rc that way I never have to wonder about their location. I know exactly where they are in this file if I need to edit them. So let me write and quit that and once again I'm going to source the bash rc and now our ls should be the ls I want with all the flags and options that I like. Another common shell command that you're going to learn when you're beginning to learn the terminal is cd cd for example if I wanted to cd into downloads you know that's how you cd change directory. I went from my home directory into the downloads directory. Now a common command when you're cd-ing is cd space period period which means go up a directory. The two periods in a row mean the parent directory so cd into the parent directory which is the home directory because that's such a common command with cd a lot of people like to alias that and this is something that I also like to alias so let's go ahead and get into the bash rc and get down into our aliases and alias and what most people will do is do dot dot that way they don't have to type cd space dot dot you're just going to alias dot dot to actually equal cd space dot dot and let's write and quit that and let's see I'm going to up arrow find my source dot bash rc so I didn't have to type at that time and now let me cd into downloads and just tab complete to finish typing downloads which I do dw I just tab to finish out the word and now instead of cd and then dot dot to get back into the parent directory dot dot now this is something that people really like to get creative with is cd-ing into parent directories because a lot of people you know just this one alias isn't enough some people will want to add even more aliases for for example maybe you want to do dot dot dot and you know three dots and that's for cd-ing into a uh grandparent directory essentially is cd-ing up two levels so not the directory one level up we're going to cd into the directory that's two levels up well this is the command you would typically run cd space period period slash period period but again do you want to type that no you could just do the three dots and if you wanted to get even fancier I mean we could go ahead because sometimes you have the need to go up three levels I mean you could you could uh make aliases for however many levels up you want to cd and I see a lot of people in their bash rcs actually use this dot format and I think that's too much typing because honestly especially if you're gonna cd up like five six ten levels what are you gonna do type ten dots uh you better be counting while you're adding the dots what I would prefer here is I don't mind the dot dot but honestly I would probably just want this to actually specify a number so I know exactly how many levels I'm going up so instead of dot dot I'm gonna do dot one meaning go up one level dot two means go up two levels dot three means go up three levels etc however many you want to add let me write and quit that once again let's source the bash rc and now let me cd into the downloads directory and now instead of going up one level into home maybe I want to go up two levels which would get me into the root directory right so instead of cd dot dot slash dot dot now I have the alias dot two to go up two directories and I misspoke I thought going up two directories would take me into the root directory it actually takes me into slash home but that's not my user's home that's the slash home folder my home is actually slash home slash dt so let me once again I'm going to cd space dash to get back into downloads and let me do dot three to go up three levels which should take me all the way to the root directory and that's where I ended up and cd by itself will take me back into my user's home directory for many years I actually did use these aliases for cd'ing up the directory system so I used a dot one dot two dot three I think I had like 10 of them you know all the way to like dot nine or dot 10 and I realized I had all of these aliases that could actually be replaced by a function and I got this function actually I forget where I got this function at this is my actual host system so this is not a boon to anymore this is arco linux let me show you my bash rc here on arco linux so gonna zoom way in and let me go to my aliases section where I have a million aliases and you can find my bash rc over at my git lab the link to my git lab is in the show description and there is a section here and my aliases uh right here that is not an alias that is actually a bash function there used to be about 10 aliases here that were cd one cd two or dot one dot two dot three you know to go up a level in the file system and eventually I replace that with up this is function up you see up and then the opening and closing parentheses that is a function and inside the squarely braces is us actually defining that function what does it do well essentially what it does is you run the command up space number and that is telling the bash shell exactly how far up in the directory system you want to go so by default my terminals open in the fish shell so I had to exit fish and get into bash here and let me cd into a really long directory path so I'm going to cd into user uh share fonts I know in fonts there's a ttf all caps directory and then uh liberation I think all the liberation fonts are in their own directory as well that is one two three four five levels down that's enough so I'm going to cd into that and the way that up function works again if I do up three I'm going to go up three levels and you see I'm all the way back into user slash share because I went up three levels so if I was here one level would be ttf two levels would be fonts and three levels would be back into share let me cd back into user share fonts ttf liberation and run up space five takes me five levels up which is all the way back into the root file system if you want this up function by the way just go get my bash rc off of my get lab and you'll see the code for this particular function so go to my dot files repo on my get lab now getting back into our Ubuntu virtual machine here another common shell command you'll learn as a beginner is mkdir make directory and one of the problems with making a directory is sometimes you want to make a several directories you want to make all the parent directories grandparent directories for example we're in home right now maybe I want to make a directory in downloads so the downloads directory slash and maybe I want some sub directories maybe I want to do parent and then slash and then child if I run that command let me move my head out of the way it says mkdir it cannot create a directory download slash parent slash child because no such file or directory exists basically the problem is it can't create this child directory because the parent directory doesn't exist well mkdir does have flags that allow you to make all the child directories and those flags if you do dash pv that creates all the parent directories as well as the directory the child directory so if I do download slash parent slash and then child for the name of the child directory you can see mkdir it created slash parent and it also created slash parent slash child now for me personally and probably for most people you want make dear mkdir you want it to just create the parent directories right you don't want to have to give it these extra flags so every time I run mkdir I actually want dash pv to actually be specified and of course we're going to do that once again with bash aliases so let me get in here and I'm going to do an alias mkdir to be make dear space dash pv and then write that and I should probably go ahead and start cleaning this bash rc up let's go ahead and and do it the right way because I like making sure everything is commented nicely and neatly so under this comment that's aliases I'm going to do another comment this time just one hash symbol I'm going to do apt package manager right because that's what these aliases below it are is the apt package manager and this one here just going to say ls with all the flags and then this here is going to be the cd of the directories and then this one make dear create parents that way we have these nice little subsections because the next section I'm going to do I'm going to call it confirmations because some of the most common commands that you'll learn as a beginner are the move command mv the copy command cp and the remove command rm by default there are no safety checks with these commands meaning if I do a mv a move and I move a file into a place where a file by that name already exists move's just going to overwrite that existing file it's not going to ask me about it right it's just going to do it it's just going to assume I knew that file was there and overwrite it same thing with copy same thing with remove there's no safety checks you know if if I'm moving or removing or copying anything and it's going to override a file that's already there it's not going to ask me about it I want those commands to actually ask me for a confirmation do I really want to basically delete the file that's going to be deleted so typically what I do is I alias mv to equal mv space dash i the dash i is an interactive flag a confirmation it's going to basically say hey do you really want to override that file that's about to be overwritten and you could do the same thing for cp and rm so let me go ahead and change that to cp and cp and then this one here will do remove so now all those commands will ask me before they overwrite anything there is one other command that does have an interactive flag I really hardly ever used the link command but ln is the link command and it also has a dash i flag for confirmation and really I think I've covered a lot of the basics as far as the basic shell commands you'll use on a daily basis when you open a terminal and the aliases I would add for those commands one last thing I want to leave you with let's do something a little more fun because let's talk about some multimedia stuff and these are aliases I don't think most people have really ever considered so I'm going to do audio and I'm going to create this alias I'm going to alias play wave and wav so the dot wav extension for wave file that is a audio file format and what I want that to be is the name of my audio player now by default on a boon to the audio player is going to be rhythm box but that could be anything else and then I'm going to do asterix period wave so what that's going to do is if I'm in my terminal and if I navigate to a folder that has a bunch of wave files all I need to do is type play wave and what it'll do is it will open all of those wave files in the directory I'm currently in inside rhythm box and of course I would create aliases for all the common audio formats that I use so an open source format that is common is aug ogg so let's go ahead and create play aug and let's go ahead and obviously create play mp3 which is the most common audio format you could also create others you know play flak play aac you know whatever formats you want now that I have that let me write and quit and I'm going to source the dot bash rc and now I'm going to cd into the music directory because I downloaded a few sample mp3 files and let's test this out if I do play mp3 watch what happens rhythm box opens those mp3s it's playing them by the way but I have the audio disabled because I don't know if there's any kind of copyright issues with this audio so I didn't want to take the chance but it's playing this list of mp3 files so that is how that works and of course play aug and play wave would have worked the same way it basically plays everything of a specific file type now let me cd back into my home directory here and once again vm dot bash rc because we did this for audio which is really nice but I also wanted to do the same thing for video so you cd into a directory with a bunch of videos what would you do well you would alias if I can type correctly play and then the name of a video format such as avi let's go ahead and add that one now the default video player on Ubuntu is totem it's the standard gnom video player rhythm box is the standard gnom audio player now I don't particularly care for totem so I installed vlc I think probably many if not most Linux users probably eventually install vlc at some point and the good thing with vlc is it's a fully featured video player and it has a playlist which is kind of a nice feature especially for what we're doing here so I'm going to do vlc instead of totem and then once again the asterisk symbol meaning all files it doesn't matter what their names are that include this extension dot avi and then I'm gonna copy and paste a couple of times because let's do a few other video formats as well me personally I don't do much with avi but I often need to play dot mov files so let's go ahead and add play mov and of the most common video format I work with because I record in this video format is mp4 so let's do a play mp4 and then let me write and quit let me up arrow and source the bash rc once again and I'm gonna cd into my videos directory if I do an ls there is nothing there so I thought I had downloaded a few sample mp4 files as well so let me cd into downloads maybe they're in here ah yeah so I actually have mp3s and mp4s in my downloads directory here I only want to play the mp4 files the video files and I want to play them of course in vlc well play mp4 and you see these videos they launch in vlc now I mention vlc it's nice because if I go to view here in the menu system and I go to playlist you know it actually makes the uh video player smaller and I can actually see the list of videos that it's actually in the playlist so that's nice I wanted to get back full screen from the playlist I just double click so again just some of the bash aliases that I think every Ubuntu user especially since we're on Ubuntu here and using the apt package manager should consider now just because I made this video in Ubuntu most of these aliases apply everywhere if you don't use the apt package manager say you use pacman in arch well you can still create pacman aliases for sudo pacman syu to update your system instead make an alias call it pac syu you know shorten it to just six letters right pac syu and really what's really saving space on many of these package manager commands is the fact that you don't have to type sudo right you're just saving on not typing sudo which we should talk about other commands that involve sudo that maybe you don't want to have to do sudo now on most system d distributions the reboot command no longer requires sudo privileges but if you're on a non system d distribution and you have to type sudo reboot to reboot your machine well what I would do is shorten it by doing an alias alias reboot equals sudo reboot right and some of the other commands that you will commonly use in the terminal that requires sudo privileges if you're on a system d distribution anything with the system cto command most of those commands require sudo so actually I would probably just alias system ctl to actually be sudo system ctl that way I don't have to bother with typing sudo over and over again every time I do a system ctl command now these were just some example bash aliases but I really think that the ones I showed on camera today these really are probably bash aliases that every Ubuntu should probably have in their bash rc I think every Ubuntu user would find what I showed on camera today to be useful now everybody has different use cases everybody uses their computer differently when we talk about bash aliases I know a lot of you guys have favorite bash aliases that you find extremely helpful and share them in the comments below I would love to see what you guys are doing with your aliases now before I go I need to thank a few special people I need to thank the producers of the show Devin Gabe James Matt Michael Mitchell Paul Scott Wess Allen Chuck Commander Ingrid Iokai Dylan George Lee Linux Ninja Maxim Mike Erion Alexander peace arch and for door public tech red prophet Stephen Willie these guys they're my highest tiered patrons over on patreon without these guys this episode about bash aliases on Ubuntu 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 these videos about linux and free and open source software and you want to support my work subscribe to distro tube over on patreon all right guys peace and check out the alias for the terminal rick roll in my bash rc