The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Archiving Problem bintaleb UNIX for Dummies Questions & Answers 2 03-11-2007 07:47 AM
Archiving dreams5617 Shell Programming and Scripting 1 10-20-2006 06:33 AM
Archiving Users suseesk Shell Programming and Scripting 2 04-10-2006 10:10 AM
archiving a directory using tar harminder UNIX for Dummies Questions & Answers 2 09-22-2005 06:23 AM
Archiving rmasonuk UNIX for Dummies Questions & Answers 7 11-10-2003 02:07 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-18-2008
aefskysa aefskysa is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 7
Archiving by Time

Hi all. I am trying to set up archiving of directories, such that I keep every directory made in the past week, but just one directory per week beyond that. Using the find command, I can easily delete everything more than one week old, but can not figure out how to save one.

Each directory contains a single zip file. I'd prefer to keep the one with the largest zip file, but this is not necessary. If someone can tell me how I can keep just one directory, regardless of criteria, I would be greatly appreciative.

I realize that this could probably be done by hand, but a zip file and directory is created ~every 30 minutes, so it would be rather tedious.

Thanks for any help you can provide.

EDIT: This archiving is currently done (deleting everything more than a week old) in a shell script that is called by the program. This script creates and moves the zip file from a bunch of jpg's. Hence, I figured this was the correct sub-forum. If not, let me know and I will be glad to move it.

Last edited by aefskysa; 07-18-2008 at 06:43 AM.. Reason: Addition
  #2 (permalink)  
Old 07-18-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
So is this solved or still open?

If it is still open - why not do a find to get largest of them, safe it first, and then delete all of them (if I got it right)?
  #3 (permalink)  
Old 07-18-2008
aefskysa aefskysa is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 7
It is still open. I did not see an option among the man page for "find" to get the largest file. Which option is it?
  #4 (permalink)  
Old 07-18-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
Sorry, might be misleading, as find can only show files compared to some size, what might give you still too many files, instead of 1 for the largest. Here is a bit lengthy explanation, how you could handle this and implement in the script you already have:

Code:
root@isau02:/data/tmp/testfeld> ll
insgesamt 36
drwxr-xr-x 2 isau users 4096 2008-07-18 13:59 .
drwxr-xr-x 7 isau users 4096 2008-07-09 14:36 ..
-rwx------ 1 root root   197 2008-07-08 10:00 array.ksh
-rw-r--r-- 1 root root    98 2008-07-17 14:31 infile
-rwx------ 1 root root   207 2008-07-04 10:10 input.ksh
-rwx------ 1 root root   328 2008-07-08 09:21 loop.ksh
-rwx------ 1 root root    27 2008-07-18 13:59 mach.ksh
-rw-r--r-- 1 root root   845 2008-07-08 07:58 NMEA.txt
-rw-r--r-- 1 root root     0 2008-07-18 13:55 temp2.txt
-rwx------ 1 root root   174 2008-06-27 13:25 weekend_is_close.ksh
root@isau02:/data/tmp/testfeld> find . -type f -exec ls -la {} \;| awk '{print $5,$NF}'
207 ./input.ksh
328 ./loop.ksh
845 ./NMEA.txt
98 ./infile
197 ./array.ksh
27 ./mach.ksh
0 ./temp2.txt
174 ./weekend_is_close.ksh
root@isau02:/data/tmp/testfeld> find . -type f -exec ls -la {} \;| awk '{print $5,$NF}'| sort -k 1,1n
0 ./temp2.txt
27 ./mach.ksh
98 ./infile
174 ./weekend_is_close.ksh
197 ./array.ksh
207 ./input.ksh
328 ./loop.ksh
845 ./NMEA.txt
root@isau02:/data/tmp/testfeld> find . -type f -exec ls -la {} \;| awk '{print $5,$NF}'| sort -k 1,1n| tail -1| awk '{print $2}'
./NMEA.txt

Last edited by zaxxon; 01-20-2009 at 05:45 AM.. Reason: removed a domain name
  #5 (permalink)  
Old 07-18-2008
aefskysa aefskysa is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 7
That is quite helpful, but seems to be missing the final step. Once I pick out that file, how can I execute any other command on it? I am thinking I just want to 'touch' that file and make the date far enough in the past that the script will cease caring about it. Thanks again.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0