The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find files and display only directory list containing those files r7p UNIX for Dummies Questions & Answers 4 06-05-2009 09:46 AM
To list files only in a directory dipashre Shell Programming and Scripting 5 12-18-2008 07:31 AM
arg list too long when trying to tar files jds3 UNIX for Dummies Questions & Answers 5 07-17-2006 12:00 PM
arg list too long when mv files? jamos007 UNIX for Dummies Questions & Answers 2 05-10-2006 01:39 AM
list of files in one Directory venkyA UNIX for Dummies Questions & Answers 3 06-24-2005 05:49 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-21-2009
techmoris techmoris is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 27
rm long list of files in a directory

Hi,

I have used a command rm *.txt in a directory which has about 2000 txt files.

but it is throwing the following error:

error: args list too long.

any ideas pls..
  #2 (permalink)  
Old 08-21-2009
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,972

Code:
find /path/to/dir/ -iname '*.txt' -exec echo rm '{}' ';'

Run it once to be sure it picks the right files, then remove the 'echo' and run it again to do it for real.
  #3 (permalink)  
Old 08-21-2009
Leo Gutierrez Leo Gutierrez is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 13

Code:
rm `find -name "*.txt" `

  #4 (permalink)  
Old 08-21-2009
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,972
Quote:
Originally Posted by Leo Gutierrez View Post
Code:
rm `find -name "*.txt" `
If it's too many arguments with globbing, how do you expect backticks to help cram them into one argument list? That's not going to work!

---------- Post updated at 01:47 PM ---------- Previous update was at 01:45 PM ----------

Quote:
Originally Posted by edfair View Post
The list generated is limited in size. Try breaking your request down to the size it can handle like:
rm a*.txt
rm b*.txt
and so forth. If one of the sub groups is too large you will need to break it down further.
I think the limit is 256 but it has been a while since I tried to difine it.
This is not an effective or general-purpose solution, especially since the size of a commandline may be limited by the size of the names and not just their number. The proper way to deal with it is to use pipes or tools, not to keep randomly trying different globs until you find one small enough.
  #5 (permalink)  
Old 08-21-2009
techmoris techmoris is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 27
error: find: bad option -iname

find /path/to/dir/ -iname '*.pdf' -exec echo rm '{}' ';'

after running this command, I am getting the following error:

find: bad option -iname
  #6 (permalink)  
Old 08-21-2009
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,972
Try 'name' instead. 'iname' is the case-insensitive variant supported by the GNU variant I usually use. And you are replacing /path/to/dir with the path to your dir, right?
  #7 (permalink)  
Old 08-21-2009
techmoris techmoris is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 27
didnt worked

didnt wrked
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 -4. The time now is 06:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0