Thursday, May 9, 2024
66
rated 0 times [  66] [ 0]  / answers: 1 / hits: 371207  / 1 Year ago, tue, march 21, 2023, 11:42:24

For example, I do



cd Music
dir


and get



123456789.mp3
qweerkrtrkgljdjfkdjfdkf.mp3
a.mp3
b.mp3
blabla.mp3


how do I delete, say, files qweerkrtrkgljdjfkdjfdkf.mp3 and blabla.mp3 with least effort?



UPD: Key idea is that file names can be long so I actually dont want to type them.


More From » command-line

 Answers
1

Try this:



rm -f 2.mp3 blabla.mp3


rm removes files, and -f forces it to (so that it wont stop, asking you if you want to delete the file). If this not in your home directory, prepend sudo. Here is another way that might require less typing (a bit harder to read though)



rm -f {2,blabla}.mp3


This expands to 2.mp3 blabla.mp3. If you want to use larger filenames, you can use the wildcard character (*), which will return all items starting/ending with the filename you chose. For example:



rm -f bla*


will remove all files starting with bla. If you used this:



rm -f *.mp3


It will remove all files ending with .mp3. If you used this:



rm -f bla*.mp3


It will remove all files starting with bla and ending with .mp3. Possibilities are nearly endless with the * character :P


[#34291] Thursday, March 23, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hirtieve

Total Points: 207
Total Questions: 104
Total Answers: 114

Location: Cook Islands
Member since Thu, May 21, 2020
4 Years ago
hirtieve questions
;