KSH script
Anyone has any idea how to do script this:
This will keep two directories whose first fields are the same. I can do that by: ls | awk -F '_' ' {print $1} ' If there are more than two dir for each field it will delete anything older than 60 days. I can't figure out how to pick up two or more dir whose $1 look the same and not the rest. Then I can rm -r exec the older ones by their mtime or atime or whatevertime, I have to look that up. Any thoughts? |
What do you mean by pick-up?
I think you need to clarify your requirements. |
I agree feed a man a fish theory. That is why I only need help with this one section. By pick up I mean in a variable. How do I get a count of each individual file whose first fields are different. In other words I need to keep 2 files that are alike and rm the rest that are older by their date stamp. There are many many files with the same name. I only need the two newest one.
|
find / -type f -name "name_*" |xargs ls -tr | tail -n 2
That, or I still don't get what you wanted ... Cheers, Tink |
Here's an example:
this is the $ls en_05062010_1055 ResMorStorefrontAuthor_05062010_1109 en_05172010_0730 ResMorWebCSRSIT_05062010_1101 fr_05062010_1059 ResMorWebCSRSIT_05172010_0741 fr_05172010_0734 Tomcat_Ager.sh ls | awk -F '_' ' {print $1} ' gives me this so I can sort them by whatever is in front of the _ ( underscore) en en fr fr ResMorStorefront ResMorStorefrontAuthor ResMorWebCSRSIT ResMorWebCSRSIT I need to keep two of the files from each set of files and clip off anything older than the two newer ones. Thanks in advance |
Quote:
This is where I'm getting lost... Quote:
|
Heh ...
Same ... another stab in the dark: Code:
#!/bin/bash should delete the oldest files. Cheers, Tink |
Well I am going to go on a limb here and say that awk can probably do all of it if I am reading the file names correctly??
Apart from the Tomcat file the rest appear to have a date and time stamp after the initial name of the file so I am presuming the ls will sort them logically (someone can shoot me down if I am wrong here), so I would use: Code:
ls | awk -F_ '++_[$1] > 2{print | "rm "$0}' |
Quote:
case date == ASCII sort order. With MMDDYYYY (who dreamt that up, anyway!? ;D) you could have older files with a higher ASCII sort order than the date value last. Cheers, Tink |
thanks guys i appreciate the help
|
@Tinkster
Quote:
I was wondering if you could provide an example of where it would not work? Not doubting you just couldn't think of an example ;) |
Quote:
Code:
$ touch 04012010 No matter whether you sort ASCII or ASCII reverse, you miss out on one of the 2010 dates. Cheers, Tink |
Quote:
Cheers, Tink |
All times are GMT -5. The time now is 06:15 PM. |