Operating System - HP-UX
1833875 Members
1656 Online
110063 Solutions
New Discussion

Re: HP-UX find command unable to remove files from directories multiple levels deep

 
SOLVED
Go to solution
kaushikbr
Frequent Advisor

HP-UX find command unable to remove files from directories multiple levels deep

Hello Experts

I'm writing a ksh script to find and remove files and directories that are multiple levels deep. A typical directory looks somewhat like this

/hpcnfs4/nfsdir/data/PRIVATE_DATA/username/aileron/reduced_spec_test/Pressure read/Res_DPA1_H2_Pres_ip/MERGE/OUTPUT/reduced_spec_test/Pressure read/Res_DPA1_H2_Pres_ip/MERGE/OUTPUT/reduced_spec_test/Pressure/Res_DPA1_H2_Pres_ip/MERGE/OUTPUT/reduced_spec_test/Pressure read/Res_DPA1_H2_Pres_ip/MERGE/OUTPUT/reduced_spec_test/Pressure read/Res_DPA1_H2_Pres_ip/MERGE/OUTPUT/reduced_spec_test/Pressure read/Res_DPA1_H2_Pres_ip/MERGE/OUTPUT/reduced_spec_test/Pressure read/Res_DPA1_H2_Pres_ip/MERGE/OUTPUT/reduced_spec_test/Pressure read/Result_DPA1_H2_Pressure_op/MERGE/OUTPUT/reduced_spec_test/Pressure read/Result_DPA1_H2_Pressure_op/MERGE/OUTPUT/reduced_spec_test/Pressure read/Result_DPA1_H2_Pressure_op/MERGE/OUTPUT\reduced_spec_test/Pressure read/Result_DPA1_H2_Pressure_op/MERGE/OUTPUT\reduced_spec_test/Pressure read/Result_DPA1_H2_Pressure_op/MERGE/OUTPUT\reduced_spec_test/Pressure read/Result_DPA1_H2_Pressure_op/MERGE/OUTPUT\reduced_spec_test/Pressure read/Result_DPA1_H2_Pressure_op/GP7/OUTPUT\

That is right the directory name has back slashes and blank spaces
( /Preasure read/, OUTPUT\).
The current filesystem is mounted on a windows machine, hence the blank spaces and back slashes in the directory name.

I'm writing a script to look for such directories, remove files and them remove the underlying directory.

I have tried using find -exec rm option.. it fails with 'Pathname exceeds system limitations'. Not sure how else I can remove these files and directories.

Thanks all for your valuable responses.

Please note I'm not a perl expert, hence writing a ksh shell script.

Regards
K
11 REPLIES 11
James R. Ferguson
Acclaimed Contributor

Re: HP-UX find command unable to remove files from directories multiple levels deep

Hi:

Did you quote the directory name arguments to 'find()'?

For example:

# find "/Pressure read OUTPUT\" -exec ls -ld {} +

Regards!

...JRF...
Pete Randall
Outstanding Contributor

Re: HP-UX find command unable to remove files from directories multiple levels deep

It might help if you provided the find command you used. My first thought is that you need to quote things because of the backslashes and spaces, but I can't see your command.


Pete

Pete
Manix
Honored Contributor

Re: HP-UX find command unable to remove files from directories multiple levels deep

Could be a issue with the difference in
path names in window client machine

You may try the commands like below ,with -xdev option if it works

find / -size +1000c -mtime 100 -type f -exec -xdev rm {} \;

find /path -mtime +30 -type f -exec -xdev rm {} \;

Thanks
Manix
HP-UX been always lovable - Mani Kalra
kaushikbr
Frequent Advisor

Re: HP-UX find command unable to remove files from directories multiple levels deep

I have attached my script.

I'm using
find "$direc" -name "*.*" -type f -exec rm {} \;

Since there are many such directories, I read all the directories in a loop and process each directory. The env variable "$direc" holds the directory information.

Thanks and Regards
K
Steven Schweda
Honored Contributor

Re: HP-UX find command unable to remove files from directories multiple levels deep

> I have attached my script.

It might be easier if you supplied only a
failing command (with its output) instead of
a whole script (which can't easily be tested
by others).
Dennis Handly
Acclaimed Contributor
Solution

Re: HP-UX find command unable to remove files from directories multiple levels deep

>The current filesystem is mounted on a windows machine, hence the blank spaces and backslashes in the directory name.

I can understand evil spaces but shouldn't the backslashes be converted to slashes for each directory component?

>it fails with 'Pathname exceeds system limitations'.

Is this a Windows error?
You may have to cd into that directory and remove files from that CWD.
Emil Velez
Honored Contributor

Re: HP-UX find command unable to remove files from directories multiple levels deep

might have to use single quote and not do variable substitution.
kaushikbr
Frequent Advisor

Re: HP-UX find command unable to remove files from directories multiple levels deep

Hi

Thank you all for your replies.
Some background to the problem -
The users use an application that has this inherent feature of creating these recursive directories. Our backups are failing because of these multiple levels of subdirectories. Hence the script to tidy up this, until the problem with the application is fixed.

I'm afraid, I'm not allowed to change the directory naming, hence I have to process backslashes. Since this filesystem is hosted on a HP-UX 11.31 which is then mapped onto windows PCs.

The 'Pathname exceeds system limitations' error message is on the HP-UX machine.

Thanks and Regards
Kaushik
James R. Ferguson
Acclaimed Contributor

Re: HP-UX find command unable to remove files from directories multiple levels deep

Hi (again):

> The users use an application that has this inherent feature of creating these recursive directories.

Are they really recursive?

I would try adding '! -follow' to your 'find' expression.

> The 'Pathname exceeds system limitations' error message is on the HP-UX machine.

This might be 'find' abandoning searches that are truly recursive. As I said, try preventing the visit of symbolic links with ' ! - follow '.

Also, unless your full path name exceeds the value of 'getconf POSIX_PATH_MAX' characters (which should be 255 characters), you should otherwise be fine.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: HP-UX find command unable to remove files from directories multiple levels deep

Hi (again):

Since you have given a "bunny" at this point, suggesting a solution to your problem, what exactly was the solution?

Regards!

...JRF...
kaushikbr
Frequent Advisor

Re: HP-UX find command unable to remove files from directories multiple levels deep

Hi All

Thank you all for your valuable comments.
Dennis Handly's suggestion of cd to the directory and remove the files from CWD worked. It was a bit of a workaround, but it worked.
Here is what I have changed in the script.


find "$direc" -type f >> ${REMOVEFILE_LIST}

while read FILE2REMOVE
do
echo "File --- "
echo "$FILE2REMOVE"
echo " "
cd $(dirname "$FILE2REMOVE")
ls -l "$(basename "$FILE2REMOVE")"
rm "$(basename "$FILE2REMOVE")"
ls -l "$(basename "$FILE2REMOVE")"
done < ${REMOVEFILE_LIST}