Question - how to use tar to compress multiple top level folders recursively into discrete zip files
-
So let's say I have a share outlined below.
Share
--- folder
---- to compress
---- to compress 1
-- some files / folders
---- to compress 2If I wanted to have a single tar command that would compress "to compress", "to compress 1" and "to compress 2" into distinct compressed zip files, without specifically stating the files and folders to compress.
Something agnostic to whatever is under
--- folder
that'll create separate zip files is what I'm hoping to do. -
What OS?
-
Assuming BASH for launching tar...
Then the "complex way"...
for i in compress compress1 compress2; do tar -czvf $i.tgz $i; done
-
Does it matter, the tar process is tar?
But osx is likely where this would be run from.
-
Then the "simple way" with some semi-obvious assumptions...
for i in $(ls); do tar -czvf $i.tgz $i; done
-
@DustinB3403 said in Question - how to use tar to compress multiple top level folders recursively into discrete zip files:
Does it matter, the tar process is tar?
But osx is likely where this would be run from.
OS does not, shell does.
-
@scottalanmiller said in Question - how to use tar to compress multiple top level folders recursively into discrete zip files:
Assuming BASH for launching tar...
Then the "complex way"...
for i in compress compress1 compress2; do tar -czvf $i.tgz $i; done
That I think would require me to fill out the tar command on a forever ongoing process. Hoping to be able to just target the
--- folder
root for. -
Or another way....
for i in $(ls -r | grep compress); do tar -czvf $i.tgz $i; done
-
@DustinB3403 said in Question - how to use tar to compress multiple top level folders recursively into discrete zip files:
@scottalanmiller said in Question - how to use tar to compress multiple top level folders recursively into discrete zip files:
Assuming BASH for launching tar...
Then the "complex way"...
for i in compress compress1 compress2; do tar -czvf $i.tgz $i; done
That I think would require me to fill out the tar command on a forever ongoing process. Hoping to be able to just target the
--- folder
root for.Should be easy to do, you just have to define what makes the target folder obviously the target and write the bit in the $() to return that and away you go.
-
@DustinB3403 said in Question - how to use tar to compress multiple top level folders recursively into discrete zip files:
Does it matter, the tar process is tar?
But osx is likely where this would be run from.
Because I was going to write a cmd for loop for you if it were Win, and I was going to pass if it were *nix.
-
Well of the
--- folder
never changes, but the content beneath it does, that would be what I would target.I'm trying to resolve our user base breaking our backups by have file paths longer than 255 characters, which the simplest way I can think of is to just compress everything in
--- folder
. -
@JasGot said in Question - how to use tar to compress multiple top level folders recursively into discrete zip files:
@DustinB3403 said in Question - how to use tar to compress multiple top level folders recursively into discrete zip files:
Does it matter, the tar process is tar?
But osx is likely where this would be run from.
Because I was going to write a cmd for loop for you if it were Win, and I was going to pass if it were *nix.
It's the shell, not the OS, that determines the looping structure. PowerShell on Linux is the same as on Windows. Bash on Windows is the same as on Linux.
-
I don't follow your - - - naming scheme. Can you explain differently?
-
@Obsolesce said in Question - how to use tar to compress multiple top level folders recursively into discrete zip files:
I don't follow your - - - naming scheme. Can you explain differently?
Yeah the spacing didn't copy over from mobile.
Essentially it's
Root folder
- sub folder
-
- child folder
- different sub folder from root
-
- child folder
-
Okay so this is the next annoyance with this, I am getting the entire parent folder up until the target folder in the compressed file.
IE: compressed-folder.tar contains
- Share Name
- Sub-Parent-Folder
- Next-Level-Parent-Folder
- Target-Folder
. . . . all of the files and sub-folders
- Target-Folder
- Next-Level-Parent-Folder
- Sub-Parent-Folder
Anyway to have tar just target the
Target-Folder
that is on an SMB share, compress that specifically (and it's children to a single file) so I can then move that compressed file without all of the overhead folder structure? - Share Name
-
I suppose I could mount each and every
Target-Folder
but that seems completely counter intuitive and a massive effort. . . -
@DustinB3403 said in Question - how to use tar to compress multiple top level folders recursively into discrete zip files:
Okay so this is the next annoyance with this, I am getting the entire parent folder up until the target folder in the compressed file.
IE: compressed-folder.tar contains
- Share Name
- Sub-Parent-Folder
- Next-Level-Parent-Folder
- Target-Folder
. . . . all of the files and sub-folders
- Target-Folder
- Next-Level-Parent-Folder
- Sub-Parent-Folder
Anyway to have tar just target the
Target-Folder
that is on an SMB share, compress that specifically (and it's children to a single file) so I can then move that compressed file without all of the overhead folder structure?Why not specify
/path/to/targetfolder/
- Share Name
-
@Obsolesce said in Question - how to use tar to compress multiple top level folders recursively into discrete zip files:
Why not specify /path/to/targetfolder/
I'm not following what you mean.
How I'm currently doing this is
tar -zcvf Compressed.zip /Volumes/Parent/Child/Target-folder/
Edit:
And I get everything in the path
/Volumes/Parent/Child/Target-folder/
so the compressed file, when decompressed is/Volumes/Parent/Child/Target-Folder/some-stuff
What I want is just
Target-Folder
and it's contents, not the parent folder path. -
Supposedly
tar -C /Volumes/Parent/Child/Target-folder -cvf Compressed.zip SelectedDirectory
works. . . let me test that. -
@DustinB3403 said in Question - how to use tar to compress multiple top level folders recursively into discrete zip files:
Supposedly
tar -C /Volumes/Parent/Child/Target-folder -cvf Compressed.zip SelectedDirectory
works. . . let me test that.Okay so that does work, just is a pain in the rear to have to do manually.