Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Is there a better way to do it than this? (I have not tested this script yet, so it is more like pseudo code...)
Code:
#!/bin/sh
#tar & compress all subdirectories individually
for file in $(ls -1); do
if [ -d file ]; then
tar --delete-files -czf ${file}.zip $file
fi
done
exit 0
What are you suggesting is wrong with your proposed method?
I would suggest a more "traditional" file extension though - probably filename.tar.gz
I didn't know if anything was wrong with this method. But usually when i think a loop is the right way to do it, someone on here gives me a 1-liner that is much better.
I just tested my code and this works:
Code:
for file in $(ls -1); do if [ -d $file ]; then tar --remove-files -czvvf ${file}.zip ${file}/; fi; done
Add the files to the zip archive without using tar
I know no more than this:
Quote:
zip is a compression and file packaging utility ... it is analogous to a combination of the UNIX commands tar and compress and is compatible with PKZIP (Phil Katz’s ZIP for MSDOS systems).
That makes me think the prior tar -cjf command would do the same thing.
BTW, this works:
Code:
for file in $(ls -1); do if [ -d $file ]; then zip -rm ${file}.zip ${file}/; fi; done
#!/bin/sh
# zip all subdirectories individually
if [ $# -ne 1 ]; then
echo 1>&2 Usage: $0 path/exclusion.lst
exit 1
fi
echo "exclusion list contains" `cat $1`
for file in $(ls -1); do
echo checking "$file"
if [ -d "$file" ]; then
echo "$file is a directory"
exclCheck=`grep "$file" $1`
if [ -z $exclCheck ]; then
echo "zipping $file"
zip -rm "${file}.zip" "${file}/"
else
echo "Exclusion list contains ${exclCheck}."
echo "skipping $file"
fi;
fi;
done
exit 0
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.