on-internet
← Community

shell script to back up files

Stack Overflow ·

backupfile(){ if [ $# -ne 1 ];then echo "Invalid argument number,exprcted 1 receivd $#" return fi dir=$1 file=$2 if [ ! \( -d $dir/backup \) ];then mkdir $dir/backup fi for file in $file;do if [ -f $file ]&&[ ! \(-f $dir/backup/${file##*/} \) ];then cp $file $dir/backup/${file##*/} echo "$file has been backed up." fi done } read -p "Entry the diractory you want to backup::" arg1 backupfile $arg1 This is a function named backupfile that is intended to back up files. It first creates a folder named “backup” and then backs up the specified file to that folder. At least, that is how I understand i

Comments

Sign in or sign up to comment and upvote.

No comments yet.