How could I read the content of a parent folder and if sub-folders are found, then make a tar.gz
files of those subfolders found. However, I know that subfolders will have the following filename format: name-1.2.3
What I want is to create a tar.gz
file that looks like: name-1.2.3-20100928.tar.gz
Any help will be appreciated.
views:
31answers:
2
A:
#!/bin/sh
DATE=`/bin/date +%y%m%e`
cd /path/to/your/folder
for folder in *; do
if [ -d $folder ]; then
tar -cvzf $folder-$DATE.tar.gz $folder
fi
done
mezzie
2010-09-28 20:18:55
A:
Better immunize your scripts against spaces in names:
#!/bin/bash
# Yes nested quoting is allowed with $(...) syntax, no matter whether syntax coloration does
DATE="$(/bin/date "+%y%m%e")"
cd /path/to/your/folder
for folder in * ; do
if test -d "$folder" ; then
tar cvzf "$folder-$DATE.tar.gz" "$folder"
fi
done
Benoit
2010-09-29 06:46:53