-3

I have a simple text file named as 'file.txt'

I want to create a .zip file which only include that 'file.txt'. I tried cat file.txt | zip newZipFun.zip -@. But it compressed my parent folder.

Additionally I need to output my .zip to a different location too.

  • 3
    Why not just zip newZipFun.zip file.txt? Why are you trying to pipe the content of a file into zip? – larsks Aug 9 '15 at 0:35
  • I tried 'zip file.txt newZipFun.zip' and gives me three warning messages and saying "zip error : Zip file structure invalid (file.txt)" – Jude Niroshan Aug 9 '15 at 0:41
  • 2
    It's the other way around: zip [archive_name] [file to add] – Bacon Aug 9 '15 at 0:42
  • What @Bacon said. Also, read the fine manual and you will learn these things for yourself. man zip would have shown you. – Wildcard Oct 22 '16 at 2:10
1

If you can't just do zip newZipFun.zip file.txt as larsks suggested, you can imagine doing

 find . -name "toto*" |  xargs zip totos.zip

where "toto*" is the name of all files starting with toto, in the current working directory and it's sub directories

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.