UNIX login initialization: Which per-user startup file contains shell instructions that are executed automatically when a user logs in (for Bourne/POSIX-compatible shells)?

Difficulty: Easy

Correct Answer: .profile

Explanation:


Introduction / Context:
On UNIX and Linux, each user can customize the shell environment at login. The shell reads specific dotfiles in the user’s home directory to set variables, change the PATH, define aliases, and start background agents. Knowing which file is executed at login is essential for persistent configuration and troubleshooting environment issues.


Given Data / Assumptions:

  • You are using a Bourne-compatible shell (sh, ksh, bash in POSIX mode).
  • You want commands to run automatically at login time.
  • Dotfiles are hidden files stored in the user’s home directory.


Concept / Approach:
For Bourne/POSIX shells, the standard login initialization file is ~/.profile. When a login shell starts, it sources this file and applies exported variables, PATH changes, and other startup logic. Other shells have different files (e.g., bash also uses ~/.bash_profile or ~/.bash_login; csh/tcsh use ~/.login and ~/.cshrc), but .profile is the classic answer for Bourne-style shells.


Step-by-Step Solution:

Create or edit ~/.profile in your home directory.Add environment settings such as PATH, umask, and aliases.Log out and back in, or run . ~/.profile to apply changes immediately.Verify with echo $PATH or alias to confirm the changes took effect.


Verification / Alternative check:
Check your shell’s manual (man sh, man bash) for the exact startup file order. On bash, ~/.bash_profile may be preferred; if absent, bash will fall back to ~/.profile for login shells.


Why Other Options Are Wrong:
.exrc: vi editor configuration, not a shell login file. .autoexec / autoexec.bat: DOS/Windows legacy startup files, not UNIX. None of the above: incorrect because ~/.profile is valid.


Common Pitfalls:
Editing the wrong file for the shell in use; forgetting to export variables; expecting changes to apply to already running shells without sourcing the file.


Final Answer:
.profile

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion