rm long list of files in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting rm long list of files in a directory
# 1  
Old 08-21-2009
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  
Old 08-21-2009
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  
Old 08-21-2009
Code:
rm `find -name "*.txt" `

# 4  
Old 08-21-2009
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.
# 5  
Old 08-21-2009
Quote:
Originally Posted by Leo Gutierrez
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
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.
# 6  
Old 08-21-2009
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
# 7  
Old 08-21-2009
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

2. Shell Programming and Scripting

Copy list of files from a keyword list to another directory

Hello, I have a folder with a massive amount of files, and I want to copy out a specific subset of the files to a new directory. I would like to use a text file with the filenames listed, but can't get it to work. The thing I'm hung up on is that the folder names in the path can and do have... (5 Replies)
Discussion started by: twjolson
5 Replies

3. Shell Programming and Scripting

Need Help Moving Long List Of Files Into Directories

I am very new to BASH and I am having difficulties moving a long list of image files into similarly named directories. I've been trying to come with a script all night and no luck. Here is what my list of files looks like: DSC_0059_01.jpg DSC_0059_02.jpg DSC_0059_03.jpg DSC_0059_04.jpg... (5 Replies)
Discussion started by: jowens1138
5 Replies

4. Solaris

Replacing a string in a long list of files

I have a script that needs to read a file with a long list of /path/filenames - replace the name of the server in each file - and write the file to the same path with a date extension. This is the script that I have so far #!/bin/ksh umask 022 LIST=`scripts.list` for i in $LIST do ... (2 Replies)
Discussion started by: bjdamon
2 Replies

5. Solaris

calculate sum size of files by date (arg list too long)

Hi, I wanted a script to find sum of files for a particular date, below is my script ls -lrt *.req | nawk '$6 == "Aug"' | nawk '$7 == "1"'| awk '{sum = sum + $5} END {print sum}' However, i get the error below /usr/bin/ls: arg list too long How do i fix that. Many thanks before. (2 Replies)
Discussion started by: beginningDBA
2 Replies

6. Shell Programming and Scripting

TAR Files Argument list too long error

Hi, I have a requirement where I need to TAR more than 50K files. Even though I can do TAR successfully on few 100s of files, but whenever Im trying to TAR the entire 50K files, I am getting the error message : Argument List Too Long. Please suggest how can i avoid this error. Im... (2 Replies)
Discussion started by: unx100
2 Replies

7. Shell Programming and Scripting

find list of files from a list and copy to a directory

I will be very grateful if someone can help me with bash shell script that does the following: I have a list of filenames: A01_155716 A05_155780 A07_155812 A09_155844 A11_155876 that are kept in different sub directories within my current directory. I want to find these files and copy... (3 Replies)
Discussion started by: manishabh
3 Replies

8. UNIX for Dummies Questions & Answers

Find files and display only directory list containing those files

I have a directory (and many sub dirs beneath) on AIX system, containing thousands of file. I'm looking to get a list of all directory containing "*.pdf" file. I know basic syntax of find command, but it gives me list of all pdf files, which numbers in thousands. All I need to know is, which... (4 Replies)
Discussion started by: r7p
4 Replies

9. UNIX for Dummies Questions & Answers

arg list too long when trying to tar files

Hi, I am trying to perform this task: tar -cvf tar.newfile ??????.bas I got error "arg list too long". Is ther any way around? I have about 1500 file need to be tar together. Thanks in advance (5 Replies)
Discussion started by: jds3
5 Replies

10. UNIX for Dummies Questions & Answers

arg list too long when mv files?

hello all i need some help because i am a unix/linux dummy...i have the following: DIR1> has 121437 files in it with varying dates going back to early April, a sub dir DIR1/DIR2> has 55835 files in it I need to move all files (T*.*) out of DIR1 into DIR2 that are older than today? Ive been... (2 Replies)
Discussion started by: jamos007
2 Replies
Login or Register to Ask a Question