LINUX – rm not working – too many arguments – or any command not working with * because too many files/arguments
FIRST MAKE SURE YOUR IN THE RIGHT FOLDER: cd /folder_which_will_have_everything_in_it_deleted

Deleting with the following command:
# rm -rf *

Will fail if you have to many files in the folder
It will say “fail too many arguments” or something like that

Here is an option to delete all the files
# find -type f -exec echo -n {} \; -exec rm -rf {} \; -exec echo ” DELETED” \;
For every file it lists it, deletes it, and tells you DELETED after

To delete everything not just files
# find -exec echo -n {} \; -exec rm -rf {} \; -exec echo ” DELETED” \;

Or maybe do it like this files first and then directories and everything else
# find -type f -exec echo -n {} \; -exec rm -rf {} \; -exec echo ” DELETED” \;
# find -exec echo -n {} \; -exec rm -rf {} \; -exec echo ” DELETED” \;

Note: if your trying to do a command on all files with * and im not talking about just “rm”, you can also use the above method for any command. The structure is like this use “find [start directory] [select options] -exec [command1] \; -exec [command2] \; -exec [command3] \;” and so on. For [start directory] I leave blank as I am always inside the directory Use [select options] like “-type f” to select only files, or whatever select options you want. Then use {} inside your [command#] to represent the file name. So for example if find finds a file called ./folder1/file2… if you have a command that says:
find -type f -exec echo “Hi: ” {} \;
Then it will output:
Hi: ./folder1/file2

Note: I have a few more articles on find, just use the search tool above and type “linux find”

Leave a Reply

Your email address will not be published. Required fields are marked *