LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 05-28-2004, 02:10 AM   #1
suchi_s
Member
 
Registered: May 2004
Posts: 133

Rep: Reputation: 15
error in removing ,when the no of files r too large


when using command rm *.txt
getting error

bash: /bin/rm: argument list too long...
while removing i m getting this error
 
Old 05-28-2004, 04:40 AM   #2
suchi_s
Member
 
Registered: May 2004
Posts: 133

Original Poster
Rep: Reputation: 15
rm command

when i use the command rm *txt
error comes
argument list too long
 
Old 05-28-2004, 05:15 AM   #3
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Lubuntu
Posts: 19,174
Blog Entries: 4

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Moved: This thread is more suitable in Linux-General and has been moved accordingly to help your thread/question get the exposure it deserves.

Please try to post in the correct forums.
 
Old 05-28-2004, 05:34 AM   #4
kinasz
Member
 
Registered: Mar 2004
Location: Brisbane, Australia
Distribution: FreeBSD, Suse
Posts: 103

Rep: Reputation: 15
try something like

{ while [true ]
do
ls -1 *txt| head| rm *
done };

rough as guts, it will infinite loop when they are all deleted but will do the job

edit: anyone know how to fix the condition on this one?

Last edited by kinasz; 05-28-2004 at 05:36 AM.
 
Old 05-28-2004, 05:59 AM   #5
suchi_s
Member
 
Registered: May 2004
Posts: 133

Original Poster
Rep: Reputation: 15
what is for xargs command with find and print command , with that we can overcome this prob but dont know how to use it.
 
Old 05-28-2004, 06:31 AM   #6
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 197Reputation: 197
Moved: Not a Success Story.
 
Old 05-28-2004, 06:34 AM   #7
Demonbane
Guru
 
Registered: Aug 2003
Location: Sydney, Australia
Distribution: Gentoo
Posts: 1,796

Rep: Reputation: 47
maybe do it one by one?
Code:
for foo in *.txt; do rm -i $foo; done
 
Old 05-28-2004, 06:46 AM   #8
frandalla
Member
 
Registered: Oct 2003
Location: Tokyo - Japan
Distribution: Slackware
Posts: 348
Blog Entries: 1

Rep: Reputation: 37
The problem is you have just too many files... try doing first:
rm a*.txt
rm m*.txt
rm d*.txt
rm c*.txt
or just the letters that have most of the files and then
rm *.txt
 
Old 05-28-2004, 06:47 AM   #9
bahramH
Member
 
Registered: Apr 2004
Location: France
Distribution: Mandrake
Posts: 67

Rep: Reputation: 15
An onther solution, without the infinite loop, would be :

> a = `ls *txt`
> for file in $a
> do
> rm -f $file
> done

the first command put all files with txt extension into the variable a ;

the sign is not ', but ` .
 
Old 05-28-2004, 06:48 AM   #10
suchi_s
Member
 
Registered: May 2004
Posts: 133

Original Poster
Rep: Reputation: 15
what if all the files start from a*
 
Old 05-28-2004, 07:12 AM   #11
kinasz
Member
 
Registered: Mar 2004
Location: Brisbane, Australia
Distribution: FreeBSD, Suse
Posts: 103

Rep: Reputation: 15
that's what i was aiming at - good one
 
Old 05-28-2004, 07:14 AM   #12
bureado
Member
 
Registered: Oct 2003
Location: Caracas
Distribution: Knoppix 3.3 (Debian sarge/sid)
Posts: 72

Rep: Reputation: 15
You are doing

rm *txt

And you must do

rm *.txt

Try and if it doesn't work just follow the longer solutions.
 
Old 05-28-2004, 12:23 PM   #13
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
find . -maxdepth 1 -type f -name "*.txt" -exec rm {} \;

Explanation:
Find starts looking in the current directory for files that match the attributes given by the arguments
'-maxdepth 1' limits the find command to look only in the directory specified
'-type f' only match against regular files (not directories, links, etc.)
'-name "*.txt"' only choose files that match the *.txt format
'-exec rm {} \;' for each file found that matches, execute the rm command. Replace {} with the name of the file found, and the \; just signals the end of the command to execute.

man find for more details
 
Old 05-28-2004, 12:31 PM   #14
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
This is a duplicate thread. You can find the original here
 
Old 05-28-2004, 12:59 PM   #15
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Lubuntu
Posts: 19,174
Blog Entries: 4

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
suchi_s - you will have seen that your 2 threads were merged into one. Please try to post in the correct forum - and only post once.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ed command error hpaixao Programming 9 02-17-2005 02:26 PM
c++ command not found error... ? Cheka Linux - Newbie 2 01-29-2005 03:43 PM
CVS command error welson_sun Linux - Software 1 09-21-2004 10:16 PM
IO error with dd command devershetty Linux - Newbie 1 12-09-2003 08:23 PM
command line > error mrtwice Linux - General 1 06-03-2003 04:47 PM


All times are GMT -5. The time now is 02:07 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration