The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
multi part compressed files gffb UNIX for Dummies Questions & Answers 7 05-01-2008 08:32 PM
diff on compressed files with tar.gz ext rakeshou UNIX for Dummies Questions & Answers 7 09-20-2007 03:27 PM
Line count for compressed files swamy455 Shell Programming and Scripting 1 08-02-2007 11:40 PM
how to know year create/modified files? blesets UNIX for Dummies Questions & Answers 5 03-10-2007 12:20 AM
import compressed files using pipe pengwyn UNIX for Dummies Questions & Answers 0 07-19-2005 03:57 AM

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 03-23-2007
igidttam igidttam is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 22
delete compressed files from year 2005

I'm trying to delete files that were created/modified in the year 2005 that we compressed and have the .Z extension on them. I tried using the awk utility but the syntax is incorrect. I don't know how to use a wildcard to capture all the compressed files. Here's the code I used

( ls -lR | awk '$8 == "2005" && $9 == ".Z" {print $0}' )

Any suggestions on how to do this would be greatly appreciated.
Thanks
  #2 (permalink)  
Old 03-23-2007
awk awk is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
Quote:
Originally Posted by igidttam
I'm trying to delete files that were created/modified in the year 2005 that we compressed and have the .Z extension on them. I tried using the awk utility but the syntax is incorrect. I don't know how to use a wildcard to capture all the compressed files. Here's the code I used

( ls -lR | awk '$8 == "2005" && $9 == ".Z" {print $0}' )

Any suggestions on how to do this would be greatly appreciated.
Thanks
Try this -

ls -lR | awk '$8 == "2005" && $9 ~ /Z$/ {print $0}'

this assumes you done have any "non-compressed" files that end with the character "Z"
  #3 (permalink)  
Old 03-23-2007
igidttam igidttam is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 22
That worked! Thank you
  #4 (permalink)  
Old 03-23-2007
igidttam igidttam is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 22
how do I remove only those files tha I captured using that command?
do I substitute rm -f for the print $0
  #5 (permalink)  
Old 03-23-2007
awk awk is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
Smile

It is never quite that easy, are there any subdirectories to worry about (your command for the ls included the -R option?

for that possibility, the best option would be

find ./ -type f -name '*.Z' -exec ls -l {} \; | awk '$8 == 2005{print $NF}' | xargs rm -f

of course, you could use a system command in awk, but I prefer to do that outside the awk.

This assumes your system supports all these commands.

Basically, this says - for all Files in this directory and all subdirectories whose filename ends with a .Z, do a long listing of it, see if the year is 2005 and if so print only the file name (including directory), and for those passing through the awk, do a "rm -f" on them.

technically, it is possible to add the mtime to the find to choose only those for 2005, but I agree that it just as easy to use the awk as this filter. However, using the right mtime parameters, it could all be done in one command (without pipes) by doing

find ./ -type f -name '*.Z' -mtime +days -mtime -days -exec rm -f {} \;

but I am too lazy to calculate what the two days parameters would need to be.
  #6 (permalink)  
Old 03-23-2007
igidttam igidttam is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 22
Thank you. this is a big help!!!
I appreciate it!
Closed Thread

Bookmarks

Tags
mtime

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 05:44 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