vlg
asked on
Bash script needed to zip all subdirs
Hello all
In a dir, call it /home/fred, I have many subdirs, many with subdirs themselves.
I'd like a bash script that gets all the dir names in /home/fred, and zips them into zipfiles named after the directory itself with a ".zip" at the end.
Something like ls -D | xargs zip -r somehow_get_the_dir_name.z ip dir_name would work from the command line but I can't figure out how to pass the dir names to the zip command, so I'm guessing that some scripting is called for here.
Thanks!
v
In a dir, call it /home/fred, I have many subdirs, many with subdirs themselves.
I'd like a bash script that gets all the dir names in /home/fred, and zips them into zipfiles named after the directory itself with a ".zip" at the end.
Something like ls -D | xargs zip -r somehow_get_the_dir_name.z
Thanks!
v
If you have GUN tar, it is better to do:
tar -czvf backup.tar.gz `find /home/fred -type d`
If you want related path, use:
cd /home/fred
tar -czvf backup.tar.gz `find . -type d`
To verify what's in the *.gz file:
tar -ztvf backup.tar.gz
To extract files from the backup .gz file:
tar -zxvf backup.tar.gz
tar -czvf backup.tar.gz `find /home/fred -type d`
If you want related path, use:
cd /home/fred
tar -czvf backup.tar.gz `find . -type d`
To verify what's in the *.gz file:
tar -ztvf backup.tar.gz
To extract files from the backup .gz file:
tar -zxvf backup.tar.gz
I will go for yuzh suggestion, tar and gz is zip the file and compress it, and you can also do with a directory :)
ASKER
Hello
Yes, I'd love to use tar, but it will be decompressed by Windows people who have no tar, so I have to use the zip format.
liddler, your code is descending into the subdirectories in /home/fred -- can I make it not do that? Just take any dir it finds in /home/fred, and zip it.
Thanks!
Yes, I'd love to use tar, but it will be decompressed by Windows people who have no tar, so I have to use the zip format.
liddler, your code is descending into the subdirectories in /home/fred -- can I make it not do that? Just take any dir it finds in /home/fred, and zip it.
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Winzip, or the compress utilities comes with Window XP can handle the *.tar.gz file.
So, the "find"command is the answer for you?
It doesn't make much sense to me for the question !
Ok, guys, Merry Xmas and Happy New Years, Cheers!
It doesn't make much sense to me for the question !
Ok, guys, Merry Xmas and Happy New Years, Cheers!
for dir in `find /home/fred -type d`
do
cd $dir
zip -r $dir.zip `ls -D .`
done