India Broadband

Forum

 

Linux Workaround for ‘Argument list too long’ error message while removing all files

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 ...


Go Back   India Broadband Forum > Daily dose of technology > News and views > Computer hardware and software tips and tricks

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

 

LinkBack Thread Tools Display Modes
Old 26-03-2006, 01:15 PM   #1
 
Admin's Avatar
 
Join Date: Jan 2006
Location: New Delhi
Age: 31
Posts: 3,345
Rep Power: 10 Admin is on a distinguished road
Default Linux Workaround for ‘Argument list too long’ error message while removing all files

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!!
Admin is online now   Reply With Quote
Reply

Bookmarks

Tags
linux, list, long’, workaround, ‘argument


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +5.5. The time now is 05:49 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
India Broadband Forum