Results 1 to 5 of 5
Hi everyone
I have 50 files in the following format.
fileone.0001.txt
filetwo.0002.txt
filethree.0003.txt
filefour.0004.txt
filefive.0005.txt
filesix.0006.txt
fileseven.0007.txt up to filefifty.0050.txt
Can someone please show me how to delete only the ...
- 08-13-2010 #1Linux User
- Join Date
- Jul 2007
- Location
- Greece
- Posts
- 277
how to delete a specific range of files
Hi everyone
I have 50 files in the following format.
fileone.0001.txt
filetwo.0002.txt
filethree.0003.txt
filefour.0004.txt
filefive.0005.txt
filesix.0006.txt
fileseven.0007.txt up to filefifty.0050.txt
Can someone please show me how to delete only the first 20 files.
I can dobut this will delete everything.Code:find . -type f -name '*txt' -exec rm -rf {} \;
Can somebody please tell me how can I define the range of files I want to delete within this syntax?
Many many thanksOne Love!!!
- 08-13-2010 #2
try this
I am a bit uneasy with the *.Code:for a in {1..20}; do b=`printf '%02d.txt' $a`; ls -1 *$b; done | xargs ls -la
It would be better to guard it more, perhaps if the files all start with the same name?
Anyhow, if you feel comfortable, replace the ls with rmLast edited by Irithori; 08-13-2010 at 11:22 AM.
You must always face the curtain with a bow.
- 08-13-2010 #3Linux User
- Join Date
- Jul 2007
- Location
- Greece
- Posts
- 277
Thanks a lot for your reply Irithori
Yes the files all start with the same name, I shouldn't have rename them.
They are all in the format
file.0001.txt
file.0002.txt and so on.
When I run your script I got the errors below.
Code:for: Command not found. a: Undefined variable. do: Command not found. b: Undefined variable.
One Love!!!
- 08-13-2010 #4
Which shell are you using?
try
And replace ls -la with rm if you are ok with the resultCode:bash for a in {1..20}; do b=`printf 'file.00%02d.txt' $a`; ls -la $b; doneYou must always face the curtain with a bow.
- 08-13-2010 #5Linux User
- Join Date
- Jul 2007
- Location
- Greece
- Posts
- 277
Excellent!

Thank you very much IRITHON
See you in Octoberfest.One Love!!!


Reply With Quote