delete compressed files from year 2005


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers delete compressed files from year 2005
# 1  
Old 03-23-2007
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  
Old 03-23-2007
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  
Old 03-23-2007
That worked! Thank you
# 4  
Old 03-23-2007
how do I remove only those files tha I captured using that command?
do I substitute rm -f for the print $0
# 5  
Old 03-23-2007
Bug

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  
Old 03-23-2007
Thank you. this is a big help!!!
I appreciate it!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Validate compressed files

Hi All, I have zip file that needs to be validated and checked for 5 times with sleep of 60 seconds. Some thing like below #!/bin/bash counter=1 while do curl -i -k -X GET `strings tmp.txt |grep Location| cut -f2 -d" "` -H "Authorization: Token $TOKEN" -o $zip_file ## this is... (6 Replies)
Discussion started by: Master_Mind
6 Replies

2. UNIX for Beginners Questions & Answers

Delete all files created in specific year

I have more than 200K files created in year 2017 under directory having size of 50GB. I want to all these files in one shot. Is there any faster option available with find command to delete all these file ? (6 Replies)
Discussion started by: sp23029
6 Replies

3. Shell Programming and Scripting

Delete files using year

Hi All, how can i delete files from my Unix directory on the basis of year, i have files from 2001 to till 2014, but from their, i have to delete only 2013 file.Below is my file name rwxrwxrwx 1 guopt users 5169 Jul 12 00:30 grt592_20130712003000.SAP Thanks Kki (2 Replies)
Discussion started by: kki
2 Replies

4. Shell Programming and Scripting

Delete files older than 1 year through FTP

Hi All, I want to login to a remote server using FTP command and then check for files older than 1 year and delete those files. Please let me know how can i achieve this using Unix Commands. Thanks in Advance, (10 Replies)
Discussion started by: HemaV
10 Replies

5. Shell Programming and Scripting

Delete all the files and subdirectories for the year 2006

Hi I have lot of files and subdirectories inside a directory which are created in the years 2006, 2007, 2008, 2009 and 2010. I want to delete all the files and subdirectories belonging to the year 2006 alone. How can I do that ? (5 Replies)
Discussion started by: samsungsamsung
5 Replies

6. UNIX for Dummies Questions & Answers

Delete files by year

can someone provide a command to delete files by year? I have several files created last year 2009. Im trying to list first ls -lrt | grep '/2009/ {print $10}' by it returns no result. Pls advise (2 Replies)
Discussion started by: lhareigh890
2 Replies

7. UNIX for Dummies Questions & Answers

Extracting data from many compressed files

I have a large number (50,000) of pretty large compressed files and I need only certain lines of data from them (each relevant line contains a certain key word). Each file contains 300 such lines. The individual file names are indexed by file number (file_name.1, file_name.2, ... ,... (1 Reply)
Discussion started by: Boltzmann
1 Replies

8. UNIX for Dummies Questions & Answers

How to distribute compressed files as text?

Hello everybody, I've seen some text documents where they publish blocks of text and tell you to save it as "file.tgz" for example, and when you decompress the file, it actually works. How is that done? is there a program? Because i tried cat and doesn't work, tried less, more, hexedit and... (2 Replies)
Discussion started by: semash!
2 Replies

9. UNIX for Dummies Questions & Answers

To view compressed files

Hello All I compressed a file hello by using compress command compress hello ( enter ) i got the file as hello.z 1. My question is how can i see the file hello.z 2. How can i uncompress it back to change it to filename hello thanks (4 Replies)
Discussion started by: supercops
4 Replies

10. UNIX for Dummies Questions & Answers

multi part compressed files

Hi there, not sure if I am in the right place but here is my question. I have a file that is over 100mb and my host does not allow FTP of files above 100mb so I thought I would use a compression utility to compress it into smaller parts say 10mb each, upload them and then re-assemble them on... (7 Replies)
Discussion started by: gffb
7 Replies
Login or Register to Ask a Question