Daniel M.
Daniel M.

Reputation: 89

How to multiple compress different folders with Squash FS on linux?

I have tried those without success:

for i in */; do mksquashfs "${i}" "${i}.squashfs" -comp xz

find . -name "*/" -exec mksquashfs {} {}.squashfs -comp xz \;

My object here, is find folders on the location, and compress them separately, but without doing it one by one.

Original code:

mksquashfs Direcoty\ Name\ To\ Compress \1/ Direcoty\ Name\ To\ Compress \1.squashfs -comp xz

mksquashfs Direcoty\ Name\ To\ Compress \2/ Direcoty\ Name\ To\ Compress \2.squashfs -comp xz

mksquashfs Direcoty\ Name\ To\ Compress \3/ Direcoty\ Name\ To\ Compress \3.squashfs -comp xz

mksquashfs Direcoty\ Name\ To\ Compress \4/ Direcoty\ Name\ To\ Compress \4.squashfs -comp xz

mksquashfs Direcoty\ Name\ To\ Compress \5/ Direcoty\ Name\ To\ Compress \5.squashfs -comp xz

Upvotes: 0

Views: 393

Answers (1)

Phillip Lougher
Phillip Lougher

Reputation: 161

This is more Bash and Find usage rather than Squashfs.

You have made mistakes in both attempts.

for i in */; do mksquashfs "${i}" "${i}.squashfs" -comp xz

In this attempt, you're forgetting that "*/" will expand to a filename with a trailing /, and this will be included in the Squashfs image filename, i.e.

i = "hello/"

${i}.squashfs = hello/.squashfs

You either have to strip the trailing /, or not have it there in the first place.

This will work

for i in *; do if [ -d "$i" ]; then mksquashfs "$i" "$i.squashfs" -comp xz; fi; done

In the Find case

find . -name "*/" -exec mksquashfs {} {}.squashfs -comp xz ;

Find will complain about the embedded "/" in "*/". Additionally, once fixed find will recursively descend the directories, running Mksquashfs on everything. You want to limit it to the top level and directories.

This will work

find . -maxdepth 1 -name "[^.]*" -type d -exec mksquashfs {} {}.squashfs -comp xz \;

Upvotes: 1

Related Questions