This is a discussion on Linux Workaround for ‘Argument list too long’ error message while removing all files within the Computer hardware and software tips and tricks forums, part of the News and views category; Linux Workaround for ‘Argument list too long’ error message while removing all files from a directory While someone deleting the ...
| |||||||
| Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| | #1 |
| Join Date: Jan 2006 Location: New Delhi Age: 31
Posts: 3,345
Rep Power: 10 | Linux Workaround for ‘Argument list too long’ error message while removing all files from a directory While someone deleting the files by using rm on the linux server, he might face this problem. There is a maximum number of files that can be passed as arguments to rm. So it does not allow you remove the files with ‘rm’ command. Using rm to delete files is the easiest way adopted by linux users. Well, I see that if this does not work, there is a solution provided for this problem. As mentioned, there were around 72K files were generated in a folder which needed to be deleted. In the example, there are all the files starting with “Count”, so can be chosen using “Count*”. Here is the output on command prompt. root # rm Count* /bin/rm: Argument list too long. The workaround as given is: Use find to pipe all the matching files to rm, one at a time. root # find . -name ‘Count*’ | xargs rm And this can remove as many files as you want. Perfect!! Not yet… The “find | xargs” solution doesn’t work on files with spaces.Now what to do? The only reliable way I could find is to use find . -name ‘Count*’ -exec rm {} \; but there’s a caveat: it will look for Count* in subdirectories as well, which may be undesireable. So in that case, -maxdepth 0 does the trick. root # find . -maxdepth 0 -name ‘Count*’ -exec rm {} \; I hope you got your trick now!! |
| | |
| Bookmarks |
| Tags |
| linux, list, long’, workaround, ‘argument |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |