0Pricing
DevOps Bootcamp · Lesson

Shell Startup Files (.bashrc, .profile)

Explore the purpose and execution order of common shell startup files for persistent configuration.

Shell Startup Files (.bashrc, .profile) is a free DevOps Bootcamp lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Shell Startup Files Intro

When you open a terminal, your shell doesn't just appear blank! It loads settings, defines shortcuts, and sets up your environment. These actions are controlled by special "startup files."

These files are like configuration scripts that run automatically when a new shell session begins, personalizing your command-line experience.

Interactive vs. Non-interactive

Shells can be interactive or non-interactive.

  • Interactive: You type commands and get immediate feedback (e.g., your terminal).
  • Non-interactive: A script runs in the background without user input.

Different startup files are read depending on whether the shell is interactive or not.

Login vs. Non-login Shells

Interactive shells have another distinction: login or non-login.

  • Login Shell: You log in to your system (e.g., initial terminal after boot, SSH session).
  • Non-Login Shell: You open a new terminal window after logging in, or run a script (e.g., bash -c "echo Hello").

This difference is key to understanding which startup files are executed.

Your Personal Login Profile: .profile

The ~/.profile file is executed when you start a login shell. It's designed for settings that should apply to your entire user environment, regardless of the specific shell you're using (Bash, Zsh, etc.).

Common uses include setting environment variables like PATH, which tells your shell where to find executable programs.

Bash's Interactive Config: .bashrc

The ~/.bashrc file is run for interactive non-login shells. This is the most common scenario when you open a new terminal window.

It's where you typically put Bash-specific customizations like aliases (command shortcuts), shell functions, and prompt modifications (PS1 variable).

Demo: What's in Your .bashrc?

Let's check if you have a ~/.bashrc file and see some common content. This script will try to display its contents.

#!/bin/bash

if [ -f ~/.bashrc ]; then
  echo "--- Contents of ~/.bashrc ---"
  head -n 10 ~/.bashrc # Show first 10 lines
  echo "---------------------------"
else
  echo "No ~/.bashrc file found."
fi

Typical Execution Order

For a login shell (like after SSHing in):

  • /etc/profile (system-wide)
  • ~/.profile (user-specific)
  • Often, ~/.profile will then source ~/.bashrc for interactive use.

For an interactive non-login shell (like opening a new terminal):

  • ~/.bashrc is usually read directly.

System-Wide Startup Files

Besides your personal files, there are system-wide startup files that apply to all users on the system.

  • /etc/profile: Similar to ~/.profile, for all login shells.
  • /etc/bash.bashrc (or similar): For all interactive non-login Bash shells.

These are configured by the system administrator.

Applying Changes: The `source` Command

After editing ~/.bashrc or ~/.profile, changes won't take effect in your current shell until you restart the shell or "source" the file.

The source command (or its alias .) re-reads the file and applies its settings to the current shell environment.

#!/bin/bash

# Example: Add an alias to .bashrc
echo "alias ll='ls -alF'" >> ~/.bashrc

# Source the file to apply changes
source ~/.bashrc

# Now 'll' should work!
# (Note: This might not show output directly in this environment,
# but demonstrates the command's purpose.)
echo "Try typing 'll' in a new terminal after this!"

Shell Startup Check

Which of the following statements about shell startup files are TRUE?

Recap: Persistent Configuration

You've learned how shell startup files like ~/.profile and ~/.bashrc are essential for customizing your Linux environment.

  • ~/.profile: For login shells, general environment settings.
  • ~/.bashrc: For interactive non-login Bash shells, Bash-specific customizations.
  • The source command applies changes without restarting your shell.

These files ensure your terminal works exactly how you like it, every time!

Frequently asked questions

Is the “Shell Startup Files (.bashrc, .profile)” lesson free?

Yes — the full text of “Shell Startup Files (.bashrc, .profile)” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “Shell Startup Files (.bashrc, .profile)”?

Explore the purpose and execution order of common shell startup files for persistent configuration. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Shell Startup Files (.bashrc, .profile)” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Managing Environment Variables (export, unset)
  2. Shell Startup Files (.bashrc, .profile)
  3. Package Management (apt, yum, pacman)
  4. Understanding and Customizing the PATH Variable
← Back to DevOps Bootcamp