nerdexam
CompTIA

XK0-005 · Question #243

A user wants to alias dir so it always returns the contents of the ls -la command. However, the user has to reset the alias with every login. Which of the following is the BEST action the user can…

The correct answer is C. echo "alias dir=ls -la" >> ~/.profile. Choice C (echo "alias dir='ls -la'" >> ~/.profile) is best because ~/.profile is sourced by login shells (bash, sh, etc.) and is the standard portable location for user-specific environment settings including aliases. Choice D uses > (overwrite) instead of >> (append), which…

System Management

Question

A user wants to alias dir so it always returns the contents of the ls -la command. However, the user has to reset the alias with every login. Which of the following is the BEST action the user can take to ensure the command is always available?

Options

  • Aecho "alias dir=ls -la" > /etc/profile
  • Becho "alias dir=ls -la" >> /etc/skel
  • Cecho "alias dir=ls -la" >> ~/.profile
  • Decho "alias dir=ls -la" > ~/.bashrc

How the community answered

(22 responses)
  • A
    5% (1)
  • C
    91% (20)
  • D
    5% (1)

Explanation

Choice C (echo "alias dir='ls -la'" >> ~/.profile) is best because ~/.profile is sourced by login shells (bash, sh, etc.) and is the standard portable location for user-specific environment settings including aliases. Choice D uses > (overwrite) instead of >> (append), which would destroy the existing ~/.bashrc. Choice A writes to /etc/profile, which affects all users - inappropriate for a single user's alias. Choice B targets /etc/skel, a template directory for new users, not an executable config file.

Topics

#Shell Configuration#Linux Aliases#User Environment#File Redirection

Community Discussion

No community discussion yet for this question.

Full XK0-005 Practice