[SOLVED] How to delete multiple files ranging from 1 to 10 using rm command
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm not a big fan of using wildcards in things like "rm", but it's your data. You need to loop over the file(name)s in question. See if this gives you an idea of how to start.
but your example is like programming, php, javascript,
i don't know how to do programming from the terminal, i never learned that before
then it's time you started.
but meanwhile, you can use any script on the command line; either by entering it just as it is (will evoke a secondary prompt, might be confusing) - or by chaining the commands with semicolons, which is what syg00 did.
in other words, you can copy-paste that example straight into your terminal.
i will extend it a little:
That does not work. [ ] can only return one character!
In fact it is identical with [01-1] or [01] or [0-1].
You must either use a loop or
Code:
(shopt -s nullglob; echo \rm *\({1..10}\).*)
Notes:
{x..y} and shopt require bash.
I put a backslash before rm to bypass any alias or function (in case it's an interactive shell).
I put echo before the \rm to show what it would do; remove the echo to really do it!
I put ( ) around the whole thing to run it in a subshell, so the nullglob effect does not remain in the main(=current) shell.
I put a . after the \) to require exactly that. Always be most specific to prevent from a false match(=deletion)!
Last edited by MadeInGermany; 12-10-2018 at 03:12 AM.
That's because the shell is a scripting language, not just a user interface. It's very well worth the effort of learning. The beginning may be hardest but the return on effort starts to show quickly once you start to feel a little comfortable with it. I highly recommend and encourage it.
These two threads probably explain what you want. This specifies with curly brackets. But please, do test these things before actually doing them. Make some files with ranges and test out how these works before actually doing it on real files.
i don't want to delete all the files with .avi or files starting with myvideo.
What i'm trying to do is remove duplicates
Myvideo - My Car.avi
Myvideo - My Car (1).avi
Myvideo - My Car (2).avi
Myvideo - My Car (3).avi
Myvideo - My Car (4).avi
Myvideo - My Car (5).avi
Coolvideo - My Dog.avi
Coolvideo - My Dog (1).avi
Coolvideo - My Dog (2).avi
Coolvideo - My Dog (3).avi
Coolvideo - My Dog (4).avi
Coolvideo - My Dog (5).avi
Coolvideo - My Dog (6).avi
so what im trying to delete is all the files with brackets (1) (2) (3)
As you only want to remove duplicates (whatever its duplicate number is), it seems that you just need:
Code:
rm *\([[:digit:]]*\)*
Disclaimer: you must NOT have in the same folder some files with "(some_number)" pattern that you would want to keep as they will be erased as well with that command...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.