zoukankan      html  css  js  c++  java
  • linux下防止文件误删除的工具

    linux系统下是没有回收站的,删除的文件或者目录默认是永远也找不回来的,因此,我们需要自己建立一个'回收站',来暂时存放删除的文件

    #编辑文件
    [root@hass-11 ~]# vim /etc/profile.d/trash.sh
    #!/bin/bash
    movetotrash(){
    if [ "$1" != "" ];then
    	mv $@ /.trash/
    else
    	echo "command:rm filename ..."
    fi
    }
    
    recoveryfile(){
    if [ "$1" != "" ];then
    	path=`pwd`
    	cd /.trash/
    	mv -i $@ $path
    	cd - >/dev/null 2>&1
    else
    	echo "command:ur filename ..."
    fi
    }
    
    #创建目录
    mkdir /.trash
    #命令行执行
    bash /etc/profile.sh/trash.sh
    #在家目录下的.bashrc目录下添加以下内容
    [root@hass-11 ~]# vim ~/.bashrc
    ...
    alias rm=movetotrash
    alias re=recoveryfile
    alias rl="ls /.trash"
    #命令行执行
    [root@hass-11 ~]# source ~/.bashrc
    
    #验证
    [root@hass-11 ~]# ll
    total 100
    -rw-r--r-- 1 root root    48 Sep  2 14:00 c.txt
    -rw-r--r-- 1 root root    48 Sep  2 14:53 d.txt
    [root@hass-11 ~]# rm c.txt d.txt 
    [root@hass-11 ~]# rl
    c.txt  d.txt
    [root@hass-11 ~]# re c.txt d.txt
    [root@hass-11 ~]# ll
    total 100
    -rw-r--r-- 1 root root    48 Sep  2 14:00 c.txt
    -rw-r--r-- 1 root root    48 Sep  2 14:53 d.txt
    
    
  • 相关阅读:
    java常见面试题汇总(一)
    我的自学之路:java学习路线图分享
    bzoj3714 [PA2014]Kuglarz
    cf478D Red-Green Towers
    cf478C Table Decorations
    cf478B Random Teams
    cf479A Expression
    cf479C Exams
    cf479D Long Jumps
    cf479E Riding in a Lift
  • 原文地址:https://www.cnblogs.com/syy1757528181/p/13615200.html
Copyright © 2011-2022 走看看