web analytics

Unix: show tcp packets

TCP packets could be catched by tcpdump:

tcpdump -n -i any ‘tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn and port 80’

UNIX: mounting CD

Here are the mount commands for different *nix systems.


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


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


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

AIX: reset user password

Change the password for the user (as root):

passwd username

Reset the login counter and unlock the user:

chsec -f /etc/security/lastlog -a "unsuccessful_login_count=0" -s username chuser "account_locked=false" username

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.

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" ;;  *) […]

Unix: rename files to lowercase

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


ls -1rt | awk ‘{ printf("mv %s %s\n", $0, tolower($0)) | "sh" } END { close("sh") }’


ls -1rt | awk ‘{ printf("mv %s %s\n", $0, toupper($0)) | "sh" } END { close("sh") }’

Unix: get the file date

ls -1 | cpio -o | cpio -ivt | awk ‘{print $NF, $(NF-1), $(NF-4), $(NF-3) }’

Warning: I/O expensive for the large files!


@a = localtime((stat($my_file))[9]); $a[4]++; printf "%02d%02d%02d",@a[5,4,3];

Redirect script output to the log

If the whole output of the complex script should be redirected to the log, the following trick could be used.

if [ "$1" != "-log" ] ; then                                      $0 -log "$@" 2>&1 | tee the_log_file.$$.log                  
   echo "The log file for the current session: the_log_file.$$.log"  
   exit 0                                                      
shift  # remove "-log" parameter

grep in find command: how to display file names

Here is very simple trick to force the grep command to display file name, when it’s used together with find operation. Just write /dev/null as the “second file”

find . -type f -exec grep somestring {} /dev/null \;

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 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 […]