0
0
Linux CLIscripting~30 mins

.bashrc and .bash_profile in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding and Using .bashrc and .bash_profile
📖 Scenario: You have just started using Linux and want to customize your command line environment. You want to learn how to set up environment variables and aliases that load automatically when you open a terminal or log in.
🎯 Goal: Learn how to create and edit .bashrc and .bash_profile files to customize your shell environment. You will create environment variables and aliases, and understand when each file is used.
📋 What You'll Learn
Create a .bash_profile file with a custom environment variable
Create a .bashrc file with a custom alias
Configure .bash_profile to load .bashrc
Display the values of the environment variable and alias to verify setup
💡 Why This Matters
🌍 Real World
Customizing your shell environment makes your work faster and more comfortable by automating common tasks and setting preferences.
💼 Career
Many IT and developer jobs require knowledge of shell configuration to optimize workflows and manage environments efficiently.
Progress0 / 4 steps
1
Create a .bash_profile with a custom environment variable
Create a file called .bash_profile in your home directory. Inside it, add a line that sets an environment variable named MY_NAME with the value LinuxUser. Use echo "export MY_NAME=LinuxUser" > ~/.bash_profile.
Linux CLI
Need a hint?

Use echo to write the export line to .bash_profile.

2
Create a .bashrc with a custom alias
Create a file called .bashrc in your home directory. Inside it, add a line that creates an alias named ll which runs ls -la. Use echo "alias ll='ls -la'" > ~/.bashrc.
Linux CLI
Need a hint?

Use echo to write the alias to .bashrc.

3
Configure .bash_profile to load .bashrc
Edit your .bash_profile to add a line that loads .bashrc if it exists. Use echo "if [ -f ~/.bashrc ]; then . ~/.bashrc; fi" >> ~/.bash_profile.
Linux CLI
Need a hint?

Use echo ... >> ~/.bash_profile to append the if statement that sources .bashrc.

4
Display the environment variable and alias to verify setup
First, load the configuration by running . ~/.bash_profile. Then print the value of the environment variable MY_NAME using echo $MY_NAME. Finally, print the alias ll using alias ll.
Linux CLI
Need a hint?

Use . ~/.bash_profile to load, then echo $MY_NAME and alias ll.