Removing a filename which has special characters passed from a pipe with xargs

Hi,

On AIX 5200-07-00 I have a find command as following to delete files from a certain location that are more than 7 days old. I am being told that I cannot use -exec option to delete files from these directories.
Having said that I am more curious to know how this can be done.

an sample file name could be something as follows

12345678�ABCDEFGH,11T��������N�ADSKFHADFH�R,FR�W�H�UP���������������CASDFAS123

When I use the following command

find /history_directory -mtime +7 | xargs -I {} rm -fr {}

I get the message that states that an end quote is missing as follows

xargs: 0402-060 An end quote is missing from the string:

I am assuming it is because of the single quote in the file name.

When I try the following command in the directory where the file is located.

find . | xargs grep \'

I get the same results

xargs: 0402-060 An end quote is missing from the string:

How do I resolve this issue and make the above find command work?
Please advise.

Thx
Jerardfjay

Try this:

find /history_directory -mtime +7 | xargs rm -fr {} \;

Regards

Franklin,

Thanks for your response, however that does not work. Please see below.

/home/user1/a> ls -ltr
total 0
-rw-rw-rw-   1 abcedfg  abcedfg          0 May 11 00:00 57470SWA_0030C2_____,REAR_R'L_____AEA900578A2
-rw-rw-rw-   1 abcedfg  abcedfg          0 May 11 00:00 57470SWA_0030C2_____,REAR_R'L_____AEA900578A1
/home/user1/a> find . -mtime +7
./57470SWA_0030C2_____,REAR_R'L_____AEA900578A2
./57470SWA_0030C2_____,REAR_R'L_____AEA900578A1
/home/user1/a> find . -mtime +7 | xargs rm -fr {} \;
xargs: 0402-060 An end quote is missing from the string: ./57470SWA_0030C2_____,REAR_RL_____AEA900578A2.
/home/user1/a>

Please advise.

Thx
Jerardfjay

That's a big limitation. Additionally if GNU find/xargs was installed, their -0 option could have been used to handle the bad filenames... Maybe this will help:

find /history_directory -mtime +7  | 
             while read file
                do 
                   rm  -- "$file"   
                done

[ Tested on Solaris with non-GNU tools. Does not handle filenames with embedded newlines. ]