UNIX: mounting CD

Here are the mount commands for different *nix systems.

HP-UX

nohup /usr/sbin/pfs_mountd &
nohup /usr/sbin/pfsd &
/usr/sbin/pfs_mount -t rrip -x unix /dev/dsk/c5t2d0 /SD_CDROM

AIX

mount -r -v cdrfs /dev/cd0 /cdrom

Solaris Intel

mount -F hsfs -r /dev/dsk/c0t6d0p0 /cdrom

SPARC Solaris

mount -r -F hsfs /dev/dsk/c0t6d0s2 /cdrom

TRU64

mount -t cdfs -r -o nodefperm,noversion,rrip /dev/rz4c /cdrom

Linux

mount -t iso9660 /dev/cdrom /cdrom

Unix: print in color

This simple procedure takes 3 arguments as the parameters:

  • Text
  • Foreground color
  • Background color

It prints the text to the terminal in selected colors.

[cc lang=”bash”]
function print_color {
local text=$1
local fg=$2
local bg=$3
case “$fg” in
red) fg=”31m” ;;
green) fg=”32m” ;;
yellow) fg=”33m” ;;
blue) fg=”34m” ;;
white) fg=”37m” ;;
black) fg=”30m” ;;
*) fg=”37m” ;;
esac
case “$bg” in
red) bg=”41m” ;;
green) bg=”42m” ;;
yellow) bg=”43m” ;;
blue) bg=”44m” ;;
white) bg=”47m” ;;
black) bg=”40m” ;;
*) bg=”40m” ;;
esac
echo -en “\033[${fg}\033[${bg}${text}\033[0m”
}
[/cc]

Unix: rename files to lowercase

It’s very simple to rename the files to lowercase/uppercase using awk:

Lowercase
[cc lang=”bash”]
ls -1rt | awk ‘{ printf(“mv %s %s\n”, $0, tolower($0)) | “sh” } END { close(“sh”) }’
[/cc]

Uppercase
[cc lang=”bash”]
ls -1rt | awk ‘{ printf(“mv %s %s\n”, $0, toupper($0)) | “sh” } END { close(“sh”) }’
[/cc]

Using pattern lists in Unix

Here is the small reminder about the syntax of the “case” command and the usage of the pattern lists.


#!/bin/ksh
print -n "Please enter the line: "
read line

case "$line" in
?(dog|cat) ) print "zero or one occurrence of any pattern" ;;
*(low|high) ) print "zero or more occurrences of any pattern" ;;
@(duncan|methos) ) print "exactly one occurrence of any pattern" ;;
+(rudolph|blitzen) ) print "one or more occurrence of any pattern" ;;
!(grinch|babay) ) print "everything except patterns" ;;
-@([hH?]) ) print "Some help..." ;;
-v*(erbose) ) print "Some more words..." ;;
*) print "Something else..." ;;
esac

Print the PATH directories in the readable format


echo $PATH| awk -v RS=":" '{ print $0 }'

echo $LD_LIBRARY_PATH |awk -v RS=":" '{ system ( "ls -rltd " $0 ) }'

Warning!
As far as the option ‘-v’ is used, the new awk(nawk in some systems) should be used.

To check if the new version of awk is installed:

awk 1 /dev/null

The output will be empty for new awk.
You have the old awk, if the output is something like

awk: syntax error near line 1

In this case nawk should be used instead awk

MS-DOS modification: echo %PATH% | awk -v RS=”;” “{ print $0 }”