Zipping contents without the actual directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Zipping contents without the actual directory
# 1  
Old 09-12-2017
Zipping contents without the actual directory

Hi ,
I want to zip files present in the directories listed under a parent directory without zipping the directory itself
my parent directory path is
/informatica/DGDMN/PowerCenter1011/server/infa_shared/SrcFiles/OTE/Final_Directory
I have the below directories named as 1,2,3,4,5 listed under the parent directory "Final_Directory"
Code:
1
2
3
4
5

I want to zip the contents of each of these five directories separately and create 5 separate zipped files in such a way that the directory itself does not get zipped
The code that I used to create 5 zipped files is below. But it creates 5 zipped files along with zipping their folders (1,2,3,4,5).How should I modify this script to create zipped files only for the contents of each of these folders separately without zipping their actual folders?

Please help

Code:
 cd $final_path ;
 for i in */ ;
 do zip -r "${i%/}.zip" "$i" ; 
 done


Last edited by rbatte1; 09-13-2017 at 12:19 PM..
# 2  
Old 09-12-2017
you could add
Code:
cd $i

before issuing zip command, and then
Code:
cd ..

right after

So your loop would look like follows
Code:
 
 do
   cd $I
   your zip here, just adjust it accordingly
   cd ..
 done

# 3  
Old 09-13-2017
Quote:
Originally Posted by paul1234
Hi ,
I want to zip files present in the directories listed under a parent directory without zipping the directory itself
You haven't told us which OS you are using:

Code:
find <startdir> -type d -exec /path/to/zip {} {}/* \;

Notice, that some versions of the find-command do not allow for multiple instances of the {}-macro and because i do not know which one you are using you will have to find out if yours does or doesn't. In the latter case put the zip-command into a small script to which you pass the {} as argument and call that from the find-command.

I hope this helps.

bakunin
# 4  
Old 09-13-2017
Another option:-

Code:
cd /path/to/main/dir
for subdir in *
do
   pushd $subdir
   if [ $? =0 ]
   then
      tar -cvf ../$subdir.tar .
      popd
   else
      echo "Failed to change to \"$subdir\"" >&2
   fi
done

This will safely change into & out of the directories you are working with and create a .tar for each on in the main directory (the big huge path you list) or you could direct them to a specific location if that is better for you.


I hope that this helps,
Robin
# 5  
Old 09-13-2017
Can you help with zipping the files ?
# 6  
Old 09-13-2017
Moderator's Comments:
Mod Comment Posting "Does not work" without explanation does not help you or anyone. If a command does not work for you, please show the exact circumstances you used it, and the exact error or malfunction you received. Do not paraphrase errors, or post the text as links, images, or attachments if you can avoid it: Paste the exact message, in code tags, like [code] text [/code] or by selecting the text and using the Image button.

Thank you.

The UNIX and Linux Forums
# 7  
Old 09-13-2017
Quote:
Originally Posted by paul1234
I tried this ..and it is not working
Hello paul1234,

Telling us "it is not working" will NOT help either you or us. Our respected forum members(MODs-->rbatte1, bakunin) already tried to help you without knowing much information about your system. I would like to request you please let us know all the details about your system eg--> O.S, sample Input_file in code tags more clearly and expected sample output more clearly in code tags along with all the conditions which you want to keep in solution. So that we could try to help and could try to learn/guide on same.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Zipping the logs of directory

Hi Folks, I have logs at the following location cd /out/app/logs/ now that logs directory contain different types of logs now sometimes i need to do disk clean up activity so i need to zipped the logs can you please advise any command by which all the logs created in this directory are... (2 Replies)
Discussion started by: punpun66
2 Replies

2. UNIX for Dummies Questions & Answers

Deleting a directory and zipping another directory

Hi Folks, I have a directory in unix that is /usr/local/pos contain the folowing directoreis ..that is dir1 dir2 dir3 now I want to delete only dir2 please advise how to remove the directory dir 2 ..that is rm command and how to use it , and second if I want to zip the dir3 please... (1 Reply)
Discussion started by: punpun66
1 Replies

3. Shell Programming and Scripting

Catching the xml tag when only parent directory is known ..not the actual directory

Hi folks, I have an query that is let say i have to search in an xml file an tag that is <abcdef> now this xml file is at /opt/usr/local so one fastest way to achieve this is go to this location by cd /opt/usr/local and then do grep like this... grep -i abcdef but for this I must know the... (4 Replies)
Discussion started by: punpun66
4 Replies

4. Shell Programming and Scripting

Zipping a directory and extracting to another server.

Hello everyone, I am trying to make a script in KSH that will zip an entire directory but leave out one file in that directory. I then need to send that zipped directory to another UNIX box. I am new to UNIX and would appreciate a good template to study from. (3 Replies)
Discussion started by: BrutalBryan
3 Replies

5. Ubuntu

Help with zipping contents but not path

I have a folder, and in this folder, there are about 197 folders. Resources a files and folders b files and folders Like that. I need to make a zip with files and folders in them with the name the same as the parent folder. so. a.zip files and folders b.zip files and... (4 Replies)
Discussion started by: austech360
4 Replies

6. Shell Programming and Scripting

Zipping of file in a different directory

Hi, I am having some problem with a shell script which zip some files. For zipping I have used the following command: find . -name "Test_*" -mtime 0 | zip Test_$(date +"%Y%m%d") -@ I have kept the script in /home/abc directory. It is creating the zip file within the same directory where i... (2 Replies)
Discussion started by: abhishek_510
2 Replies

7. Shell Programming and Scripting

zipping a directory when the file count is over $X

Hiya, I've been plugging away at this script and I cant get it to behave as I need. first off it fails to adhere to the conditions of the file limit, and zips the directory regardless of the file count and secondly, but less important it zips up the entire path not just the directory I'm... (2 Replies)
Discussion started by: orionrush
2 Replies

8. Shell Programming and Scripting

Remove contents of directory, but not directory

What's the best way to delete everything in a directory, but not the directory itself, without using shell wildcards? (9 Replies)
Discussion started by: pdc
9 Replies

9. UNIX for Dummies Questions & Answers

zipping all the tar files to singlr file in directory

Hi, i have more than 300 tar files in directory and i want to zip all tar files to single file. could anybody tell me the command since i know how to do zip for single tar file: bash-3.00$gzip 2008_11_10.tar bash-3.00$ pwd /oracle1/archivebackup in this directory i have lot files... (2 Replies)
Discussion started by: prakash.gr
2 Replies

10. Shell Programming and Scripting

determining actual directory of a symlinked directory

Hello all, I have files at /var/dir1/dir2/fil1.log etc.,. dir2 is symlinked to /export/xxx/dir3 I am trying to monitor the disk space of the mount where these log files are present. How do I determine dynamically the actual directory of the log files and corresponding mount when I use df... (3 Replies)
Discussion started by: chiru_h
3 Replies
Login or Register to Ask a Question