Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
 
Reply to this topicStart new topic
> Need Help With Bash Script, not sure if this is the right place but
Bender
post Oct 7 2004, 12:12 PM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 4
Joined: 6-July 03
Member No.: 1,056



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
Go to the top of the page
 
+Quote Post
Hemant
post Oct 8 2004, 01:30 AM
Post #2


RMS is my Hero
******

Group: Support Specialist
Posts: 782
Joined: 6-October 02
From: Trichy,INDIA
Member No.: 29



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)


--------------------
Hemant Kumar
user posted image
hemant@linuxhelp.net
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 18th November 2017 - 09:10 AM