Archive for November, 2009

Linux Network Setup/Monitor commands

Posted on November 30, 2009. Filed under: Linux | Tags: , , , , |

1. check devices status:

lspci  (dmidecode, lsusb, lshw , lspci)


2.  Check the network status:

mii-tool  (you should be root)

ip link


3. NIC card change sequence:



/lib/udev/rename_netiface <old> <new>


4. iftop

a good console bandwidth visualization tool that shows you active
connections, where they are going to/from and how much of your precious bandwidth
they are using.

iftop is a command-line system monitor tool that produces a frequently-updated list of network connections. By default, the connections are ordered by bandwidth usage, with only the “top” bandwidth consumers shown.


5. iptraf

IPTraf is a console-based network statistics utility for Linux. It gathers a variety of figures such as TCP connection packet and byte counts, interface statistics and activity indicators, TCP/UDP traffic breakdowns, and LAN station packet and byte counts.

Read Full Post | Make a Comment ( 1 so far )

BASH Shell: For Loop File Names With Spaces

Posted on November 20, 2009. Filed under: Linux, Mac, Shell | Tags: , , , , , , |

BASH for loop works nicely under UNIX / Linux / Windows and OS X while working on set of files. However, if you try to process a for loop on file name with spaces in them you are going to have some problem. for loop uses $IFS variable to determine what the field separators are. By default $IFS is set to the space character. There are multiple solutions to this problem.

Set $IFS variable

Try it as follows:

IFS=$(echo -en "\n\b")
for f in *
  echo "$f"


IFS=$(echo -en "\n\b")
# set me
for f in $FILES
  echo "$f"
# restore $IFS

More examples using $IFS and while loop

Now you know that if the field delimiters are not whitespace, you can set IFS. For example, while loop can be used to get all fields from /etc/passwd file:

while IFS=: read userName passWord userID groupID geCos homeDir userShell
      echo "$userName -> $homeDir"
done < /etc/passwd

Using old good find command to process file names

To process the output of find with a command, try as follows:

find . -print0 | while read -d $'' file
  echo -v "$file"

Try to copy files to /tmp with spaces in a filename using find command and shell pipes:

find . -print0 | while read -d $'' file; do cp -v "$file" /tmp; done

Processing filenames using an array

Sometimes you need read a file into an array as one array element per line. Following script will read file names into an array and you can process each file using for loop. This is useful for complex tasks:


# failsafe - fall back to current directory
[ "$DIR" == "" ] && DIR="." 

# save and change IFS

# read all file name into an array
fileArray=($(find $DIR -type f))

# restore it

# get length of an array

# use for loop read all filenames
for (( i=0; i<${tLen}; i++ ));
  echo "${fileArray[$i]}"

Playing mp3s with spaces in file names

Place following code in your ~/.bashrc file:

	local o=$IFS
	IFS=$(echo -en "\n\b")
	/usr/bin/beep-media-player "$(cat  $@)" &

Keep list of all mp3s in a text file such as follows (~/eng.mp3.txt):

/nas/english/Adriano Celentano - Susanna.mp3
/nas/english/Nick Cave & Kylie Minogue - Where The Wild Roses Grow.mp3
/nas/english/Roberta Flack - Kiling Me Softly With This Song.mp3
/nas/english/The Beatles - Girl.mp3
/nas/english/John Lennon - Stand By Me.mp3
/nas/english/The Seatbelts, Cowboy Bebop - 01-Tank.mp3

To play just type:
$ mp3 eng.mp3.txt

Another example about IFS:


set $(cat my.file)

# Now the lines are stored in $1, $2, $3, …

echo $1
echo $2
echo $3
echo $4


Read Full Post | Make a Comment ( None so far )

Install Chromium (Google chrome) web browser in Ubuntu

Posted on November 10, 2009. Filed under: Linux |

Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all Internet users to experience the web. The Chromium codebase is the basis for Google’s Chrome browser.

First you need to edit the /etc/apt/sources.list file

sudo gedit /etc/apt/sources.list

Add one of the following

For ubuntu 9.10 (armic) Users add the following two lines

deb karmic main

deb-src karmic main

For ubuntu 9.04 (Jaunty) Users add the following two lines

deb jaunty main

deb-src jaunty main

For ubuntu 8.10 (Intrepid) Users add the following two lines

deb intrepid main

deb-src intrepid main

Save and exit the file Now add the GPG key using the following command

sudo apt-key adv –recv-keys –keyserver 0xfbef0d696de1c72ba5a835fe5a9bf3bb4e5e17b5

Update the source list using the following command

sudo apt-get update

Install chromium using the following command

sudo apt-get install chromium-browser

Using Chromium You can open chromium from Applications—>Internet—>Chromium Web Browser



Read Full Post | Make a Comment ( None so far )

Bash small tricks

Posted on November 2, 2009. Filed under: Linux, Shell |

1. How to get the output of the command? (Not the return/exit status of the command)

ret=$(echo 123)


ret=`echo 123`

Read Full Post | Make a Comment ( None so far )

Useful linux commands: null,zero,full,lsof

Posted on November 1, 2009. Filed under: Linux | Tags: , , , |

Linux / Unix Command: null


null, zero – data sink


Data written on a null or zero special file is discarded.

Reads from the null special file always return end of file, whereas reads from zero always return characters.

null and zero are typically created by:

mknod -m 666 /dev/null c 1 3
mknod -m 666 /dev/zero c 1 5
chown root:mem /dev/null /dev/zero
chmod 666 /dev/null /dev/zero


File /dev/full has major device number 1 and minor device number 7.

Writes  to  the  /dev/full device will fail with an ENOSPC error.  This
can be used to test how a program handles disk-full errors.

Reads from the /dev/full device will return characters.

Seeks on /dev/full will always succeed.

If your system does not have /dev/full created already, it can be  cre-
ated with the following commands:

mknod -m 666 /dev/full c 1 7
chown root:root /dev/full


man full


lsof is a command meaning “list open files”, which is used in many Unix-like systems to report a list of all open files and the processes that opened them. This open source utility was developed and supported by Vic Abell, the retired Associate Director of the Purdue University Computing Center. It works in and supports several UNIX flavors.[2]

Open files in the system include disk files, pipes, network sockets and devices opened by all processes. One use for this command is when a disk cannot be unmounted because (unspecified) files are in use. The listing of open files can be consulted (suitably filtered if necessary) to identify the process that is using the files.

# lsof /var
syslogd     350     root    5w  VREG  222,5        0 440818 /var/adm/messages
syslogd     350     root    6w  VREG  222,5   339098   6248 /var/log/syslog
cron        353     root  cwd   VDIR  222,5      512 254550 /var -- atjobs

To view the Port associated with a daemon :

 # lsof -i -n -P | grep sendmail
 sendmail  31649    root    4u  IPv4 521738       TCP *:25 (LISTEN)

From the above we can see that “sendmail” is listening on its standard port of “25”.

  • -i Lists IP sockets.
  • -n Do not resolve hostnames (no DNS).
  • -P Do not resolve port names (list port number instead of its name).


man lsof

Read Full Post | Make a Comment ( None so far )

Liked it here?
Why not try sites on the blogroll...