Zip all the files including directories - subdirectories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Zip all the files including directories - subdirectories
# 1  
Old 07-02-2012
Zip all the files including directories - subdirectories

Hi,

Is is possible to zip a folder and all its contents within the folder ( including sub-directories and files) into a zip file? and can regain the same structure if unzipped?


Thanks
# 2  
Old 07-02-2012
tar it first then zip the tar file. This syntax works on any UNIX:

Code:
cd ./path
tar cvf /tmp/my_archive.tar *
# zip or gzip
gzip  /tmp/my_archive.tar

To unpack and use:
Code:
mkdir ./my_new_path
cd ./my_new_path
gunzip /tmp/my_archive.tar.gz
cd ./my_new_path
tar xf /tmp/my_archive.tar

# 3  
Old 07-02-2012
Hi,

Yes this can be acheive by the tar and gzip command. Look up the man pages for more details but below is a short example.

Code:
This is the dir structure of test, it has sub dirs test1 and test2 and even files underneath. 
test/
test/test1/
test/test2/

# you will have to create the archive of the dirs you want by doing this 

tar -cvf test.tar test # test.tar is the name you are giving to ur tar file. 
                              # test is the dir. note you can specify multiple dirs by   giving a space ex: test1 test 2 ..so on

# once your tar is created, use gzip to compress the tar ball. 

gzip test.tar 

# if you want to extract the tar you can do so by following :
# gunzip and then extract. 

gunzip test.tar.gz /tmp/wherevr # this will un-compress the tar ball.

tar -xvf test.tar /tmp/wherver # this will extract the tar ball with all the sub dirs and files underneath.

# 4  
Old 07-02-2012
Can a mix of tar and other options like -z or something help?

I am just curious and not sure about the options.
# 5  
Old 07-02-2012
you can use the -z option to compress and uncompress directly.
this eliminates the use of an extra command gzip/gunzip
# 6  
Old 07-02-2012
Quote:
Originally Posted by Irishboy24
you can use the -z option to compress and uncompress directly.
this eliminates the use of an extra command gzip/gunzip
Thanks!

I wondered because I remembered using tar with other options.
# 7  
Old 07-02-2012
Warning: the -z option does not work on all UNIX systems.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 Replies

2. Shell Programming and Scripting

Unzip all the files with subdirectories present and append a part of string from the main .zip files

Hi frnds, My requirement is I have a zip file with name say eg: test_ABC_UH_ccde2a_awdeaea_20150422.zip within that there are subdirectories on each directory we again have .zip files and in that we have files like mama20150422.gz and so on. Iam in need of a bash script so that it unzips... (0 Replies)
Discussion started by: Ravi Kishore
0 Replies

3. Shell Programming and Scripting

Find file and zip without including directory path

Does anyone know of a way to zip the resulting file from a find command? My approach below finds the file and zips the entire directory path, which is not what I need. After scanning the web, it seems to be much easier to perform gzip, but unfortunately the approach must use zip. find `$DIR`... (5 Replies)
Discussion started by: koeji
5 Replies

4. UNIX for Dummies Questions & Answers

show all text files in directories and subdirectories

Hi! I am trying to find all text files in my home directory that contain the string "C-d" so I tyied this : cd ~ find . -type f -exec grep -l "C-d" {} + but it took very long so I tryed this : ls -aR | xargs file |grep text but it didn't descend in the directories and it said :... (3 Replies)
Discussion started by: kelamahim
3 Replies

5. UNIX for Dummies Questions & Answers

Help with untarring multiple files from tarred directories and subdirectories

Hi, I want to untar all log files from following tarred directory hierarchy Log_files.tar.gz/subject*.tar.gz/project*/*.log It means there are subject1.tar.gz to subject9.tar.gz and in those tarred subect directories there are project1 - project5 directories and in those directories there... (2 Replies)
Discussion started by: rv_trojan
2 Replies

6. UNIX for Dummies Questions & Answers

dircmp without including sub-directories

I have 2 directories I want to compare for like files. One directory has 2 subdirectories associated with it, the other directory does not. When I do the dircmp -s I should get only a few files different between the two directories. I do, but the directory with subdirectories prints out all these... (3 Replies)
Discussion started by: MissI
3 Replies

7. UNIX for Dummies Questions & Answers

Create zip without including directories

Hi guys, I'm trying to do the following: zip -r /tmp/foo.zip public/accounts/foo But the zip that's been made has the whole "public/accounts/foo" path. I want only the foo folder to be zipped. How can I do this? Thanks, Elías (2 Replies)
Discussion started by: elioncho
2 Replies

8. UNIX for Dummies Questions & Answers

Zip a folder including its sub-folders.

Hi, I have a folder that contains a few sub-folders. I would like to zip that folder and KEEP the subfolders. What it does at the moment is taking all the files within the subfolders and zipping them into one big file (zip -r ...). Does anyone know the UNIX command to keep the subfolders in the... (3 Replies)
Discussion started by: gdog
3 Replies

9. Shell Programming and Scripting

How to Remove Ctrl M characters in files from directories and its subdirectories

Hi, How to recursively remove Ctrl M characters in files from a directory and its sub directory ? I know unix2dos command is there but to remove in bunch of files ... ? Thanks (7 Replies)
Discussion started by: skdp
7 Replies

10. UNIX for Dummies Questions & Answers

to grep and rm including all subdirectories

Is there a way to grep a word pattern in all files under all subdirectories? Similar question with rm. To remove files with certain extension in all subdirectories? Thanks to all who reply! (1 Reply)
Discussion started by: annej33
1 Replies
Login or Register to Ask a Question