Operating System - HP-UX
1836706 Members
2741 Online
110108 Solutions
New Discussion

Fail rm command: Arguments too long.

 
Miguel Carabano_1
Regular Advisor

Fail rm command: Arguments too long.

Hi Team,

I need remove approximately 32000 files, but when I execute the rm command:

Host:user> rm *.YUT
Arguments too long.

Thanks
7 REPLIES 7
Warren_9
Honored Contributor

Re: Fail rm command: Arguments too long.

Hi,

you can try to use the find command to remove the files.

e.g. find . -name \*.YUT -exec rm {} \;

GOOD LUCK!
Dennis Handly
Acclaimed Contributor

Re: Fail rm command: Arguments too long.

>I need remove approximately 32000 files

You could use rm if you give it a subset of files:
$ rm [a-b]*.YUT

>Warren: you can try to use the find command to remove the files.
e.g. find . -name \*.YUT -exec rm {} \;

Yes, this will always work. You can also speed it up if you replace "\;" by "+".
Sandman!
Honored Contributor

Re: Fail rm command: Arguments too long.

Yet another way to do this would be to supply 10 or so files at a time to rm(1). This should take care of the "Arguments too long" problem.

# ls -1 *.YUT | xargs -n10 rm
Dennis Handly
Acclaimed Contributor

Re: Fail rm command: Arguments too long.

>Sandman: would be to supply 10 or so files at a time to rm(1).
# ls -1 *.YUT | xargs -n10 rm

Probably lots more than 10. Either 100 or 40. With the right patches/config, you can do up to 1 Mb at a time.

The above ls(1) will fail exactly the same as rm(1). You need to use ls and grep:
$ ls | grep "\.YUT$" | xargs -n40 rm
A. Clay Stephenson
Acclaimed Contributor

Re: Fail rm command: Arguments too long.

Yes, ls will fail exactly as rm fails because neither of them is failing. It's the shell that is actually failing as the argument list is instantiated because the list is too large. In the old days of UNIX the argument limit was 5120 characters and now is typically measured in MiB's --- but the limit is still finite. Whenever it is possible to overflow this limit, you should always make provisons using xargs or some other mechanism so that the limit (whatever it is) never comes into play.

Moreover, it is generally a very poor design that puts so many files in a directory even if the argument limit is never reached.
If it ain't broke, I can fix that.
dileepkumarhr
Occasional Advisor

Re: Fail rm command: Arguments too long.

rm [-f] [-i] [-R] [-r] [filenames | directory]
-f Remove all files (whether write-protected or not) in a directory without prompting the user. In a write-protected directory, however, files are never removed (whatever their permissions are), but no messages are displayed. If the removal of a write-protected directory is attempted, this option will not suppress an error message.
-i Interactive. With this option, rm prompts for confirmation before removing any files. It over- rides the -f option and remains in effect even if the standard input is not a terminal.
-R Same as -r option.
-r Recursively remove directories and subdirectories in the argument list. The directory will be emptied of files and removed. The user is normally prompted for removal of any write-protected files which the directory contains. The write-protected files are removed without prompting, however, if the -f option is used, or if the standard input is not a terminal and the -i option is not used. Symbolic links that are encountered with this option will not be traversed. If the removal of a non-empty, write-protected directory is attempted, the utility will always fail (even if the -f option is used), resulting in an error message.
filenames A path of a filename to be removed.

Sandman!
Honored Contributor

Re: Fail rm command: Arguments too long.

Good point Clay and Dennis...the ls(1) will fail for the same reason as the rm(1) did.