Zip recursive content of folder when (not current directory=


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Zip recursive content of folder when (not current directory=
# 1  
Old 04-13-2010
Question Zip recursive content of folder (not current directory)

Hi,

Is there a way to zip the content (recursively) of a folder other then the current directory, and keep the directory structure intact?

Example:

/var/tmp/myfolder
----------------- file1
----------------- file2
----------------- folder1
------------------------ file3


Now I want to create a zip file that looks like this:
file1
file2
folder1
------ file3

ie I don't want the folder "myfolder" to be part of the zip file, only the *content* of that folder. And I want to execute the zip-command from anywhere (ie not necessarily with "myfolder" as the current directory).

Is this possible, in one single command using the basic zip command? I found a few threads here that touched this topic, but none that answered it fully.

Regards
/Jimi

Last edited by jimih; 04-13-2010 at 12:32 PM..
# 2  
Old 04-13-2010
Using find command with cpio or tar to create an archive then you zip the archive file
# 3  
Old 04-13-2010
Data

Quote:
Originally Posted by vbe
Using find command with cpio or tar to create an archive then you zip the archive file
ok, so what you are saying is that it is impossible to achieve with a single zip-command?
# 4  
Old 04-13-2010
I suppose it depends of zip version (and origin...)
e.g. here in HP-UX :
Code:
ant:/home/vbe $ /usr/local/bin/zip -R foo sas_cours/*
        zip warning: name not matched: .mozilla/firefox/jax156rk.vbe/lock
        zip warning: name not matched: .mozilla/firefox_save/jax156rk.vbe/lock
        zip warning: name not matched: script/091102/save
        zip warning: name not matched: script/091105/save/save
  adding: sas_cours/accident.sas7bdat (deflated 95%)
  adding: sas_cours/monde1.sas7bdat (deflated 84%)
  adding: sas_cours/monde.sas7bdat (deflated 88%)
  adding: sas_cours/marque.sas7bdat (deflated 90%)
  adding: sas_cours/manquant.sas7bdat (deflated 90%)
  adding: sas_cours/magasin.sas7bdat (deflated 90%)
  adding: sas_cours/machine.sas7bdat (deflated 90%)
  adding: sas_cours/logimport.sas (deflated 21%)
  adding: sas_cours/logexportxt.sas (deflated 17%)
  adding: sas_cours/logexport.sas (deflated 16%)
  adding: sas_cours/iris.sas7bdat (deflated 92%)
  adding: sas_cours/test68.sas7bdat (deflated 91%)
  adding: sas_cours/log_expaccid.sas (deflated 17%)
  adding: sas_cours/qualite.sas7bdat (deflated 94%)
  adding: sas_cours/fitness.sas7bdat (deflated 85%)
  adding: sas_cours/propage.sas7bdat (deflated 85%)
  adding: sas_cours/htwt.sas7bdat (deflated 88%)
  adding: sas_cours/pays.sas7bdat (deflated 73%)
  adding: sas_cours/films.sas7bdat (deflated 85%)
  adding: sas_cours/formats.sas7bcat (deflated 97%)
  adding: sas_cours/ingots.sas7bdat (deflated 86%)
  adding: sas_cours/test.sas7bdat (deflated 91%)
  adding: sas_cours/teach.sas7bdat (deflated 91%)
  adding: sas_cours/secret.sas7bdat (deflated 90%)
  adding: sas_cours/scores.sas7bdat (deflated 91%)
  adding: sas_cours/remiss.sas7bdat (deflated 90%)
  adding: sas_cours/region.sas7bdat (deflated 93%)
  adding: sas_cours/log_exp_classe.sas (deflated 17%)
  adding: sas_cours/monde2.sas7bdat (deflated 86%)
  adding: sas_cours/note.sas7bdat (deflated 84%)
  adding: sas_cours/pays2.sas7bdat (deflated 89%)
  adding: sas_cours/pgm.asv (deflated 19%)
  adding: sas_cours/phys8.sas7bdat (deflated 84%)
  adding: sas_cours/plant.sas7bdat (deflated 86%)
  adding: sas_cours/produit.sas7bdat (deflated 86%)
  adding: sas_cours/produit1.sas7bdat (deflated 85%)
  adding: sas_cours/patient.sas7bdat (deflated 83%)
  adding: sas_cours/expaccid.csv (deflated 43%)
  adding: sas_cours/exp_classe.txt (deflated 53%)
  adding: sas_cours/ecole.sas7bdat (deflated 86%)
  adding: sas_cours/depense.sas7bdat (deflated 86%)
  adding: sas_cours/exo11.sas (deflated 19%)
  adding: sas_cours/cars.sas7bdat (deflated 94%)
  adding: sas_cours/exo2.sas (deflated 2%)
  adding: sas_cours/classe.sas7bdat (deflated 88%)
  adding: sas_cours/exo3.sas (deflated 22%)
  adding: sas_cours/crebas_v8_unix.sas (deflated 74%)
  adding: sas_cours/canc.sas7bdat (deflated 88%)
  adding: sas_cours/budget.sas7bdat (deflated 91%)
  adding: sas_cours/achat.sas7bdat (deflated 92%)
  adding: sas_cours/auto.asc (deflated 48%)
  adding: sas_cours/auto.sas7bdat (deflated 91%)
  adding: sas_cours/auto1.sas7bdat (deflated 94%)
  adding: sas_cours/autoexec.sas (deflated 79%)
  adding: sas_cours/bac.sas7bdat (deflated 91%)
  adding: sas_cours/basket.sas7bdat (deflated 90%)
  adding: sas_cours/exo6.sas (deflated 18%)
  adding: sas_cours/chien.sas7bdat (deflated 90%)
  adding: sas_cours/client.sas7bdat (deflated 88%)
  adding: sas_cours/dogs.sas7bdat (deflated 86%)
  adding: sas_cours/exo5_b.sas (deflated 49%)
  adding: sas_cours/exo5_a.sas (deflated 27%)
  adding: sas_cours/exo4_c.sas (deflated 59%)
  adding: sas_cours/exo4_b.sas (deflated 20%)
  adding: sas_cours/exo4_a.sas (deflated 25%)
  adding: sas_cours/exo3_b.sas (deflated 24%)
  adding: sas_cours/dico.sas7bdat (deflated 92%)
  adding: sas_cours/detergen.sas7bdat (deflated 87%)
  adding: sas_cours/edu91.sas7bdat (deflated 86%)
  adding: sas_cours/educatio.asc (deflated 51%)
  adding: sas_cours/educatio.sas7bdat (deflated 86%)
  adding: sas_cours/employes.sas7bdat (deflated 85%)
  adding: sas_cours/exo1.sas (deflated 25%)
  adding: sas_cours/exo1.sas.sav (deflated 25%)
  adding: sas_cours/crime.sas7bdat (deflated 84%)
  adding: sas_cours/trefle.sas7bdat (deflated 90%)
  adding: sas_cours/urgence.sas7bdat (deflated 90%)
  adding: sas_cours/uspop.sas7bdat (deflated 86%)
  adding: sas_cours/vache.sas7bdat (deflated 87%)
  adding: sas_cours/vehicule.sas7bdat (deflated 85%)
  adding: sas_cours/vente.sas7bdat (deflated 85%)
  adding: sas_cours/voiture.sas7bdat (deflated 86%)
  adding: sas_cours/voitures.sas7bdat (deflated 94%)
ant:/home/vbe $ ll foo.zip 
-rw-rw-r--   1 vbe        bin         194308 Apr 13 18:22 foo.zip

But this is not HP-UX standard:
Quote:

ZIP(1L) Info-ZIP ZIP(1L)
14 August 1999 (v2.3)

NAME
zip, zipcloak, zipnote, zipsplit - package and compress (archive)
files

SYNOPSIS
zip [-aABcdDeEfFghjklLmoqrRSTuvVwXyz!@$] [-b path] [-n suffixes]
[-t mmddyyyy] [-tt mmddyyyy] [ zipfile [ file1 file2 ...]] [-xi list]

zipcloak [-dhL] [-b path] zipfile

zipnote [-hwL] [-b path] zipfile

zipsplit [-hiLpst] [-n size] [-b path] zipfile

DESCRIPTION
zip is a compression and file packaging utility for Unix, VMS, MSDOS,
OS/2, Windows NT, Minix, Atari and Macintosh, Amiga and Acorn RISC OS.
It is analogous to a combination of the UNIX commands tar(1) and
compress(1) and is compatible with PKZIP (Phil Katz's ZIP for MSDOS
systems). A companion program (unzip(1L)), unpacks zip archives. The
zip and unzip(1L) programs can work with archives produced by PKZIP,
and PKZIP and PKUNZIP can work with archives produced by zip. zip
version 2.3 is compatible with PKZIP 2.04. Note that PKUNZIP 1.10
cannot extract files produced by PKZIP 2.04 or zip 2.3. You must use
PKUNZIP 2.04g or unzip 5.0p1 (or later versions) to extract them.


---------- Post updated at 18:54 ---------- Previous update was at 18:33 ----------

Have you tried -r ./* ?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Recursive folder search faster than find?

I'm trying to find folders created by a propritary data aquisition software with the .aps ending--yes, I have never encountered folder with a suffix before (some files also end in .aps) and sort them by date. I need the whole path ls -dt "$dataDir"*".aps"does exactly what I want except for the... (2 Replies)
Discussion started by: Michael Stora
2 Replies

2. UNIX for Dummies Questions & Answers

How to extract contents of ONLY one directory from ZIP folder.

I have a ZIP folder ( folder.zip or folder.jar ) which contains , lets say 3 directories under it ( directory1, directory2, directory3). How can i unzip the contents of directory2 ONLY ? I do not have to unzip the complete folder. TIA. (2 Replies)
Discussion started by: Sheel
2 Replies

3. Shell Programming and Scripting

Restricting zip to current directory only

I am using the following command in a C shell script: find . -name "*.*" -print | zip $ProjectZipFile -@ to zip files in a Unix (Sun and/or Linux) directory for archiving purposes. This command works fine, the only problem being that if sub-directories are present, they are included in... (5 Replies)
Discussion started by: phudgens
5 Replies

4. UNIX for Dummies Questions & Answers

Zip command (zip folder doesn't include a folder of the same name)

Hi guys, I have a question about the zip command. Right now I have a directory with some files and folders on it that I want to compress. When I run the zip command: zip foo -r I am getting a foo.zip file that once I unzip it contains a foo folder. I want to create the foo.zip, but that... (1 Reply)
Discussion started by: elioncho
1 Replies

5. Shell Programming and Scripting

Finding files in current directory when 100,000's files in current directory

Hi All I was wondering what is the most efficient way to find files in the current directory(that may contain 100,000's files), that meets a certain specified file type and of a certain age. I have experimented with the find command in unix but it also searches all sub directories. I have... (2 Replies)
Discussion started by: kewong007
2 Replies

6. Windows & DOS: Issues & Discussions

How can I upload a zip folder on a unix path from my windows folder?

Hello, I am an amature at UNIX commands and functionality. Please could you all assist me by replying to my below mentioned querry : How can I upload a zip folder on a unix path from my windows folder? Thanks guys Cheers (2 Replies)
Discussion started by: ajit.yadav83
2 Replies

7. Shell Programming and Scripting

Zip the folder

i want the scripts or unix command to zip the folder. (3 Replies)
Discussion started by: kingganesh04
3 Replies

8. Shell Programming and Scripting

Recursive call to find files and directories in Shell script from current path.

################################################################ Copy this script to your path from where you want to search for all the files and directories in subdirectories recursively. ################################################################# code starts here... (2 Replies)
Discussion started by: Ramit_Gupta
2 Replies

9. Shell Programming and Scripting

non recursive search in the current directory only

Hi, Am trying for a script which should delete more than 15 days older files in my current directory.Am using the below piece of code: "find /tmp -type f -name "pattern" -mtime +15 -exec /usr/bin/ls -altr {} \;" "find /tmp -type f -name "pattern" -mtime +15 -exec /usr/bin/rm -f {} \;" ... (9 Replies)
Discussion started by: puppala
9 Replies

10. Shell Programming and Scripting

Use awk to create new folder in current directory

Alright, I am sure this is a laughable question, but I don't know so I am going to ask anyway. I have a little script I am writing to take information from one source, recode it in a certain way, and print to files for each subject I have data for. This all works perfectly. I just want to put... (6 Replies)
Discussion started by: ccox85
6 Replies
Login or Register to Ask a Question