How could I read the content of a parent folder and if sub-folders are found, then make a tar.gz
files of th开发者_StackOverflow中文版ose 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.
#!/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
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
精彩评论