Skip to main content
Engineering LibreTexts

02-E.16.1: System Wide User Profiles: etc profile

  • Page ID
    26818
  • The /etc/profile File

    The /etc/profile contains Linux system wide environment and other startup scripts. Usually the default command line prompt is set in this file. It is used for all users logging in to the bash, ksh, or sh shells. This is usually where the PATH variable, user limits, and other settings are defined for users. This file is only run for login shell and therefore does not run when a script is executed. Part of this file is checking for the existence of the /etc/profile.d directory (we will discuss more about this in a moment).

    The administrator can make some minor changes in this file if they desire to customize the system. However, to make large changes or application specific changes, create a separate script in the /etc/profile.d directory.

    Below is an example of the /etc/profile

    # /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
    # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
    if [ "$PS1" ]; then
       if [ -f /etc/bash.bashrc ]; then
          . /etc/bash.bashrc
       fi
    fi
    
    
    if [ -x /usr/bin/id ]; then
       USER="`id -un`"
       LOGNAME=$USER
       MAIL="/var/spool/mail/$USER"
    fi
    
    export USER LOGNAME MAIL 
    
    for i in /etc/profile.d/*.sh ; do
        if [ -r "$i" ]; then
         . $i
        fi
    done
    

    The script:

    • check to see if the prompt variable, $PS1, is defined - if so then this is an interactive login
    • check for the existence of /etc/bash.bashrc - if it exists the system sources the file
    • check to see if the file /usr/bin/id is executable, if so then we get the userid, the loginname and point to the email file
    • check for existence of the /etc/profile.d directory, if it exists we source each file in that directory

    "The Bash Shell Startup Files" by Multiple contributors, Beyond Linux® From Scratch (System V Edition) is licensed under CC BY-NC-SA 2.0

    • Was this article helpful?