find command error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find command error
# 1  
Old 09-27-2012
find command error

Hi,

We have a shell script which looks into a directroy for any folder older than 30 days and removes them. The command being used is

Code:
find $ARCHIVE_DIR -type d -mtime +$PURGE_HIST_DAYS -exec rm -rf {} \;

It removes some folders but then throw below errors for others:
Code:
find: /invoice/archive/20120826/50161101: No such file or directory
find: /invoice/archive/20120826/50162736: No such file or directory
find: /invoice/archive/20120826/50164716: No such file or directory
find: /invoice/archive/20120826/50165042: No such file or directory

Why it is able to find and remove some folders but then falter on other folders? Can someone please point out what might be issue with this command?

Regards

Last edited by radoulov; 09-27-2012 at 06:53 AM..
# 2  
Old 09-27-2012
You are missing the -depth option.
# 3  
Old 09-27-2012
The problem is that find visits parent directories first, deleting them and all their contents, before attempting to visit the by then deleted files. Since find has no knowledge of the sideeffects of commands run with -exec, it is unaware that files and directories it intended to visit are now gone.

Either visit the children first with jlliagre's -depth predicate suggestion, or don't descend into deleted hierarchies by adding -prune between -mtime and -exec.

The -prune approach will be more efficient for this task.

Regards,
Alister

Last edited by alister; 09-27-2012 at 10:06 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find command giving bad status error

In a fastload teradata utility I am trying to delete the files which are older than 30days using the find and rm command as following. find . -name 'xxx_*' -mtime +30 -exec rm -f {} \; I expect it to delete all the files older than 30 days but sometimes it gives an error : find: bad status--... (3 Replies)
Discussion started by: stelkar
3 Replies

2. Shell Programming and Scripting

find command -No such file error

Hi , I tried the below code to remove the files older that 30 days . #!/bin/ksh set -x file_path1="/home/etc" file_path2="/home/hst" file_nm="HST" days=30 find $file_path1/*$file_nm* -type f -mtime +$days -exec rm -f {} \; find $file_path2/*$file_nm* -type f -mtime +$days -exec rm... (3 Replies)
Discussion started by: smile689
3 Replies

3. Shell Programming and Scripting

Find command error having space in filename

Hi, I am working in solaris.I am using below script to copy the files from /usr/tmp to /usr/gm But while running this it is not considering the files list after the filename having space in them. Example:- compile_custom_pll.sh conv_data_sqlload.sh conv_sqlload.sh Copy of... (5 Replies)
Discussion started by: millan
5 Replies

4. Shell Programming and Scripting

find command error

Hi folks, I am trying a small script to delete a files from multiple servers having a common pattern. I use this code for i in `seq -w 25 100` do echo "************host server-name*********" ssh -p 22022 server-name 'echo `hostname` && find /var/log -name "test*" ... (5 Replies)
Discussion started by: gauravsharma29
5 Replies

5. Shell Programming and Scripting

ksh - find command with 2 actions attached and error logging

Hi there, I'm encountering problems on an AIX system when using following in my script. find . -name *.edi -type f -exec sh -c 'scp {} $user@$server:$path || exit 5; mv {} $sent || exit 7' \; the error i get is following find: 0652-018 An expression term lacks a required... (4 Replies)
Discussion started by: Kerberos
4 Replies

6. UNIX for Advanced & Expert Users

find command error

Executing "find /abc -follow -ls" the message "find: cycle detected for /abc/def/ghi/ What does this mean? Thanks... (2 Replies)
Discussion started by: twk
2 Replies

7. Shell Programming and Scripting

Find Command in the script throw error

Hi I have script that is developed to serch for 30 days old Directory & Files and then remove them ... when i run it successfully removes the Directory & files & but it throw errors on the screen .. .. + find . -type f -mtime +30 -exec rm -f {} ; + exit please help me ?? I... (0 Replies)
Discussion started by: Beginner123
0 Replies

8. Shell Programming and Scripting

Perl Script Error with find command

Guys, I need to find all the files ending with either dmp or dmp.Z. This command is giving me error. @files =`find $path \(-name "*.dmp" -o -name "*.dmp.Z"\) -mtime +30`; sh: 0403-057 Syntax error at line 1 : `(' is not expected. Thanks in advance (4 Replies)
Discussion started by: MKNENI
4 Replies

9. UNIX for Dummies Questions & Answers

find command exec error

Hi All, i am writing a shell script in korn shell which deletes all the files in a directory once in every 10DAYS. the directory has different format files. the script has something like this; cd /home/data/pavi echo "Please Enter the Number of Days to search for" read DAYS... (2 Replies)
Discussion started by: pavan_test
2 Replies

10. Shell Programming and Scripting

I want to get the file which created the error when the find command was run

I want to get the file which created the error when the find command was run ? I am wrote a script to mail a list of files whose file size is ge than 0 and returns 0 but wen it finds a folder with only empty files it exits as 1. i need to modify it so that the return for this is also 0 (but it... (1 Reply)
Discussion started by: guhas
1 Replies
Login or Register to Ask a Question