*changes should be made in .bashrc file or .aliases file pulled into .bashrc.
Hello Everyone! Today I am bringing you some more super cool command line knowledge to help you work more efficiently in your bash terminal: Dot Files. It’s crazy how I have never used them before. I am learning so many new concepts this year and I’m eager to share them with you.
Two types of dot files I’d like to share today are Aliases and Functions.
Aliases are shortcuts you can use in your terminal to represent something else. For example, “c” in my terminal is aliased to “clear”. “Clear” is a command line argument to clear your screen whenever it gets too clunky/messy/etcetera with data. Another alias I have created is “rb” which is a shortcut for “source ~/.bashrc”. This command refreshes the terminal without having to exit out.
To access your dot files, go to your home folder with all of your files. Currently, I am using a Mac OS, so I go to my finder and then my home folder. Most of the time dot files are hidden. To uncover them hit, “shift” + “command” + ” .” .
You can create an aliases file like any other file. Create a new file using your normal text editor and save it as “.aliases”. Your computer will know what this means. Once you’ve created your file you can begin to make aliases. It’s super easy. If I want to create a folder in my terminal named “sports”, I can type “m sports” which is the same as “mkdir sports”. To create “m” as an alias, all you need to do is type alias m=”mkdir” on a line in your .aliases file. Don’t add spaces. BOOM, that’s it.
Take a look at some of my aliases below:
If you end up forgetting some of your aliases. All you have to do in your terminal is enter “type c”, and your bash terminal should state that “c is aliased to clear”. Feel free to make tons of shortcuts. Make sure that which ever aliases you decide to use aren’t already commands. Use “type” to verify that they aren’t.
Another cool type of dot file is functions. “.functions” is another file you can create to use shortcuts in your terminal. Currently, I only use one function. The function that I use does two jobs in one short command. It makes a folder AND cd’s into it. I use the command “mkd”, which is a shortcut for “mkdir folder_name” and “cd folder_name”. There are tons of functions you can find on the web to suit your needs. The snippet I am about to show you is a function that most of my co-workers use in their “.functions” file as well.
It looks like another language now doesn’t it? You can learn to create your own functions with the good ole google search. OR, you can borrow others’ from open source GitHub accounts and articles. I found several online but personally found no use for them. I am sure as I gain more experience, I will come across tasks I’d like to automate using functions. For now, I’ll stick with just this one.