Linux System Administration

When writing a bash scripts most of us by default use echo command as means to print to standard output stream. echo is easy to use and mostly it fits our needs without any problem. However, with simplicity very often comes limitation. This is also the case with echo command. Formatting an echo command output can be a nightmare and very often impossible task to do.

The solution to this can be a good old friend of all C/C++ the “printf” tool. printf can be just as easily implemented into a bash script is it is used with C/C++ programs. This article describes some basics of printf along with practical examples:

Read more ...


When managing a linux/unix operating system from the command line, users are interacting with the system via shell. This article will explore some of the basic features of the bash shell prompt. Default bash command line prompt on many linux systems does not have a color and display information about user's username, hostname and current working directory. As you well see in the following sections of this document this default settings can be easily changed by exporting a bash prompt PS{n} variables. Bash prompt can be modified to suit users needs and can display time, load, number of users using the system, uptime and more.

Read more ...

Sometimes it is needed to check what user is executing the bash script and whether the user supplied all required arguments:

display_usage() { 
	echo "This script must be run with super-user privileges." 
	echo -e "\nUsage:\n$0 [arguments] \n" 
# if less than two arguments supplied, display usage 
	if [  $# -le 1 ] 
		exit 1
# check whether user had supplied -h or --help . If yes display usage 
	if [[ ( $# == "--help") ||  $# == "-h" ]] 
		exit 0
# display usage if the script is not run as root user 
	if [[ $USER != "root" ]]; then 
		echo "This script must be run as root!" 
		exit 1
echo "All good !!!"


$ ./ 1 
This script must be run with super-user privileges.

Usage: ./ [arguments] 

$ su
# ./ 1 2
All good !!!

Page 7 of 72

Go to top