Linux中自定义命令实现随时随地归档目录
本文于 118 天前发布,最后更新于 118 天前
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 目录中生成当前目录的压缩包。

暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇