From: Luke on 14 Oct 2009 12:23 Unix version is: SunOS 5.10 Generic_141414-02 sun4v sparc SUNW,T5240 I am encountering the following error: 'ksh: /usr/bin/find: arg list too long' for this script: #!/bin/ksh FILE_AGE_CRITERION_IN_DAYS=$1 FILE_NAME_PATTERN_TO_MATCH=* DIR_TO_CLEAN=$3 LOG_DIR=$4 FILES_DELETED_COUNT=0 for FILE in `find $DIR_TO_CLEAN/* -prune -type f -name "$FILE_NAME_PATTERN_TO_MATCH" -mtime +$FILE_AGE_CRITERION_IN_DAYS - print` do rm -f $FILE let "FILES_DELETED_COUNT+=1" done echo "- Deleted $FILES_DELETED_COUNT file(s) from $DIR_TO_CLEAN" | tee -a $LOG_DIR/$LOG_FILE The directory that I am trying to clean up is huge and I would prefer to not have to provide multiple file name patterns to match. Can someone provide an alternative code snippet that will: 1) Avoid the 'ksh: /usr/bin/find: arg list too long' issue 2) Delete all files in a directory that meet an age criterion 3) Not delete any files in any sub-directories (prune functionality) 4) Not delete any sub-directories in the directory TIA Luke
From: Barry Margolin on 14 Oct 2009 12:38 In article <4b12bc4e-d879-437e-8839-2b179f23f8cd(a)j39g2000yqh.googlegroups.com>, Luke <luke_airig(a)hotmail.com> wrote: > Unix version is: SunOS 5.10 Generic_141414-02 sun4v sparc SUNW,T5240 > > I am encountering the following error: > > 'ksh: /usr/bin/find: arg list too long' > > for this script: > > #!/bin/ksh > FILE_AGE_CRITERION_IN_DAYS=$1 > FILE_NAME_PATTERN_TO_MATCH=* > DIR_TO_CLEAN=$3 > LOG_DIR=$4 > > FILES_DELETED_COUNT=0 > for FILE in `find $DIR_TO_CLEAN/* -prune -type f -name > "$FILE_NAME_PATTERN_TO_MATCH" -mtime +$FILE_AGE_CRITERION_IN_DAYS - > print` > do > rm -f $FILE > let "FILES_DELETED_COUNT+=1" > done > echo "- Deleted $FILES_DELETED_COUNT file(s) from $DIR_TO_CLEAN" | tee > -a $LOG_DIR/$LOG_FILE > > > The directory that I am trying to clean up is huge and I would prefer > to not have to provide multiple file name patterns to match. > > Can someone provide an alternative code snippet that will: > > 1) Avoid the 'ksh: /usr/bin/find: arg list too long' issue > 2) Delete all files in a directory that meet an age criterion > 3) Not delete any files in any sub-directories (prune functionality) > 4) Not delete any sub-directories in the directory If your find has the -maxdepth option, you can use it to solve this problem: find $DIR_TO_CLEAN -maxdepth 1 -type f ... -- Barry Margolin, barmar(a)alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group ***
From: Eddie Corns on 14 Oct 2009 13:00 Luke <luke_airig(a)hotmail.com> writes: >Unix version is: SunOS 5.10 Generic_141414-02 sun4v sparc SUNW,T5240 >I am encountering the following error: >'ksh: /usr/bin/find: arg list too long' >for this script: >#!/bin/ksh >FILE_AGE_CRITERION_IN_DAYS=$1 >FILE_NAME_PATTERN_TO_MATCH=* >DIR_TO_CLEAN=$3 >LOG_DIR=$4 >FILES_DELETED_COUNT=0 >for FILE in `find $DIR_TO_CLEAN/* -prune -type f -name >"$FILE_NAME_PATTERN_TO_MATCH" -mtime +$FILE_AGE_CRITERION_IN_DAYS - >print` >do > rm -f $FILE > let "FILES_DELETED_COUNT+=1" >done >echo "- Deleted $FILES_DELETED_COUNT file(s) from $DIR_TO_CLEAN" | tee >-a $LOG_DIR/$LOG_FILE >The directory that I am trying to clean up is huge and I would prefer >to not have to provide multiple file name patterns to match. >Can someone provide an alternative code snippet that will: >1) Avoid the 'ksh: /usr/bin/find: arg list too long' issue >2) Delete all files in a directory that meet an age criterion >3) Not delete any files in any sub-directories (prune functionality) >4) Not delete any sub-directories in the directory >TIA >Luke The first argument to find is a path not a file so you don't use the "/*" ie find $DIR_TO_CLEAN -prune etc. Not sure if that would be enough, if the output from find was still too large it might cause the for statement to blow up. You could do something like: $ find $DIR blah blah | while read file do rm -f $file blah done Or $ echo Before `ls $DIR | wc -l` $ find $DIR blah -exec rm -f {} \; $ echo After `ls $DIR | wc -l` Eddie
From: Dagon on 14 Oct 2009 14:13 Luke <luke_airig(a)hotmail.com> wrote: >I am encountering the following error: >'ksh: /usr/bin/find: arg list too long' > .... >for FILE in `find $DIR_TO_CLEAN/* -prune -type f -name .... You're letting the shell expand the * under $DIR_TO_CLEAN, which means it's trying to pass thousands of names to the find command. Instead, pass only the one directory to find and let it figure out all the children, that's what it does. If you want to exclude the parent directory itself, include -mindepth 1. -- Mark Rafn dagon(a)dagon.net <http://www.dagon.net/>
From: Stephane CHAZELAS on 14 Oct 2009 15:13 2009-10-14, 09:23(-07), Luke: > > Unix version is: SunOS 5.10 Generic_141414-02 sun4v sparc SUNW,T5240 > > I am encountering the following error: > > 'ksh: /usr/bin/find: arg list too long' > > for this script: > > #!/bin/ksh > file_age_criterion_in_days=$1 > file_name_pattern_to_match=* > dir_to_clean=$3 > log_dir=$4 > > files_deleted_count=0 > for file in `find $dir_to_clean/* -prune -type f -name > "$file_name_pattern_to_match" -mtime +$file_age_criterion_in_days - > print` [...] files_deleted_count=$( find "$dir_to_clean/." ! -name . -prune \ ! -type d \ -name "$file_name_pattern_to_match" \ -mtime "+$file_age_criterion_in_days" \ -exec rm -f {} \; -exec echo . \; ) -- St�phane
|
Next
|
Last
Pages: 1 2 3 Prev: weird environ Next: Xlib question - efficient way to get pixel value? |