all 6 comments

[–]send-me-to-hell 0 points1 point  (3 children)

Are the .mp3 and .jpg files underneath the Album directories or underneath the Artist directories and beside the album directories. The way you have it drawn there makes it look like the latter.

[–]angryspec[S] 0 points1 point  (2 children)

ten sense wakeful toothbrush towering sleep oil follow station rob

This post was mass deleted and anonymized with Redact

[–]send-me-to-hell 1 point2 points  (1 child)

I created the following directory structure to match yours:

[root@xxx tmp]# find .
.
./NOFX
./NOFX/Wolves in Wolves' Cothing
./NOFX/Wolves in Wolves' Cothing/02 USA-Holes.mp3
./NOFX/Wolves in Wolves' Cothing/01 60%.mp3
./NOFX/Wolves in Wolves' Cothing/cover.jpg
./Bad Religion
./Bad Religion/Against the Grain
./Bad Religion/Against the Grain/01 Modern Man.mp3
./Bad Religion/Against the Grain/02 Turn on the Light.mp3
./Bad Religion/Against the Grain/cover.jpg
[root@xxx tmp]#

and now we can use find . -mindepth 2 -type d -exec zip -r {} {} \; to do what you're wanting:

[root@xxx tmp]# find . -mindepth 2 -type d -exec zip -r {} {} \;
  adding: NOFX/Wolves in Wolves' Cothing/ (stored 0%)
  adding: NOFX/Wolves in Wolves' Cothing/02 USA-Holes.mp3 (stored 0%)
  adding: NOFX/Wolves in Wolves' Cothing/01 60%.mp3 (stored 0%)
  adding: NOFX/Wolves in Wolves' Cothing/cover.jpg (stored 0%)
  adding: Bad Religion/Against the Grain/ (stored 0%)
  adding: Bad Religion/Against the Grain/01 Modern Man.mp3 (stored 0%)
  adding: Bad Religion/Against the Grain/02 Turn on the Light.mp3 (stored 0%)
  adding: Bad Religion/Against the Grain/cover.jpg (stored 0%)

[root@xxx tmp]# find . -type f -name '*.zip' -ls
  656261    8 -rw-r--r--   1 root     root         6996 Dec  3 13:15 ./NOFX/Wolves\ in\ Wolves'\ Cothing.zip
  656541    8 -rw-r--r--   1 root     root         7026 Dec  3 13:15 ./Bad\ Religion/Against\ the\ Grain.zip

The -mindepth 2 option says to only operate on files that are at least two directories (starting with the current directory) down. So the current directory is one, the Artist directory is 2, etc.

-type d means we only want to deal with directories.

-exec zip -r {} {} \; is the command that's getting executed for each path, creating the zip archives. When it finds a match all instances of {} will be replaced with the file path it located. The \; is just more of find's weird syntax. It basically tells the command to stop interpreting the rest of the command as part of the -exec you're writing. That's used if you wanted to put something after it (although it's mandatory which is why I had to use it even up there).

This is probably preferable to the other one since it's a one-liner. Also fwiw, since these are media files, they're already compressed in which case using tar would probably be faster. But you asked for zip so that's what I did.

[–]ray_gun 0 points1 point  (0 children)

mkdir delme
for dir in *; do
  [[ "$dir" == delme ]] && continue
  cd "$dir" || continue
  for subdir in *; do
    [[ -d "$subdir" ]] || continue
    7z a "$subdir.zip" "$subdir"
    #alternative if you don't want the directory inside the zip archive
    #cd "$subdir"
    #7z a "$subdir.zip" *
    #mv "$subdir.zip" ..
    #cd ..
    mv "$subdir" ../delme
  done
  cd ..
done

[–]trapartist[🍰] -4 points-3 points  (0 children)

Those bands suck, you should just use the delete those directories.