Delete many files from csh script

Delete many files from csh script

Post by Ola M?rtensso » Tue, 01 Dec 1998 04:00:00



Hi,

When trying to delete about 1000 of files with the "rm *.*" command from a
csh script I get the error message "Argument
list too long". I guess the shell is trying to make a huge list of the
filenames and then trying to delete each file. Does anybody
have a solution for this? The filenames mostly consists of random numbers so
a solution with, e.g, "rm *153.*" is no good.

Thanks in advance
Ola Martensson

 
 
 

Delete many files from csh script

Post by sriin.. » Tue, 01 Dec 1998 04:00:00


You could try using find instead:

e.g. find <dir name> -type f -name "[0-9]*" -exec rm {} \; -print

Best regards
Kevin.


>Hi,
>When trying to delete about 1000 of files with the "rm *.*" command from a
>csh script I get the error message "Argument
>list too long". I guess the shell is trying to make a huge list of the
>filenames and then trying to delete each file. Does anybody
>have a solution for this? The filenames mostly consists of random numbers so
>a solution with, e.g, "rm *153.*" is no good.
>Thanks in advance
>Ola Martensson


 
 
 

Delete many files from csh script

Post by Brian B. McGuinnes » Tue, 01 Dec 1998 04:00:00


The "find" command will search subdirectories, which could cause
serious trouble if all Ola wanted to do was to delete files in the
current directory.

I would strongly suggest using

find <dir name> -type f -name "[0-9]*" -exec echo rm {} \; | more

the first time in order to verify that only the proper files will be
removed.

--- Brian


> You could try using find instead:

> e.g. find <dir name> -type f -name "[0-9]*" -exec rm {} \; -print

> Best regards
> Kevin.


> >Hi,

> >When trying to delete about 1000 of files with the "rm *.*" command from a
> >csh script I get the error message "Argument
> >list too long". I guess the shell is trying to make a huge list of the
> >filenames and then trying to delete each file. Does anybody
> >have a solution for this? The filenames mostly consists of random numbers so
> >a solution with, e.g, "rm *153.*" is no good.

> >Thanks in advance
> >Ola Martensson

 
 
 

Delete many files from csh script

Post by Bruce Barnet » Tue, 01 Dec 1998 04:00:00



> Hi,

> When trying to delete about 1000 of files with the "rm *.*" command from a
> csh script I get the error message "Argument
> list too long". I guess the shell is trying to make a huge list of the
> filenames and then trying to delete each file. Does anybody
> have a solution for this? The filenames mostly consists of random numbers so
> a solution with, e.g, "rm *153.*" is no good.

Someone has already mentioned find with or without xargs, I am sure.
You can also use a brute force method:

# This solves the problem when there are 100 times too many files
foreach i ( {1,2,3,4,5,6,7,8,9,0}{1,2,3,4,5,6,7,8,9,0} )
        rm *$i.*
end

or

# This solves the problem when there are 1000 times too many files
foreach i ( {1,2,3,4,5,6,7,8,9,0}{1,2,3,4,5,6,7,8,9,0}{1,2,3,4,5,6,7,8,9,0} )
        rm *$i.*
end

You might need a "set nonomatch"
and to use "/bin/rm -f" instead of rm (if you have "rm" alias to "rm -i")

--
Bruce  <barnett at crd. ge. com> (speaking as myself, and not a GE employee)

 
 
 

Delete many files from csh script

Post by Monty Taylo » Tue, 01 Dec 1998 04:00:00


You could go up a directory, 'rm -rf <dir name>' and then recreate the dir.
That shoves the workload onto rm and off of the shell's globbing.

--
--------------------------------------------------------------
Monty Taylor
Best Consulting -- Seattle, WA


Quote:>Hi,

>When trying to delete about 1000 of files with the "rm *.*" command from a
>csh script I get the error message "Argument
>list too long". I guess the shell is trying to make a huge list of the
>filenames and then trying to delete each file. Does anybody
>have a solution for this? The filenames mostly consists of random numbers
so
>a solution with, e.g, "rm *153.*" is no good.

>Thanks in advance
>Ola Martensson

 
 
 

Delete many files from csh script

Post by Charles Dem » Tue, 01 Dec 1998 04:00:00




>You could go up a directory, 'rm -rf <dir name>' and then recreate the dir.

>That shoves the workload onto rm and off of the shell's globbing.

But that would delete files that don't have a . in the name, like
my_file for example.

rm *.*  would not delete the file my_file, but your approach would.
This is unix, not DOS.  :-)

I personally prefer the find piped to xargs rm approach posted by
others.

Chuck Demas
Needham, Mass.



>>Hi,

>>When trying to delete about 1000 of files with the "rm *.*" command from a
>>csh script I get the error message "Argument
>>list too long". I guess the shell is trying to make a huge list of the
>>filenames and then trying to delete each file. Does anybody
>>have a solution for this? The filenames mostly consists of random numbers
>so
>>a solution with, e.g, "rm *153.*" is no good.

>>Thanks in advance
>>Ola Martensson

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.

 
 
 

1. how to call csh scripts from inside other csh scripts

I've got a csh script that executes other csh scripts. The problem is that
despite the fact that all the scripts are in my path, if I do not copy the
scripts that are being called into the subdirectory where the master script
is executed, then the master script complains that it cannot find these other
scripts.

Is this something that's a part of csh, or is there a way to actually get this to work?

2. Frame buffer OpenGL performance comparisons

3. Deleting mails from csh script

4. module names fix

5. Deleting files / useful aliases (was TCSH CSH BASH.....)

6. Your Average User and the Linux OS

7. csh commands within csh scripts

8. Strange shell script behaviour

9. Help to find a good book on csh/tcsh to teach myself csh/tcsh script

10. Csh shell script files ??

11. Where can I find examples of csh script files

12. csh - how do I manipulate 1000's of files in a script?

13. Need a sample csh script file