Posted: . At: 8:30 AM. This was 2 years ago. Post ID: 2949
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Setting up your BASH prompt. How to get the most out of the BASH shell.


Setting up your BASH prompt.

A nice BASH shell prompt. This shows the current time and the current folder you are in as well as a full directory path if you are in a subfolder.

PS1="-\t-- \u@\h [\w]\$ "

How to set the contents of the Xterm title bar. Using the PROMPT_COMMAND variable. This displays the current directory path in the title bar. Very useful indeed.

# Setting the value of the Xterm title.
# Only if we are in X...
if [ $DISPLAY ] ; then
	PROMPT_COMMAND='echo -ne "\033]0;${OSRELEASE}: ${PWD}\007"'
fi

This function will scan a folder and find any symbolic links that do not point anywhere. Very useful indeed.

function badlink()
# From Atomic magazine #43 August 2004. http://www.atomicmpc.com.au
{
	DEFAULT=$(tput sgr0);
	FILELIST=.badlink.list
 
	[ -e $FILELIST ] && $( rm -fr $FILELIST )
 
	function checklink()
	{
		for badlink in $1/*; do
			[ -h "$badlink" -a ! -e "$badlink" ] && echo \
			\"$badlink\" >> $FILELIST
			[ -d "$badlink" ] && checklink $badlink
		done
	}
 
	for directory in `pwd`; do
		if [ -d $directory ] ; then
			checklink $directory;
		fi
	done
 
	if [ -e $FILELIST ] ; then
		for line in $(cat $FILELIST); do
			echo $line | xargs -r rm | echo -e "$line \
			-removed"
			echo
		done
		rm -fr $FILELIST
	else
		printf "Bad symlinks not found.\n\n"
	fi
} # End Atomic function.

How to find out what your IP address is. Using ifconfig and awk.

┌──(john㉿DESKTOP-PF01IEE)-[~]
└─$ ifconfig eth0 | awk '/inet/ { print $2 } ' | sed -e s/addr://
172.31.9.156
fe80::215:5dff:feff:2a4b

More useful variables to have in your ~/.bashrc.

# Setting a blinking block cursor for the console.
echo -e '\033[?6c'
 
# try to set DISPLAY smart (from Hans) :)
# From a SUSE .bashrc file.
#
if test -z "$DISPLAY" -a "$TERM" = "xterm" -a -x /usr/bin/who ; then
	WHOAMI="`/usr/bin/who am i`"
	_DISPLAY="`expr "$WHOAMI" : '.*(\([^\.][^\.]*\).*)'`:0.0"
	if [ "${_DISPLAY}" != ":0:0.0" -a "${_DISPLAY}" != " :0.0" \
		-a "${_DISPLAY}" != ":0.0" ]; then
		export DISPLAY="${_DISPLAY}";
	fi
	unset WHOAMI _DISPLAY
fi
 
export EDITOR=mcedit
export TIME_STYLE=+" %d-%m-%y %I:%M %P"
# These two examples from bash-doc.
export PAGER="/usr/bin/less"
export VIEWER="mcedit"
export LESS="-i -e -M -P%t?f%f :stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-..."
shopt -s checkwinsize
 
[ -e "$HOME/.dircolors" ] && DIR_COLORS="$HOME/.dircolors"
[ -e "$DIR_COLORS" ] || DIR_COLORS=""
eval "`dircolors -b $DIR_COLORS`"

Some very useful bash scripting samples to help set up a new user

Some very useful bash scripting samples to help set up a new user.

Very useful Linux files to set up your installation

Very useful Linux files to setup your installation.

 

An Introduction to the Linux Command Shell For Beginners.

https://www.securitronlinux.com/lc/ShellIntro.pdf

A very helpful resource for new Linux users.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.