![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
Quote:
ls -lR | awk '$8 == "2005" && $9 ~ /Z$/ {print $0}' this assumes you done have any "non-compressed" files that end with the character "Z" |
|
||||
|
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. |
![]() |
| Bookmarks |
| Tags |
| mtime |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|