Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Linux 1) Give the line you would add to your .bashrc (below) to set the PS1 prom

ID: 3889596 • Letter: L

Question

Linux

1) Give the line you would add to your .bashrc (below) to set the PS1 prompt to the current time (24 hr format, HH:MM) followed by a colon and then followed by your current working directory.

2) What is the purpose of the string [] in the PS1 prompt of the below example bashrc?

3) How would you modify your .bashrc (below) to make sure ls always showed you the human readable file sizes?

4) How would you modify vim so that it always showed line numbers?

# ~/.bashrc: executed by bash(1) for non-login shells.

# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)

# for examples

# If not running interactively, don't do anything

[ -z "$PS1" ] && return

# Add local bin to PATH

export PATH=$PATH:~/bin

# default to LPRSec printer

PRINTER=CSLPRSec

export PRINTER

#don't put duplicate lines in the history. See bash(1) for more options

export HISTCONTROL=ignoredups

# enable color coding to work without less freaking out

export LESS="-R"

# check the window size after each command and, if necessary,

# update the values of LINES and COLUMNS.

shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)

[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)

if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then

debian_chroot=$(cat /etc/debian_chroot)

fi

# Prevent Firefox from trying to open on client

export MOZ_NO_REMOTE=1

# set a fancy prompt (non-color, unless we know we "want" color)

#case "$TERM" in

#xterm-color)

# PS1='${debian_chroot:+($debian_chroot)}[]u@h[]:[]w[]$ '

# ;;

#*)

# PS1='${debian_chroot:+($debian_chroot)}u@h:w$ '

# ;;

#esac

# Comment in the above and uncomment this below for a color prompt

PS1='${debian_chroot:+($debian_chroot)}[]u@h[]:[]w[]$ '

# If this is an xterm set the title to user@host:dir

case "$TERM" in

xterm*|rxvt*)

PROMPT_COMMAND='echo -ne "]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}"'

;;

*)

;;

esac

# Alias definitions.

# You may want to put all your additions into a separate file like

# ~/.bash_aliases, instead of adding them here directly.

# See /usr/share/doc/bash-doc/examples in the bash-doc package.

#if [ -f ~/.bash_aliases ]; then

# . ~/.bash_aliases

#fi

# enable color support of ls and also add handy aliases

if [ "$TERM" != "dumb" ]; then

eval "`dircolors -b`"

alias ls='ls --color=auto'

#alias dir='ls --color=auto --format=vertical'

#alias vdir='ls --color=auto --format=long'

fi

# some more ls aliases

#alias ll='ls -l'

#alias la='ls -A'

#alias l='ls -CF'

alias xpdf=atril

# enable programmable completion features (you don't need to enable

# this, if it's already enabled in /etc/bash.bashrc and /etc/profile

# sources /etc/bash.bashrc).

if [ -f /etc/bash_completion ]; then

. /etc/bash_completion

fi

Explanation / Answer

1. Any Linux command can be executed in the PS1 environment variable by using the format : $(linux_command). Thus for setting the current time use the command $(date) to display the current time inside the prompt. For example:

For time in hh:mm:ss format, use:

To display the time in 12 hour am/pm format use @ as shown below:

To show the current working directory use: w

So, to show time and directory use following:

2.These strings as : [] are used to set the color coding in the prompt.

The string [] is used to set the color to light green.

3. You can use the command :

ls -l --block-size=M ,

to give you a long format listing and round file sizes up to the nearest MiB.

4. You can always use command :set number from within a file to include the line numbers. But to change it to always include line numbers, make changes in the vimrc file. Use the following commands:

then add the following line to the file:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote