Profile Files

Afridi ShaikAfridi Shaik
3 min read

Profile files are hidden files (starting with a dot) in Linux/RHEL that define your shell environment. They control settings like environment variables, aliases (shortcuts for commands), and terminal behavior. These files are processed in a specific order when you log in or open a terminal window.

Types of Profile Files

  1. system-wide profiles

  2. user-specific profiles.

System-wide Profiles (/etc directory):

  • /etc/profile: This file contains system-wide environment variables and settings that apply to all users. It's executed when a user logs in.

  • /etc/inputrc: This file defines keyboard mappings and shortcuts for the readline library, which is used by Bash for command-line editing.

  • /etc/bashrc: This file contains system-wide Bash configurations and functions that are applied to all users when they start a new Bash shell.

User Profiles ($HOME directory):

  • .bash_profile (or .profile for non-bash shells): Executed for login shells (when you first log in through a terminal). It sets permanent environment variables and aliases.

  • .bashrc: Executed for all interactive shells (including login shells and subsequent terminal windows). It sets aliases and customizations that you want in all interactive shells.

Create Own Alias

  1. Open a text editor (e.g., nano ~/.profile.d/my_alias.sh) and add the following line, replacing command with the actual command you want to shorten and alias_name with your preferred alias:
alias alias_name='command'

  1. Save the file and source it using the following command (replace my_alias.sh with your filename if different):
source ~/.profile.d/my_alias.sh

  1. Now, whenever you type alias_name, the actual command will be executed.

Loading in Home Directory Bash Files:

  1. When you log in or open a terminal:

    • /etc/profile (if not modified)

    • /etc/profile.d scripts (alphabetical order)

    • ~/.bash_profile (or ~/.profile)

  2. For subsequent interactive shells:

    • ~/.bashrc

Impact Based on Shell:

Different shells have different profile files. For example, Bash uses .bash_profile and .bashrc, while other shells like Zsh may use .zshrc. Customizations made in these files will only affect the behavior of the respective shell.

/etc/skel Directory:

This directory contains skeleton files used to create new user home directories. When a new user is added, files from /etc/skel are copied to the user's home directory. This ensures consistency in user environments. Common files found in /etc/skel include:

  • .bash_logout (executed when logging out)

  • .bash_profile (or .profile)

  • .bashrc

0
Subscribe to my newsletter

Read articles from Afridi Shaik directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Afridi Shaik
Afridi Shaik