美文网首页
在CentOS中构建一个“垃圾桶”

在CentOS中构建一个“垃圾桶”

作者: 得Y人终老 | 来源:发表于2019-07-11 16:50 被阅读0次

    人类犯错误是因为我们不是一台电脑,所以在使用rm命令时要额外注意,不要在任何时候使用rm -rf*当你使用rm命令时,它会永久删除文件,不会像文件管理器那样将这些文件移动到“垃圾桶”。

    将文件移动到“垃圾桶”是一个好注意,当你无意中运行rm命令时,可以拯救你;但是很少有人会说这是一个坏习惯,如果你不注意“垃圾桶”,他可能会在一定的时间内被文件和文件夹堆积起来。在这种情况下,我建议你按照你的意愿去做一个定时任务

    执行以下命令开始构建“rm”的垃圾桶:
    # 下载GitHub上的垃圾桶项目,并把程序添加至系统级
    yum -y install git
    git clone https://github.com/yevhao
    mv yevhao/scripts/saferm.sh /usr/bin
    # 设置“rm”的别名为 saferm.sh <在文件末尾添加>
    vim .bashrc
    alias rm='saferm.sh'
    # 执行以下命令使别名生效
    source .bashrc
    # 创建一个文件
    touch test_file
    # 利用“rm”删除test_file
    rm -rf test_file
    Moving test_file to /root/Trash
    # 进入/root/Trash目录中,并查看其中是存在test_file文件
    cd /root/Trash
    ls
    test_file
    # 安全删除test_file文件
    pwd
    /root/Trash
    rm -rf test_file
    Moving test_file to /root/Trash
    mv: "tset_file" 与 “/root/Trash/test_file”为同一文件
    test_file could not be moved to trash. Unsafe delete (y/n)? <此时输入 y 即可>
    Deleting test_file
    # 此时查看目录,test_file就被删除了
    

    相关文章

      网友评论

          本文标题:在CentOS中构建一个“垃圾桶”

          本文链接:https://www.haomeiwen.com/subject/gbvdkctx.html