首页
Search
1
Sublime Text 4 正式版发布了,自己动手注册激活以及汉化
537 阅读
2
Lark飞书国际版,免费邮局支持50用户,200GB容量,可SMTP发信
264 阅读
3
Windows激活之路:通过HWIDGen申请永久数字许可证
205 阅读
4
甲骨文云(Oracle Cloud)免费开通ARM云服务器
203 阅读
5
Windows激活之路:将Windows 10 LTSC转成Win10专业版激活
179 阅读
网络资讯
技术教程
活动线报
VPS主机
实用工具
随手小记
登录
Search
标签搜索
VPS
服务器
腾讯云
免费
域名
阿里云
数据库
优惠券
Cloudflare
Github
中国联通
代金券
Docker
中国移动
chrome
JetBrains
Linux
Xshell
百度网盘
联通
小 萌
累计撰写
266
篇文章
累计收到
0
条评论
首页
栏目
网络资讯
技术教程
活动线报
VPS主机
实用工具
随手小记
页面
搜索到
1
篇与
的结果
2021-08-11
rm -rf 又一起惨案,该给Linux整一个回收站了!
全篇转载自 @如有乐享 ,由 小萌 进行编辑,本文仅作存档使用大家还记得这个表情吗??没错!懂一点Linux 基础的都明白这个命令! rm -rf 。 这个命令用不好的话,杀伤力奇高!著名的 rm -rf 惨案! 2015年5月28日 携程疑似由于员工错误操作导致服务挂了2017年2月2日 GitLab 管理员误删生产数据库2017年4月5日 DigitalOcean 出现删除生产数据库的事故2018年4月24日 Kuriko宣布 因机房技术人员 rm -rf /* ,导致 host 上所有数据丢失了......就在前一段时间马甲大佬竟然也踩坑了!!!!线上环境发现某个目录下存在一些类似命名的.png 文件!于是乎想手动删掉。咔咔输入以下命令 😎rm -rf *>.png回车~😎😀过去0.5 秒😉过去 1秒😲 过去1.5秒😥 过去 2秒😱 我擦,赶紧 Ctrl + C赶紧看看目录情况 ls😭 被删了将近一半的文件我去!这怎么办?该目录文件基本上都是代码,备份还是6个月之前的,当初偷懒还直接在线上改过这个目录代码!!!!跑路吧!!!😂,说笑了,跑路不存在的,就算跑路也得修复这个问题呀!经过2天终于解决了。为了防止这种事情发生!尤其是线上服务器!是时候给他增加一个回收站功能了!开源项目网上介绍的方式很多,这个给大家推荐一个开源的项目!https://github.com/andreafrancia/trash-cli/部署安装简单方法要求:Python 3 (Python 2.7 也可以) pip (在 Debian 上用 apt-get install python-pip 来安装 pip)安装命令:pip install trash-cli源码安装为所有用户安装:git clone https://github.com/andreafrancia/trash-cli.git cd trash-cli sudo pip install .为当前用户安装:git clone https://github.com/andreafrancia/trash-cli.git cd trash-cli pip install .为当前用户安装后你可能需要把以下代码添加到 .bashrc:export PATH=~/.local/bin:"$PATH"卸载命令:pip uninstall trash-cli使用方法trash-put 把文件或目录移动到回收站 trash-empty 清空回收站 trash-list 列出回收站文件 trash-restore 恢复回收站文件 trash-rm 删除回收站文件移动文件到回收站:$ trash-put列出回收站文件:$ trash-list 2008-06-01 10:30:48 /home/andrea/bar 2008-06-02 21:50:41 /home/andrea/bar 2008-06-23 21:50:49 /home/andrea/foo搜索回收站文件:$ trash-list | grep foo 2007-08-30 12:36:00 /home/andrea/foo 2007-08-30 12:39:41 /home/andrea/foo恢复回收站文件:$ trash-restore 0 2007-08-30 12:36:00 /home/andrea/foo 1 2007-08-30 12:39:41 /home/andrea/bar 2 2007-08-30 12:39:41 /home/andrea/bar2 3 2007-08-30 12:39:41 /home/andrea/foo2 4 2007-08-30 12:39:41 /home/andrea/foo What file to restore [0..4]: 4 $ ls foo foo删除所有回收站文件:$ trash-empty删除回收站中 n 天前被回收的文件:$ trash-empty <days>示例:$ date Tue Feb 19 20:26:52 CET 2008 $ trash-list 2008-02-19 20:11:34 /home/einar/today 2008-02-18 20:11:34 /home/einar/yesterday 2008-02-10 20:11:34 /home/einar/last_week $ trash-empty 7 $ trash-list 2008-02-19 20:11:34 /home/einar/today 2008-02-18 20:11:34 /home/einar/yesterday $ trash-empty 1 $ trash-list 2008-02-19 20:11:34 /home/einar/today只删除符合某种模式的文件:$ trash-rm \*.o注意:要用双引号圈住模式来避免 shell 拓展。 定时清空回收站,可以利用crontab来实现下面命令每天0点清空回收站3天前的内容0 0 * * * trash-empty 3常见问题如何创建顶级 .Trash 目录? 步骤:sudo mkdir --parent /.Trash sudo chmod a+rw /.Trash sudo chmod +t /.Trash我能把 rm 的别名设置为 trash-put 吗? 可以,但不应该这样做。以前我觉得这是个好主意,但现在我不觉得。虽然 trash-put 的界面看起来与 rm 兼容,但它们有不同的语法,这些差异会导致一些问题。比如,用 rm 删除目录时需要 -R,trash-put 则不需要。但有时候我忘记用 trash-put 了,真的不能给 rm 设置别名吗? 你可以给 rm 设置一个别名来提醒你不要使用它:alias rm='echo "This is not the command you are looking for."; false'如果你真的要用 rm,那就在 rm 前加上斜杠来取消别名:\rm file-without-hope注意,Bash 别名是有在交互式界面才有效,所以使用这个别名不会影响使用 rm 的脚本。被移动到回收站的文件在哪? 从 home 分区移动到回收站的文件在这:~/.local/share/Trash/出现错误博主在 CentOS7 安装时出现了一个错误Processing /root/trash-cli Collecting psutil (from trash-cli==0.21.7.24) Using cached https://pypi.tuna.tsinghua.edu.cn/packages/e1/b0/7276de53321c12981717490516b7e612364f2cb372ee8901bd4a66a000d7/psutil-5.8.0.tar.gz Complete output from command python setup.py egg_info: /usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires' warnings.warn(msg) /usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'long_description_content_type' warnings.warn(msg) error in psutil setup command: 'extras_require' must be a dictionary whose values are strings or lists of strings containing valid project/version requirement specifiers. ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-n6gexX/psutil/ You are using pip version 8.1.2, however version 21.2.3 is available. You should consider upgrading via the 'pip install --upgrade pip' command.后来发现 psutil 版本的问题,执行安装旧版本即可!pip install psutil==5.7.0最后说明当然还有好多其他的解决方案。比如用alias !alias rm='rm -i'下面是我目前使用的alias,希望对大家有所帮助吧!alias rm='echo "This is not the command you are looking for."; false' alias ls='ls --show-control-chars -F --color=auto' alias ll='ls -hl' alias la='ls -a' alias cp='cp -i' alias mv='mv -i' alias less='less -R' alias cat='ccat' alias diff='colordiff' alias grep='grep --color=auto' alias egrep='egrep --color=auto'
2021年08月11日
52 阅读
0 评论
0 点赞