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
Reg: delete older files from ftp sam99 UNIX for Dummies Questions & Answers 3 01-09-2008 10:56 AM
tar'ing and zipping files FredSmith UNIX for Dummies Questions & Answers 4 05-02-2006 03:09 PM
rm files older than ... annemar UNIX for Dummies Questions & Answers 2 02-08-2006 05:47 AM
files older than 15 minutes sveera Shell Programming and Scripting 0 08-05-2005 02:05 PM
tar files older than 30 days wfch UNIX for Dummies Questions & Answers 6 04-19-2004 04:40 AM

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

Join Date: Sep 2006
Posts: 56
Zipping files older than one month

I have to zip all files older than a month within a directory.
I have to archive them using the file extension
I have .dat, .csv ,.cnt files within the directory.

I used the following command It doesnt work
find /path/*.dat -mtime +30
This command doesnot display .dat files older than a month

I used a different method which is tedious, but does the zipping month wise

zip dat_zip.zip `ls -rtl *.dat|grep Jan |awk '{print $9}'`

After doing this I have the zip files in the zip directory, but if i remove Jan files from the folder using this command
ls -rtl *.dat | grep Jan | awk '{print $9}' | rm *.dat
I lose all the dat files for other months too.
As per my knowledge '|' gives o/p from previous command as I/p for next command , why am i losing all the .dat files(from other months too)

Guru's Please shed some light.

Thanks and Regards,
Ram.
  #2 (permalink)  
Old 04-07-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
Try:

Code:
find /path -name "*.dat" -mtime +30
Regards
  #3 (permalink)  
Old 04-07-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Quote:
ls -rtl *.dat | grep Jan | awk '{print $9}' | rm *.dat
This is basically equivalent to

Code:
ls -rtl *.dat | grep Jan | awk '{print $9}' >/dev/null
rm *.dat
so no wonder your *.dat files are gone. The right syntax for using the pipeline (and avoiding the Useless Use of grep | awk) is

Code:
ls -rtl *.dat | awk '/Jan/{print $9}' | xargs rm
or you could use backticks, but they are always a bit perilous, IMHO.
Sponsored Links
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 11:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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