这个脚本随机删除系统一半文件,运维必备!

杰哥的IT之旅

共 1484字,需浏览 3分钟

 · 2020-01-14



来自:开源最前线(ID:OpenSourceTop)

2019年,钢铁侠死了,美队老了,雷神胖了。这一切,都是因为那个叫 Thanos 的坏蛋!于是,就有程序员写了一个开源的灭霸命令,可随机删除电脑上一半文件。


79c7a662d4cb2fec507745f13e7dd514.webp


关于这个项目,创建者温馨提示:请不要在家里或其他地方使用。这是真家伙,要小心…毕竟这是没有撤销键的


2c5541d97afc7ec7a135213ccd0dc039.webp


目前这个项目已经在GitHub上标星1.8K235个Fork(GitHub地址:https://github.com/hotvulcan/Thanos.sh/


该命令支持mac系统,但是需要使用到gshuf命令,需要通过brew安装,安装命令如下:


#安装brew
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    #安装gshuf
    brew install coreutils


此脚本只会列出当前目录一半的文件。


完整脚本如下:


#!/bin/sh
let "i=`find . -type f | wc -l`/2";
if [[ uname=="Darwin" ]]; then
    find . -not -name "Thanos.sh" -type f -print0 | gshuf -z -n $i | xargs -0  -- cat;
else
    find . -not -name "Thanos.sh" -type f -print0 | shuf -z -n $i | xargs -0  -- cat;
fi
# Explanation
## Step 1: Get the count of files in current path divided by two.
## Step 2: Get all the files in current path and print in one line.
## Step 3: Turn half of the second step output into standard input randomly.
## Step 4: Show half of the files in terminal.

# Key Point
## If you want to make delete, what you need to do is turn 'cat' into 'rm'.


该脚本使用 find / -type f | wc -l 获取了根目录下所有文件的数量,再除以2将结果赋予给变量 i,使用 find 命令找到根目录下所有文件,shuf 输出根目录下所有文件的一半,通过 xargs 传参,再使用rm命令进行删除操作。


好了,能给的都给你们了,哪天看你们产品经理可以试看看,试玩别忘了告诉我后果是什么,毕竟本脚本功效未经测试,后果有待考证。


本公众号全部博文已整理成一个目录,请在公众号后台回复「m」获取!

推荐阅读

9972747388dc23b1de9be2206c401f97.webp你点的每个[在看],都是对杰哥最大的支持!
浏览 9
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报