I recently installed Linux Mint 17 on my laptop. I had Windows 7 before, and I backed up all of my data onto an external hard drive. Windows 7 crams all of your backup data into a ton of .zip folders. Here is my problem: I only want to extract those folders that contain my music, which lie in the path C:\...\Username\Music.... So I tried to find a way to use the unzip those files from my external hard drive and into my Music directory in my home folder using the terminal. I am still learning how to use the terminal, but this is what I have found:

for file in *.zip; do unzip -c "$file" -d "/~/Music" | grep "\Username\Music"; done

It gives me the output:

caution:  not extracting; -d ignored

When I remove the -d, it works, (well, seems to work: it ran for a while), but I get a weird output at the end and then this:


I searched for the music that was supposedly unzipped but could not find it. Can anyone tell me if and how I can accomplish my goal? I'd like to unzip only my music files from my external hard drive to my Music folder.

1 Answer 1


The -c flag of unzip means extract files to stdout/screen, so no files are actually written to disk and hence the -d option is meaningless - it may also explain the strange characters you are seeing in the terminal. Perhaps you are thinking of the -C (use case-insensitive matching) modifier?

Rather than using grep, probably what you want is to supply an optional list of archive members to be processed following the zipfile: also you likely need use Unix-style / path separators, even if the zipfile's origin is a Windows system.

Finally, "/~/Music" will likely be interpreted as a literal absolute path; you probably need ~/Music/ or "$HOME/Music/" - the latter form being more easily modified to target directories with spaces in them e.g. "$HOME/My Music/"

unzip -C "$file" '*/Username/Music/*' -d "$HOME/Music/"

Note however that this will probably result in a folder structure like ~/Music/Username/Music/somefile, which might not be what you intend. AFAIK unzip doesn't have the same flexibility to strip leading directory components that some implementations of tar do, however you may wish to look at the -j modifier.

You must log in to answer this question.