How do you customize the PS1 prompt to display the current working directory?*1 pointa) PS1="%C"b) PS1="%d"c) PS1="%H"d) PS1="%P"
Question
How do you customize the PS1 prompt to display the current working directory?*1 pointa) PS1="%C"b) PS1="%d"c) PS1="%H"d) PS1="%P"
Solution
The correct answer is d) PS1="%P". This command will customize the PS1 prompt to display the current working directory. Here are the steps to do it:
- Open your terminal.
- Type
PS1="%P"and press Enter. - Now, your prompt should display the current working directory.
Please note that this change is temporary and will be reset once you close the terminal. If you want to make it permanent, you need to add this line to your shell's startup file, which is usually ~/.bashrc or ~/.bash_profile for the bash shell. Here are the steps:
- Open your shell's startup file with a text editor. For example, you can type
nano ~/.bashrcornano ~/.bash_profileand press Enter. - Add the line
PS1="%P"to the file. - Save the file and exit the text editor.
- Restart your terminal or source the startup file by typing
source ~/.bashrcorsource ~/.bash_profileand pressing Enter. - Now, your prompt should always display the current working directory.
Similar Questions
Which character is used to represent the username in the PS1 prompt string?*1 pointa) %ub) %nc) %hd) %p
What would you enter at the shell prompt on a Linux system to display the present working directory?
Bourne Again Shell (bash), similarly to other UNIX shells utilises environmental variable PS1'' to store prompt string description. Willing to change it, it is enough to replace its value with a new one. The most permanently looking effect can be obtained by performing adequate substitution in start script, which in case of bash is in ~/.bash_profile'' file (~'' stands for the home directory of a user in question).Prompt string can contain sequences like \x'', where x - a character, which during printing of prompt will be interpreted and substituted with specific information, e.g. \t'' - actual time. Description of other standard sequences can be found in man page concerning bash (man bash).Task: Permanently set URL-like prompt of the form:
How can you change the shell prompt temporarily for the current session?*1 pointa) Modify .bashrc and restart the shellb) Use the 'chsh' commandc) Use the 'PS1' environment variabled) Use the 'exit' command
In Linux, what does the PS1 environment variable control?*1 pointa) System passwordb) Shell promptc) Disk spaced) User profile
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.