find -d with exception not working properly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find -d with exception not working properly
# 1  
Old 02-08-2011
find -d with exception not working properly

I have these following report directories that i need to cleanup (sample):

201001
201002
201003
201004 #with subdirectory 01
201005
201006 # with subdirectory 02

When I use this find command:
Code:
find . -type d -mtime 300 -print;

I got the below result which is ok for me (the subdirectories showing):
201001
201002
201003
201004
201004/01
201005
201006
201006/02

BUT: when i use the below command:
Code:
find . -type d -name "2010*" -mtime 300 -print;

I got the below result (subdirectories not showing):
201001
201002
201003
201004
201005
201006

This is a problem when i want to exclude some directories:

Code:
find . -type d -name "2010*" -mtime 300 ! -name "201006*" -print;

Above commande, I want to exclude the 201006 folder including its subdirectories. The result didnt show the main directory but showed the subdirectory.
201003
201004
201005
201006/02

The above scenarios post an issue when im trying to delete the folder with an exemption like below:
Code:
find . -type d -name "2010*" -mtime 300 ! -name "201006*" -exec rm -rf {} \;

The result is it is deleting the subfolder 201006/02 which shouldnt happen Smilie

Aprreciate if someone can shed a light on why the find command is behaving like this.

Thanks
# 2  
Old 02-08-2011
Code:
find . -type d -name "2010*" -mtime +300 |grep -v 201006 |xargs rm -rf

# 3  
Old 02-08-2011
Quote:
-mtime +300
If run today, this will look at directories with modification time older than April 13 2010 (i.e. more than 300 days ago). Unless the timestamp on your directories is unreleated to the directory name, the figure 300 seems unlikely.

I cannot explain why "-mtime 300" found anything but there was a thread recently on this board where someone had a wonky "find" command. There is much variation in the "find" command and it always helps to know what Operating System and version you have.

Given that you appear have directory names containing a date it would seem to be sensible to use the directory name rather than the "-mtime" parameter.
# 4  
Old 02-08-2011
For my understand, -mtime 300 only finds the folder/files which were modified on that day (that's April 13 2010 if your calculation is right). That's why I add + .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join not working properly

I want to join two files , with file 1 col 3 and file 2 col 1 as key. The join command is erratic for some reason. File 2 is a master file having all the names, and file 1 has some values. I want to add the names from fil2 in file 1. If I use the original master file, some output is missing. ... (16 Replies)
Discussion started by: ritakadm
16 Replies

2. Shell Programming and Scripting

Why is sort not working properly here ?

Platform: RHEL 5.4 In the below text file I have strings like following. $ cat /tmp/mytextfile.txt DISK1 DISK10 DISK101 DISK102 DISK103 DISK104 DISK105 DISK106 DISK107 DISK108 DISK109 DISK110 DISK111 DISK112 DISK113 DISK114 (8 Replies)
Discussion started by: kraljic
8 Replies

3. UNIX for Dummies Questions & Answers

~c is not working properly with -r option

Hi There, --------- file1 ------- ~c asd@ac.com -------------- Now i am using below command cat file1|mailx -s " testing" -r " My Name" abc@tech.com (3 Replies)
Discussion started by: Tapan Sharma
3 Replies

4. Shell Programming and Scripting

uuencode is not working properly

Hello Everyone, I'm very new to the shell script. I'm trying to send multiple attachments in unix using uuencode command. Total I have 3 text files which should be send in mail. but I'm getting 6 files and 3 files with subject as file name. And the content is ` end I'm working... (6 Replies)
Discussion started by: narikivar
6 Replies

5. Red Hat

sudo is not working properly

This is the first time for using sudo for me. # visudo ## Allows people in group admin to run all commands %admin ALL=(ALL) ALL # groupadd admin # useradd temp # usermod -a -G admin temp # id temp uid=506(temp) gid=506(temp) groups=506(temp),507(admin) # #sudo... (5 Replies)
Discussion started by: getrue
5 Replies

6. UNIX for Advanced & Expert Users

Sendmail is not working properly

Hi All, Can any one help me to solve the issue. The Issue is, i have started the sendmail service on my RHEL 4 update 6 box, I am able to send the mail from my box to almost all of the Email Id's except few. Exampe, test mail. . Output is :the message is sent. now if I send the... (2 Replies)
Discussion started by: akhtar.bhat
2 Replies

7. Shell Programming and Scripting

\n not working properly

Hi all, I'm trying to generate a series of txt files starting from a plain csv file part of my code: #!/bin/ksh INSTALLDIR=/Users/ME/Installdir CSV=CSV.csv TMP=/tmp/$(basename $0).txt tr -s "\r" "\n" < /$INSTALLDIR/$CSV > $TMP function Makefiles { printf '%24s:%30s\n' "sometext"... (1 Reply)
Discussion started by: Jive Spector
1 Replies

8. UNIX for Dummies Questions & Answers

Telnet is not working properly

telnet at my system is behaving stange. Some times I am able to telnet to other machines but sometimes it stop doing that. Then i have to reboot the machine and most of the time (not 100%) it works. SImilar is the case with SSH. Sometime it works , some time it don't. i am new to Unix and I do not... (1 Reply)
Discussion started by: deepak_pathania
1 Replies

9. Programming

y is this not working properly?

#include <stdio.h> #include <sys/types.h> #include <string.h> #include <sys/stat.h> #include <unistd.h> struct stat s; main() { char c; if (fork()==0) { system("clear"); do { printf("myAI\\>§ "); scanf("%s",c); if(stat(c,&s)>-1) {... (3 Replies)
Discussion started by: C|[anti-trust]
3 Replies

10. UNIX for Dummies Questions & Answers

Keyboard not working properly...

Hello Again, Those that have noticed my earlier posts will know that I have succesfully installed Solaris 8 onto my pc. I haven't been able to get x-server working (i think it doesn't like my video card) though I've been able to log into root (with a bit of help from unix forums :o ) and have... (2 Replies)
Discussion started by: timresh
2 Replies
Login or Register to Ask a Question