Operating System - Linux
1819804 Members
3170 Online
109607 Solutions
New Discussion юеВ

/usr/bin/find: Argument list too long error

 
SOLVED
Go to solution
Leah Chow
Frequent Advisor

/usr/bin/find: Argument list too long error

I have a script to delete all the old oracle trace files, if the files are more than 30 days old.

find *.trc -mtime +$DAY_AFTER -exec rm {} \;

but when i execute this command, i got ' Argument list too long' error, could someone help me on this?

Thanks for your hlep
Leah
11 REPLIES 11
Heironimus
Honored Contributor
Solution

Re: /usr/bin/find: Argument list too long error

It's because you have lots of .trc files and the shell is expanding that "*.trc" to a list that's longer than find can handle. You probably want something like this:

find . -name '*.trc' -maxdepth 1 ....
Court Campbell
Honored Contributor

Re: /usr/bin/find: Argument list too long error

I would assume it is because you never gave it a path.

find [insert_path_here] *.trc -mtime +$DAY_AFTER -exec rm {} \;
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Leah Chow
Frequent Advisor

Re: /usr/bin/find: Argument list too long error

actually before this find command, i have a
cd to the $PATH.

I am wondering whether i should change the system parameter or not?

Court Campbell
Honored Contributor

Re: /usr/bin/find: Argument list too long error

Even if you cd to the path you would need to put a "." for the path in the find statement. Otherwise it thinks that the path is *.trc, ehich could be "Argument list too long".
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Leah Chow
Frequent Advisor

Re: /usr/bin/find: Argument list too long error

still doesn't work even after i added the path.

thanks
Leah
Court Campbell
Honored Contributor

Re: /usr/bin/find: Argument list too long error

jeez, you need to use -name also. look at Heironimus' example. here:

find . -name '*.trc' -mtime +$DAY_AFTER -exec rm {} \;
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Court Campbell
Honored Contributor

Re: /usr/bin/find: Argument list too long error

and ok, you technically don't need to put the "." for the path. I just think it makes it easier for others to understand where the find command is searching.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Leah Chow
Frequent Advisor

Re: /usr/bin/find: Argument list too long error

thanks, i did add the maxdepth 1 , but i didn't pay attention on the -name, now it works, thanks a lot for your help.

d4n13l
New Member

Re: /usr/bin/find: Argument list too long error

Bom dia,

Utilizei a sintax sugerida, por├йm continua retornando o erro:

find ./clilog.txt -type f -mtime +0 -maxdepth 1 -exec rm -rf '{}' ';'
/u/CA/WorkloadAutomation_R12/bin/cleanup_cli.sh: line 15: /usr/bin/find: Argument list too long

Alguma ideia de como resolver isto?

d4n13l
New Member

Re: /usr/bin/find: Argument list too long error

Executei a linha abaixo e solucionou o problema:

find ./ -mindepth 1 -maxdepth 1 -name 'clilog.*' -type f -mtime +$1 -delete

Espero ter ajudado outros usu├бrios!

Dennis Handly
Acclaimed Contributor

Re: /usr/bin/find: Argument list too long error

> I used the suggested syntax, but it still returns the error:

Not sure how you could get that error since you don't have any "*".

 

> find ./ -mindepth 1 -maxdepth 1 -name 'clilog.*' -type f -mtime +$1 -delete

-delete doesn't exist on HP-UX find(1).  You have to use: ... -exec rm -rf {} +