Help - Search - Members - Calendar
Full Version: Need Help With Bash Script
Linuxhelp > Support > Programming in Linux

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
1.for looping through the director listing you will need following loop.

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

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)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2018 Invision Power Services, Inc.