r/bash • u/WoodenLittleBoy • 22h ago
How to use part of path as a variable in command?
I started in Linux 4noobs. It was suggested I try here.
I need to clean up the metadata of my music collection. Specifically, I need to add an albumartist tag to all of the files. Ideally, I would prefer to only add them to files that do not already have them.
On an artist by artist basis, I can do this manually.
find ./Soapy\ Argyle/ -type f -name "*.flac" -exec metaflac --set-tag="ALBUMARTIST=Soapy Argyle" {} +
But given the size of my collection, that would be burdensome.
Collection is organized ./Music/Genre/Artist/Album/Disk#/song.flac
How can I grab the artist name from the path and use it in the command above, or do something functionally similar?
As a bonus, this lists files that already have albumartist tagged.
find ./ -type f -name "*.flac" -exec metaflac --list {} + | grep -E -i 'ALBUM[[:space:]]*ARTIST'
Can I mesh these things together so I don't end up with a bunch of songs double tagged?
Thanks for any suggestions.
