Customizing Your Terminal: .bash_profile and .bashrc files
Key Takeaways
This video covers customizing the terminal using .bash_profile and .bashrc files, explaining the difference between them and how to use them to add customizations such as aliases, git prompts, and variable exports. The video demonstrates how to edit these files to apply customizations to both login and non-login shells.
Full Transcript
Hey everybody, how's it going? Uh, I've been getting a lot of questions from people lately asking me how I customize my terminal and if I would do a video showing how to set it up. So, in the next few videos, I'm going to show you how you can customize your own terminal. Now, there's a lot of different customizations that you can make uh, which will help you be more productive and also it's just nice to set up an environment that is unique and also pleasant to work with on a daily basis. So, some of the customizations that you can make, uh, you can simply just change the colors like I've done here. Um, you can add aliases, which will allow you to have shortcuts for certain commands. You can add a git prompt, which will uh, if you're inside a git repository, it'll show you what git branch you're on. Uh, you can also add git autocomp completion and you can also export certain variables like if you need to change your path variable, you can do that as well. So, all kinds of stuff. So, in this video to get started out, we're going to be taking a look at the files that we need to edit that will allow us to customize our terminal. So, first of all, why do we need to edit files? You may have seen people customize their terminal just by typing directly into it. So, for example, I could customize my prompt in the terminal by typing something like uh PS1 equals and I'll just uh do a custom with an arrow and a space here. And if I run that, you can see that this did customize my prompt. So I have a custom prompt here now that I just changed from within the terminal. But the problem is that this is only temporary. So if I quit out of the terminal and open this back up, now you can see that it's back to the way that it was. So we need to add these customizations to specific files so that they are applied every time we run the terminal. So the files we're going to edit are the bash_profile and the bashrc files located in our home directory. And these are dot files. So if I do an ls on my home directory, then I need to put in this a tag here um so that it shows all of the dot files. And if I scroll up here to my dot files, you can see that I have a bash_profile and I also have a bashrc. Now, if you don't see these files, then that's okay. You can just create them if they don't already exist. So, I'm going to go ahead and get rid of the customizations that I've made to my terminal. And the way that I'm going to do that is that I'm just going to move those uh bash files into a temporary folder for now. So, I'm going to move my uh bash_pro file into files. So, I will move that there. And I will also do that with the bash rc file too. that dot files is just a temporary directory that I made so that I could stash these away somewhere for now. So now if I quit terminal and I open it back up, then my customizations should be gone. So you can see here all the colors that I had previously aren't here anymore. And if I was to go into a git repository or something like that, then it wouldn't show me in my git branch or apply any of the other customizations that I've made. So, now that I have my new terminal window open up here, I'm going to recreate my bash_p profofile and my bash rc file. Now, I'm not going to go into too much detail about why we need these two files instead of just one. Uh, but long story short, the bash_profile is a file that is used for something called a login shell and the bash rc file is used for non-lo shells. So, I'm not going to go into the exact differences in this video, but let me go ahead and just recreate these and uh we can kind of take a look at what I mean by that. So, I'm going to go ahead and create that bash_profile. Then I'll also create a bash rc file. So, now I'm going to open up each one of these in Sublime Text and add an echo statement uh so that you can see when each one is executed. So now I'm within my bash_profile. And what I'm going to do is I'm just going to put in an echo statement and I'm going to echo out from bash_profile. And I'll go ahead and save that. Now if I go back to my terminal here, I'm also going to open up my bash rc file within Sublime. And in this case, I'm just going to do an echo and I'm going to do from bash rc and save that. So now let me go ahead and quit out of terminal and open it back up and let's see which one of these files gets executed. So if I open terminal back up, you can see that it ran our code from bash_profile uh but not from the bash rc file. And that's because this is a login shell on the Mac and it is run every time we open up a new terminal. Now I don't think that's exactly the case on Linux, but I'm not 100% sure about that. So these login shells are also run anytime you SSH into a machine and things like that. Now the bash rc file is run when we start a non-lo or a subshell. So if I just type in bash here then what it's going to do is it's going to start a subshell. And you can see as soon as I start that subshell it runs the echo statement that we put into our bash rc file here. This uh from bash rc. Now, this is different for some people, but I personally like my customizations to be the same whether I am in a login shell or a non-lo shell. Uh, so there's a simple trick that we can do which will allow us to modify just a single file and it'll be applied to all of our shells. So, to do this, I'm going to open up my uh bash profile again in Sublime Text. And all I'm going to do is call my bash rc file from within this file. So to do this, we're just going to type in this command. And you can find this online and copy and paste it if you want. But I can type if bracket f-f. And then I'm going to say within my home directory herec and then close that bracket off. Then and source dot bash rc. And then to close out that if statement, we can just type in fi. Okay, so basically what this code is saying, it's saying that if the bash rc file exists, then execute the code in that file. So now imagine what's going on here. So as soon as we open up a login shell and it runs the code that's within our bash_profile, it's going to run this code, which in turn runs the bash rc file. And if you run a subshell, then it's also going to run the bash rc file. So now we can add all of our customizations to our bash rc file and not really have to worry about our bash profile anymore. So to actually see this at work, I can go back over here to my terminal. And if I quit out of the terminal and I'll close that. And if I reopen it, you can see here now that it's echoing the statement from our bash rc file, which is what we wanted. And if I was to run a subshell here with bash, then you can see again that it ran the uh code from the bash rc file. So now we can add all of our customizations to a single place. So if I was to open up the bash rc file in sublime text and I was to do something instead like I did earlier of uh PS1 equals and then I'll just do the same thing custom arrow with a space. And if I save that and then open back up my terminal again, I'll close out of that and open it up. Now you can see I have a custom prompt here. And if I run a subshell, then I still have that custom prompt. So I think that's going to do it for this video. Uh now we have our files set up in such a way that we can add all of our customizations to one file. And in the following videos, I'll show you more specifically exactly how I customize my own terminal. And it can give you some ideas of how you want to customize yours as well. So, I hope this video was useful. I hope it helps you uh somewhat understand the difference between the bash_profile and the bash rc files. Uh but if you do have any questions, just ask in the comment section below. Uh be sure to subscribe for future videos and thank you all for watching.
Original Description
In the next few videos, we will be taking a look at how to customize our terminal with dotfiles. First, we need to understand the main dotfiles we will be working with, the .bashrc and .bash_profile files. What is the difference between these files and which one should you modify in order to customize your terminal? Let find out...
Next Video on Customizing Your Prompt: https://youtu.be/LXgXV7YmSiU
Next Video on Dotfiles: https://youtu.be/c5RZWDLqifA
✅ Support My Channel Through Patreon:
https://www.patreon.com/coreyms
✅ Become a Channel Member:
https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join
✅ One-Time Contribution Through PayPal:
https://goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
http://a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
https://www.amazon.com/shop/coreyschafer
▶️ You Can Find Me On:
My Website - http://coreyms.com/
My Second Channel - https://www.youtube.com/c/coreymschafer
Facebook - https://www.facebook.com/CoreyMSchafer
Twitter - https://twitter.com/CoreyMSchafer
Instagram - https://www.instagram.com/coreymschafer/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Corey Schafer · Corey Schafer · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Web fonts using CSS Font Face
Corey Schafer
Using Font Awesome in Desktop Applications (OS X)
Corey Schafer
Sublime Text 2: Setup, Package Control, and Settings
Corey Schafer
ArcGIS API for JavaScript Part 1: Our First Web Map
Corey Schafer
Mac Tip: Windows' Snapping Feature on Mac with HyperDock
Corey Schafer
Linux/Mac Terminal Tutorial: Creating Aliases for Commands
Corey Schafer
ArcGIS API for JavaScript Part 2: Starting Templates
Corey Schafer
Paver Patio Time Lapse
Corey Schafer
Mac Tip: Ways to perform Screen Capturing and Screenshots
Corey Schafer
WordPress Plugins: Imsanity
Corey Schafer
WordPress Tips: Test your theme with Theme Unit Test and Monster Widget
Corey Schafer
Sublime Text 3: Setup, Package Control, and Settings
Corey Schafer
Understanding Binary, Hexadecimal, Decimal (Base-10), and more
Corey Schafer
Mac Tip: Adding Folder Stacks to the Dock
Corey Schafer
CSS Tips and Tricks: Add External URLs to Print Stylesheets
Corey Schafer
JavaScript Arrays: Properties, Methods, and Manipulation (Part 7 of 7)
Corey Schafer
JavaScript Arrays: Properties, Methods, and Manipulation (Part 1 of 7)
Corey Schafer
JavaScript Arrays: Properties, Methods, and Manipulation (Part 5 of 7)
Corey Schafer
JavaScript Arrays: Properties, Methods, and Manipulation (Part 4 of 7)
Corey Schafer
JavaScript Arrays: Properties, Methods, and Manipulation (Part 3 of 7)
Corey Schafer
JavaScript Arrays: Properties, Methods, and Manipulation (Part 2 of 7)
Corey Schafer
JavaScript Arrays: Properties, Methods, and Manipulation (Part 6 of 7)
Corey Schafer
Python Tutorial: if __name__ == '__main__'
Corey Schafer
Sublime Text Quick Tip: "Go To Definition" Click Shortcut
Corey Schafer
How to quickly create favicons for the desktop, Apple/Android devices, tablets, and more
Corey Schafer
Easily Resize Multiple Images Using Picasa
Corey Schafer
Easily Resize Multiple Images Using the Mac Terminal
Corey Schafer
Python Tutorial: virtualenv and why you should use virtual environments
Corey Schafer
Python Tutorial: pip - An in-depth look at the package management system
Corey Schafer
Git Tutorial: Using the Stash Command
Corey Schafer
How Software Engineers, Developers, and Designers can volunteer their skills
Corey Schafer
Git Tutorial: Diff and Merge Tools
Corey Schafer
Git Tutorial: Change DiffMerge Font-Size on Mac OSX
Corey Schafer
Sublime Text Quick Tip: Launch Sublime Text from the Terminal
Corey Schafer
Python Tutorial: str() vs repr()
Corey Schafer
Programming Terms: DRY (Don't Repeat Yourself)
Corey Schafer
Programming Terms: String Interpolation
Corey Schafer
Programming Terms: Idempotence
Corey Schafer
Python Tutorial: Namedtuple - When and why should you use namedtuples?
Corey Schafer
Programming Terms: Mutable vs Immutable
Corey Schafer
Python Tutorial: Else Clauses on Loops
Corey Schafer
Overview of Online Learning Resources
Corey Schafer
Mac OS X Terminal Tutorial: Time-Saving Keyboard Shortcuts
Corey Schafer
Git Tutorial for Beginners: Command-Line Fundamentals
Corey Schafer
Quickest and Easiest Way to Run a Local Web-Server
Corey Schafer
Python Tutorial: Generators - How to use them and the benefits you receive
Corey Schafer
Python Tutorial: Comprehensions - How they work and why you should be using them
Corey Schafer
Chrome Quick Tip: Quickly Bookmark Open Tabs for Later Viewing
Corey Schafer
Programming Terms: Combinations and Permutations
Corey Schafer
Git Tutorial: Difference between "add -A", "add -u", "add .", and "add *"
Corey Schafer
Preparing for a Python Interview: 10 Things You Should Know
Corey Schafer
SQL Tutorial for Beginners 1: Installing PostgreSQL and Creating Your First Database
Corey Schafer
SQL Tutorial for Beginners 2: Creating Your First Table
Corey Schafer
SQL Tutorial for Beginners 3: INSERT - Adding Records to Your Database
Corey Schafer
Linux/Mac Terminal Tutorial: Navigating your Filesystem
Corey Schafer
Python: Ex Machina Easter Egg - Hidden Message within the Code
Corey Schafer
Mac Tip: New Split Screen Feature in El Capitan
Corey Schafer
Setting up a Python Development Environment in Eclipse
Corey Schafer
Git Tutorial: Fixing Common Mistakes and Undoing Bad Commits
Corey Schafer
SQL Tutorial for Beginners 4: SELECT - Retrieving Records from Your Database
Corey Schafer
More on: AI Pair Programming
View skill →Related Reads
📰
📰
📰
📰
I Stopped Using Multiple If Statements After Discovering This Python Pattern
Medium · Programming
The Biggest Mistake Vibe Coders Make With AI
Medium · AI
The Biggest Mistake Vibe Coders Make With AI
Medium · ChatGPT
I'll Build You a Custom AI Prompt System for Free (First 3 Founders Only)
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI