From: Joachim Schmitz on
Stephane CHAZELAS wrote:
> 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 . \;
> )

Why not just
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 . \;
)

I.e. without the /. ?

Bye, Jojo
From: Bjarni Juliusson on
> 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,

Make that "-maxdepth 1" to never descend into any subdirectories.

find $DIR_TO_CLEAN -maxdepth 1 -type f
-name "$FILE_NAME_PATTERN_TO_MATCH"
-mtime +$FILE_AGE_CRITERION_IN_DAYS

The -print isn't needed.


Bjarni
--

INFORMATION WANTS TO BE FREE
From: Stephane CHAZELAS on
2009-10-15, 10:34(+02), Bjarni Juliusson:
>> 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,
>
> Make that "-maxdepth 1" to never descend into any subdirectories.
[...]

-maxdepth is a GNU extension (also recognised by some BSDs), it
won't work on Solaris. See the \( -name . -o -prune \) standard
equivalent (or ! -name . -prune for the standard equivalent of
-mindepth 1 -maxdepth 1).

--
St�phane
From: Stephane CHAZELAS on
2009-10-15, 09:32(+02), Joachim Schmitz:
[...]
>> 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 . \;
>> )
>
> Why not just
> 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 . \;
> )
>
> I.e. without the /. ?
[...]

~$ mkdir -p 1/2/3
~$ find 1 ! -name . -prune -print
1
~$ find 1/. ! -name . -prune -print
1/./2

--
St�phane
From: Joachim Schmitz on
Stephane CHAZELAS wrote:
> 2009-10-15, 09:32(+02), Joachim Schmitz:
> [...]
>>> 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 . \;
>>> )
>>
>> Why not just
>> 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 . \;
>> )
>>
>> I.e. without the /. ?
> [...]
>
> ~$ mkdir -p 1/2/3
> ~$ find 1 ! -name . -prune -print
> 1
> ~$ find 1/. ! -name . -prune -print
> 1/./2

Ah, yes, I missed the -prune, thanks

Bye, Jojo