Delete all the files and subdirectories for the year 2006


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete all the files and subdirectories for the year 2006
# 1  
Old 11-04-2010
Error 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 ?
# 2  
Old 11-04-2010
Code:
find directory -type f -ls | awk '($10=="2006"){print $11}' | xargs -n10 rm

This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 11-04-2010
If these files are not modified in 2006.

Code:
find directory -type f -mtime +1200 -exec rm {} \;

You can replace 1200 to any day.
This User Gave Thanks to rdcwayx For This Post:
# 4  
Old 11-04-2010
Code:
touch -t 200512312359.59 oldest
touch -t 200701010000.00 newest
find /dir -newer oldest \! -newer newest -exec rm -f {} \;

This User Gave Thanks to pludi For This Post:
# 5  
Old 11-04-2010
Bug hi

Quote:
Originally Posted by ctsgnb
Code:
find directory -type f -ls | awk '($10=="2006"){print $11}' | xargs -n10 rm

hi

Thanks for your reply.

Is there a way to find how many files and subdirectories are present currently inside the directory with the year stamp as 2006 ?
# 6  
Old 11-04-2010
Not sure about what you mean by "inside the directory with the year stamp as 2006"

Will count the number of files stamped as 2006 inside directory (no matter how deep they can be in subdir, if you don't want to go in subdir, just add the -prune option to the find command)
Code:
find directory -type f -ls | awk '($10=="2006"){print $11}' | wc -l

will count the number of subdirectories stamped as 2006 inside directory (no matter how deep they can be in the directory tree, if you don't want to go in subdir, just add the -prune option to the find command)
Code:
find directory -type d -ls | awk '($10=="2006"){print $11}' | wc -l

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 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

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

5. AIX

Want to delete directory, subdirectories and all files which are older than 7 days

how do i remove sub directories of a directory and all files which are older than 7 days by a single command in AIX. pls help me. I am using command as #find /gpfs1/home/vinod/hpc/ -depth -type d -mtime +7 -exec rm -rf {} \; so i want to delete all sub directories and all files from the... (1 Reply)
Discussion started by: vinodkmpal
1 Replies

6. 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

7. Shell Programming and Scripting

How to delete subdirectories that are more than 1 day old AND have NO files on them

Hi Experts , At a particular dir , How to delete subirectories that are more than 1 day old AND have NO files in them. PS : -empty option is not working at my Sun OS version. Thanks, A (6 Replies)
Discussion started by: ajaypatil_am
6 Replies

8. 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

9. Shell Programming and Scripting

shell script to find and copy the files creted in the year 2006 to another directory

Hi All, I am new to UNIX. I will be thankful if some one helps me. I have to write a shell script for one of the requirement. I have files created from Jan 2006 to March 2008. My requirement is to write a script in such a way that 1) To find and copy(not Moving) the files created in the... (2 Replies)
Discussion started by: manas6
2 Replies

10. UNIX for Dummies Questions & Answers

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 |... (5 Replies)
Discussion started by: igidttam
5 Replies
Login or Register to Ask a Question