编写脚本程序备份用户指定的文件,将文件备份到目录名 _backup中(若目录不存在则自动建立),备份文件的文件名格式为文件名_bak_年月日_时分秒。
#! /bin/bash DT=$(date +%F) HT=$(date +%T) TD=~/backup if [ ! -f "$1" ]; then echo "Source $1, does not exist!" exit 1 elif [ ! -d "$TD" ]; then mkdir "$TD" && echo "Directoyr $TD has been created." fi cp $1 $TD/$1_bak_$DT\_$HT && echo "Backup $1 success."