Score:1

extract only a subfolder from a zip file without the path

us flag

I have a little problem! I have a zip file "Backup.zip"; in this zipfile I have: /Users/USERNAME/Pictures

The Picture directory has files and directories.

I need to extract only the Picture folder but without /Users/USERNAME/.

I have tried:

unzip Backup.zip '/Users/USERNAME/Pictures/*' -d home/USERNAME/Pictures/

and

unzip Backup.zip '/Users/USERNAME/Pictures/' -d home/USERNAME/Pictures/

and

unzip Backup.zip -d home/USERNAME/Pictures/ '/Users/USERNAME/Pictures/*'

But I become home/USERNAME/Pictures/Users/USERNAME/Pictures.

What is my mistake?

24601 avatar
in flag
is it because you are adding a `/` at the end of the command?
Husker avatar
us flag
unzip Backup.zip '/Users/USERNAME/Pictures/' -d home/USERNAME/Pictures its the same
hr flag
Perhaps you want the `-j` option? See for example [Junk a part of the directory with unzip?](https://unix.stackexchange.com/questions/85797/junk-a-part-of-the-directory-with-unzip)
Husker avatar
us flag
The problem seems to be that with the option -j all folders are irgnored even those that I actually want to keep! Seems like I have to unzip it and then move it with mv ... very sad
Score:0
ru flag

It seems to me that steeldriver is on the right path with unzip's "-j junk paths" option:

cd /target/destination/for/Pictures
unzip -j /path/to/backup.zip 'home/USERNAME/Pictures/*'

This tells unzip to extract files matching the pattern home/USERNAME/Pictures/* (safely quoted from the shell, just in case) from the zip file and to strip out the leading directory paths as it does so. Be careful to use the same extraction pattern as exists in the zip file.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.