0

I wrote a compressing command in Ubuntu. However,the zip file produced also contain path folder leading to the target file in form of folder. I only need the target file alone in the zip file. This is the code I currently using.

zip -9pr /mnt/test/Raimi/temp/Testing.zip /home/tect/Loco/*txt

where mnt/test/Raimi/temp is the destination folder Testing.zip is the output I intended to produced and /home/tect/Loco is the Original file located.

Please help pointed out a fault in my command if found. Thank you in advance.

  • How about cd /home/tect/Loco/ && zip -9pr /mnt/test/Raimi/temp/Testing.zip *txt? – Julie Pelletier Mar 21 '17 at 3:13
  • It shows bash: cd/home/tect/Loco/ : No such file or directory – mohd raimi Mar 21 '17 at 7:25
  • 1
    I see you got a working answer, but please learn to copy-paste or at the very least copy spaces properly. – Julie Pelletier Mar 21 '17 at 20:30
2

The -j (--junk-paths) option of zip is there exactly for this purpose.

From man zip:

-j --junk-paths

Store just the name of a saved file (junk the path), and do not store directory names. By default, zip will store the full path (relative to the current directory).

So, do:

zip -9jpr /mnt/test/Raimi/temp/Testing.zip /home/tect/Loco/*txt
  • And what if I want to run Cron task. For each time the cron activate,the produced output naming will increase by 1. Such as Testing1,Testing2 an so on? – mohd raimi Mar 21 '17 at 8:19
  • @mohdraimi: That's a different question which basically implies running a script that saves a counter variable in another file. – Julie Pelletier Mar 21 '17 at 20:30

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