Printable Version of Topic

Click here to view this topic in its original format

Linuxhelp _ Programming in Linux _ Need Help With Bash Script

Posted by: Bender Oct 7 2004, 12:12 PM

Hi

I have a directory that contains 100's of files that have similar names, lets say that format of the filename is xxx.yyy.ddd where xxx.yyy are constant and ddd is changing.

I need to delete all but the newest xxx.yyy.ddd file. making sense ?

Lets say I have some files named BAW.N.350, BAW.N.320 and BAW.N.400 where BAW.N.350 is the newest.
How would I go about making a script ( bash, python or something ) for doing that ?
I would have to go through the file listing in the directory and sort together similar filenames and then find out which is newest and delete the others.
I have very little experience with scripting so I'm a little lost sad.gif

Any ideas ?

p.s. as I say dont know if this is the place to ask this but waddaheck tongue.gif

Posted by: Hemant Oct 8 2004, 01:30 AM

1.for looping through the director listing you will need following loop.

CODE
#!/bin/bash

for x in `ls`
do
 if [$x] #check the time stamp here
 then
    rm -f "$x"
 fi
done


But this is just the guidelines.You have to use cut command for checking the time stamp.(I mean use something like ... ls -ll|cut)

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)