LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-01-2018, 10:00 AM   #1
femina.jaffer@gmail.com
LQ Newbie
 
Registered: Sep 2018
Posts: 3

Rep: Reputation: Disabled
Help me - zip all files individually in directories and subfolders


Hello,

Can anyone help me please, rather urgently? Basically, I need to loop thru the directory path and its sub folders and only zip the files individually without including the folders. The directories and sub folders should NOT be zipped. The original file should be deleted after its is saved/moved to a temp folder.

Also, how can i limit certain file types from being zipped (eg. *.zip, *.tar, *.pgp etc). If possible, I know I am asking to much....can we count the number of directories and then only zip based on certain number of directories?

Thanks so much!
 
Old 09-01-2018, 03:07 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,553

Rep: Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946
Quote:
Originally Posted by femina.jaffer@gmail.com View Post
Hello,

Can anyone help me please, rather urgently? Basically, I need to loop thru the directory path and its sub folders and only zip the files individually without including the folders. The directories and sub folders should NOT be zipped. The original file should be deleted after its is saved/moved to a temp folder.

Also, how can i limit certain file types from being zipped (eg. *.zip, *.tar, *.pgp etc). If possible, I know I am asking to much....can we count the number of directories and then only zip based on certain number of directories?
Read the LQ Rules and "Question Guidelines". We are happy to help you, but we aren't going to write scripts for you; you need to show effort of your own, so post what you have written/done/tried so far, and tell us where you're stuck. Also, when asking a group of volunteers for help, asking for/expecting 'urgent' help is fairly rude. We volunteer our time.
 
Old 09-01-2018, 05:32 PM   #3
femina.jaffer@gmail.com
LQ Newbie
 
Registered: Sep 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thank you.

My apologies, I didn't really mean to ask for a script I am somewhat experienced with writing shell scripts; but I haven't written in a long while.

I did start with the command line using "find" but it didn't do exactly what I wanted. I am still getting some duplicated zip files in the sub folders. I am also not able to get -x option to exclude multiple file names, I tried adding the switch after the execdir zip -x and could not get that too work.

find . -type f -execdir zip '{}.zip' '{}' \;

Thanks!
 
Old 09-01-2018, 07:28 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
simplely off the top of my head so it is only an idea. the tar commands will not be there.
Code:
#!/bin/bash

working_dir=/
move_to=/somewhere_else
sctipt_dir=/scripts

while read f ; do
{   
    
   # f = path and file to be tared
   zip / tar $f

   #remove original file
   rm $f
   #you will know the name of the file that is tared
   # then just add it to the code to move it to 
   #gets path the tar is in plus whatever you named the tar file

   mv -v "${f%/*}/file.tar "$move_to"
   
}
done<<<$(find "$working_dir" -type f -name "*.file")"
if you have other type files you have to figure out what or how to test files to ensure you're only processing the ones you want to. a common denominator
 
Old 09-01-2018, 07:55 PM   #5
femina.jaffer@gmail.com
LQ Newbie
 
Registered: Sep 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks so much! Will give it a try and let you know.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find the directories which is older than x days delete and zip those directories ramesh pagadala Linux - Newbie 2 08-29-2013 08:17 AM
Bash Question(for loop): How to Zip multiple files under multiple directories Znrall Linux - General 2 08-01-2012 01:52 PM
Linux zip program's -d -tt option deletes all files from zip archive Arun Gupta Linux - Software 4 04-27-2011 07:06 PM
How do i mount user directories individually in samba on WinXP avinash.rao Ubuntu 1 08-12-2008 04:47 AM
Excluding directories from zip files jonathanztaub Linux - General 1 05-17-2004 02:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration