When you want to delete only items in current directory, it is sufficient to use the wildcard like so:
$ ls *.jpeg
birthday2016_001.jpeg birthday2016_002.jpeg birthday2016_003.jpeg
$ rm *.jpeg
$ ls *.jpeg
ls: cannot access '*.jpeg': No such file or directory
As you can see, in the example above, all files with .jpeg
extension got removed. Listing them , is the same idea - echo *.jpeg
and ls *.jpeg
. So you essentially could do simply ls *.mp3 && rm *.mp3
for your case
Python alternative:
In my case, I was removing .jpeg
file, so adjust the code below as necessary:
python -c 'import os,sys;[(sys.stdout.write(i + "\n"),os.unlink(i)) for i in os.listdir(".") if i.endswith(".jpeg")]'
Sample run:
$ ls *.jpeg
birthday2016_001.jpeg birthday2016_002.jpeg birthday2016_003.jpeg
$ python -c 'import os,sys;[(sys.stdout.write(i + "\n"),os.unlink(i)) for i in os.listdir(".") if i.endswith(".jpeg")]'
birthday2016_003.jpeg
birthday2016_001.jpeg
birthday2016_002.jpeg
$ ls *.jpeg
ls: cannot access '*.jpeg': No such file or directory