使用tar命令创建日期为

时间:2015-05-16 19:21:59

标签: shell command ubuntu-12.04 tar

我需要在ubuntu 12.04 32bit

中运行此命令
tar -zcvf $ BACKUP_DIR/backup_`date "+% d-% m-% Y"`.tgz $HOME/tmp

但我无法获取包含日期的目录。当我执行命令时,shell返回

date +%d -%m -%y: the order is not found
tar: Eliminating the `/ 'initial of the names
/tmp/
/tmp/ssh-IfHQiXoK1342/
tar: /tmp/ssh-IfHQiXoK1342/agent.1342: the socket is not taken into account
/tmp/.ICE-unix/
tar: /tmp/.ICE-unix/1342: the socket is not taken into account
/tmp/pulse-xvCP3trutUHz/
/tmp/pulse-xvCP3trutUHz/pid
tar: /tmp/pulse-xvCP3trutUHz/native: the socket is not taken into account
/tmp/.X11-unix/
tar: /tmp/.X11-unix/X0: the socket is not taken into account
/tmp/keyring-ELkby8/
tar: /tmp/keyring-ELkby8/pkcs11: the socket is not taken into account
tar: /tmp/keyring-ELkby8/ssh: the socket is not taken into account
tar: /tmp/keyring-ELkby8/control: the socket is not taken into account
tar: /tmp/keyring-ELkby8/gpg: the socket is not taken into account
tar: /tmp/geany_socket.0e082422: the socket is not taken into account
/tmp/.X0-lock
/tmp/pulse-PKdhtXMmr18n/
/tmp/unity_support_test.0

结果是一个名为backup_的.tgz,我试图将更改为''或“”但它也不起作用。我需要做什么来运行命令?

1 个答案:

答案 0 :(得分:1)

命令替换的输出是wordsplit。你必须引用它。为清楚起见,请使用$()代替反引号。

tar -zcvf "$BACKUP_DIR/backup_$(date "+% d-% m-% Y")".tgz "$HOME/tmp"
相关问题