繁体   English   中英

tar目录中的文件并将存档放在另一个目录中

[英]tar the files in a directory and put the archive in another directory

我正在尝试将目录中的所有文件(echo 1)tar到归档目录(第二个echo)中名为[directory name] .tar的tar归档文件中。 这个对吗 ?

#!/bin/bash

#Author
#Josh
++++++++++++++++++++++++++
echo "Please enter the name of a folder to archive" 
++++++++++++++++++++++++++
echo "Please enter a foldername to store archives in"
++++++++++++++++++++++++++
touch fname
+++++++++++++++++++++++++
tar fname2.tar
dir_to_be_tarred=
while [ ! -d "$dir_to_be_tarred" ]; do      
    echo -n "Enter path to directory to be archived: "   # -n makes "echo" not output an ending NEWLINE
    read dir_to_be_tarred
    if [ ! -d "$dir_to_be_tarred" ]; then   # make sure the directory exists
        echo "Directory \"$dir_to_be_tarred\" does not exist"       # use quotes around the directory name in case user enter an empty line
    fi
done

storage_dir=
while [ ! -d "$storage_dir" ]; do
    echo -n "Enter path to directory where to store the archive: "
    read storage_dir
    if [ ! -d "$storage_dir" ]; then
        echo "Directory \"$storage_dir\" does not exist"
    fi
done

tarfile="$storage_dir"/`date '+%Y%m%d_%H%M%S'`.tar.gz       # the tar archive is named "YYYYMMDD_HHMMSS.tar.gz"
tar cfz "$tarfile" "$dir_to_be_tarred"
echo 'Your archive is in:
'`ls -l "$tarfile"`

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM