Help me - zip all files individually in directories and subfolders
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.