[H-GEN] symlink fun

Russell Stuart russell-humbug at stuart.id.au
Sat Feb 23 23:23:26 EST 2008


On Sun, 2008-02-24 at 11:56 +1000, Patrick Nichols wrote:
> I've got a bunch of music sorted nicely into directories, and I want to
> make a symlinked version of it which is sorted by album year.  For example
> I have the following directories:
> 
> /var/data/_Compilations_/...
> /var/data/_Classical_/...
> /var/data/Artist Name/(YYYY) Album Name/
> /var/data/Artist Name/(YYYY) Album Name/
> /var/data/Artist Name/(sYYYY) Album Name/
> 
> I want it to parse all the album dates and ouput a tree, while leaving any
> _category_ directories unlinked.  Such as the following:
> 
> /var/data/_1950s_/(1952) Mario Lanza - Some old Album/
> /var/data/_1960s_/(YYYY) Rolling Stones - Blah, Blah, Blah!/
> /var/data/_1970s_/(sYYYY) Skyhooks - Album name/
> 
> ...and so on.
> 
> The (sYYYY) denotes a singles cd, (YYYY) denotes a full album or EP.

set -e
for year in $(find [!_]*[!_] -type d -maxdepth 1 | 
              sed -n 's,.*/(s\?\([0-9]\{4\}\)) .*,\1,p' |
	      sort -u)
do
  # rm -r _${year}     - uncomment to make idempotent
  mkdir -p _${year}_
  find [!_]*[!_]"/("{,s}"${year}) "* -maxdepth 0 2>/dev/null |
    sed 's,^,../,' | tr '\n' '\0' |
    xargs -0r ln -sf --target-directory _${year}_
done





More information about the General mailing list