0

I want to bundle below three files and extract into the same folder.

files1.txt
files2.txt
files3.txt

zip -r myfiles.zip files1.txt files2.txt files3.txt

Output When extracting the zip:

files1.txt
files2.txt
files3.txt

Expected output:

myfiles/files1.txt
myfiles/files2.txt
myfiles/files3.txt
  • Do you want the archive to contain the "myfiles" subfolder, or do you want a command-line that extracts a flat zip archive into that subfolder? – Jeff Schaller Nov 13 '18 at 15:46
  • When I extract the .zip file, I would expect to have the files within the main folder(myfiles) – itgeek Nov 13 '18 at 18:41
  • I wasn't clear enough; can the extraction command be modified, as the current answer has, or should the archive contain the folder such that a vanilla extraction command results in a subdirectory? – Jeff Schaller Nov 13 '18 at 19:40
  • 1
    use the -d option of unzip: unzip -d myfiles myfiles.zip – mosvy Nov 13 '18 at 20:14
  • Why not mkdir myfiles/ ; mv files*txt myfiles/ ; zip -r myfiles.zip myfiles/ ? – JigglyNaga Nov 14 '18 at 14:15
1

If I remember correctly you could specify a -d option:

unzip myfiles.zip -d myfiles

A directory named as the argument of the -d option will be created with the extracted files inside it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.