View Single Post

  #2 (permalink)  
Old 06-06-2008, 12:29 AM
rockdalinux's Avatar
rockdalinux rockdalinux is offline
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 581
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

I hope I'm not helping with school homework problem

here is the script:
Code:
#!/bin/bash
OUT="/tmp/list.$$"
c=0
pos=$1 # file position 
dir=$2  # directory name
[ $# -ne 2 ] && exit 1 || :
find ${dir} -type f -print > $OUT
while read line
do
   (( c++ ))
   if [ $c -eq $pos ];
   then
	echo "Deleting $line at $c pos..."
        echo "/bin/rm $line"
	c=0 # reset
   fi
done < $OUT

/bin/rm $OUT
Call script as follows for 5th position and /tmp dir:
Code:
./script.sh 5 /tmp
For 10th position and /tmp/d2 dir
Code:
./script.sh 5 /tmp/d2
Read scripting book if you need further information regarding all commands used in this script.

Good luck!
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote