Reputation: 63
I ended up with many of my songs in both .m4a and .mp3 format. The duplicate .mp3s are in the same folders as their corresponding .m4as, and I'd like to delete the .mp3s. I'm trying to write a bash script to do that for me, but I'm very new to bash scripting and unsure of what I'm doing wrong. Here's my code:
#!/bin/bash
for f in ~/music/artist/album/* ; do
if [ -f f.m4a ] && [ -f f.mp3 ] ; then
rm f.mp3
echo "dup deleted"
fi
done
I'd really appreciate it if someone could figure out what's going wrong here. Thanks!
Upvotes: 1
Views: 511
Reputation: 1773
#!/bin/bash
# No need to loop through unrelated files (*.txt, directories, etc), right?
for f in ~/music/artist/album/*.m4a; do
f="${f%.*}"
if [[ -f ${f}.mp3 ]]; then
rm -f "${f}.mp3" && echo >&2 "${f}.mp3 deleted"
fi
done
Upvotes: 4
Reputation: 185053
#!/bin/bash
for f in ~/music/artist/album/* ; do
f="${f%.*}" # remove extension in simple cases (not tar.gz)
if [[ -f ${f}.m4a && -f ${f}.mp3 ]] ; then
rm -f "${f}.mp3" && echo "dup deleted"
fi
done
Upvotes: 0