How to delete multiple files ranging from 1 to 10 using rm command
How can i delete a range of files,
my file names look like this: Myvideo - My Car (34).avi i figured out how to delete one by one rm *\(1\)* rm *\(2\)* rm *\(3\)* rm *\(4\)* but that takes to long, i want to delete up to the number from 1 to 100, how can i achieve this? |
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.
Code:
for i in {1..10} ; do echo $i ; done |
that didn't work, it didn't delete anything
|
It wasn't supposed to - it was an attempt to get you thinking about how to solve it for yourself.
|
but your example is like programming, php, javascript,
i don't know how to do programming from the terminal, i never learned that before |
Have a look at
ls *[1-10]* See what happens. If it's ok use rm *[1-10]* |
Quote:
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: Code:
for i in {1..10} ; do echo rm *\($i\)* ; done |
Quote:
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}\).*) {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)! |
Quote:
|
Quote:
Code:
for i in {1..10} ; do echo rm *\("$i"\)* ; done Code:
for i in {1..10} ; do echo rm *"($i)"* ; done The . has no special meaning, so it can be within the "quotes" or outside: Code:
for i in {1..10} ; do echo rm *"($i)".* ; done |
Quote:
If you simply have a range file1 file2 file3 you can just do rm fi*. This deletes anything in that place which starts with fi. Or rm *.avi, deletes all files ending with .avi For a subset, this is obviously not a good option, if you want to delete file1 and file3, but not file 2. For multiple files you could add -r to the rm as an option. https://askubuntu.com/questions/8067...two-characters https://stackoverflow.com/questions/...-bash-on-linux 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. |
Quote:
Code:
for n in `seq 1 100`; do <whatever>;done |
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) |
did you try anything posted? Which one? What's happened?
|
As you only want to remove duplicates (whatever its duplicate number is), it seems that you just need:
Code:
rm *\([[:digit:]]*\)* EDIT: even better, you could use: Code:
shopt -s extglob |
All times are GMT -5. The time now is 02:43 PM. |