PDA

View Full Version : I cant remove files - says too many arguments


Atjeu
11-25-2003, 12:53 PM
If you are trying to remove files from a directory with rm or rm -rf * and you cant because you get the error there are too many arguments, you can do this

cd to the directory you want to remove all the files from and run this

ls |xargs rm

and everything in that directory will go away.

Erik
12-04-2003, 10:55 PM
'ls | xargs rm' only works if you are attempting to delete files. If there are directories present an error will be printed letting you know that something couldn't be removed. If you want to delete files and directories add the following options to the command:
ls | xargs rm -fr

Beware: Once you start this it will delete everything from the current directory on that the user has permission to remove. Example: bad idea to run as root while you are in the root (/) directory :)

Erik
12-04-2003, 11:38 PM
One other point: you have to do this command in the dircetory that you want to delete.

You can not do something like this: 'ls /tmp | xargs rm -fr' while you are in /home. If you do something like this then whatever ls finds /tmp xargs will attempt to remove in /home. Example: if ls finds /tmp/123.txt xargs will attempt to remove /home/123.txt.

So if you attempt to use this command in a script you first need to change the working directory to the one you want to delete stuff from.