本文于 113 天前发布,最后更新于 113 天前
alias tarthis='( ( D=`builtin pwd`; F=$(date +$HOME/`sed "s,[/ ],#,g" <<< ${D/${HOME}/}`#-%F.tgz); tar --ignore-failed-read --transform "s,^${D%/*},`date +${D%/*}.%F`,S" -czPf "$F" "$D" &>/dev/null ) & )'
将上述命令添加到环境变量中,保存退出,使其生效 source .bash_profile
。便可使用 tarthis 命令归档当前目录。
验证:
[root@dameng linuxscript]# pwd /root/linuxscript [root@dameng linuxscript]# tarthis [root@dameng linuxscript]# cd [root@dameng ~]# ll \#linuxscript#-2024-12-13.tgz -rw-r--r-- 1 root root 21505 Dec 13 09:48 '#linuxscript#-2024-12-13.tgz' [root@dameng ~]# tar -zxvf \#linuxscript#-2024-12-13.tgz tar: Removing leading `/' from member names /root.2024-12-13/linuxscript/ /root.2024-12-13/linuxscript/newfile.sh /root.2024-12-13/linuxscript/nmap-bootstrap.xsl /root.2024-12-13/linuxscript/list-cronjobs.sh /root.2024-12-13/linuxscript/user-cpu.sh /root.2024-12-13/linuxscript/test.txt /root.2024-12-13/linuxscript/autobak.sh /root.2024-12-13/linuxscript/demo.sh /root.2024-12-13/linuxscript/qmql/ /root.2024-12-13/linuxscript/qmql/danshu.tar /root.2024-12-13/linuxscript/qmql/shuangshu.tar /root.2024-12-13/linuxscript/~ip.txt /root.2024-12-13/linuxscript/invoke.sh /root.2024-12-13/linuxscript/file_size_distribution.sh /root.2024-12-13/linuxscript/demo.log /root.2024-12-13/linuxscript/scan.xml /root.2024-12-13/linuxscript/backup.sh /root.2024-12-13/linuxscript/demo.sh.crypt /root.2024-12-13/linuxscript/cpu.sh /root.2024-12-13/linuxscript/maclist /root.2024-12-13/linuxscript/hosts /root.2024-12-13/linuxscript/firewall-audit
执行效果图:
执行 tarthis 即可在 $HOME 目录中生成当前目录的压缩包。