最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

CentOS增加系統(tǒng)回收站功能介紹

  發(fā)布時(shí)間:2017-01-23 11:15:57   作者:佚名   我要評(píng)論
linux rm刪除文件之后,恢復(fù)就比較麻煩了,即使恢復(fù)了,文件名格式都變成一串?dāng)?shù)字了。 今天小編將為大家?guī)?lái)的是CentOS增加系統(tǒng)回收站功能介紹 ;希望對(duì)大家會(huì)有幫助,有需要的朋友一起去看看吧

linux rm刪除文件之后,恢復(fù)就比較麻煩了,即使恢復(fù)了,文件名格式都變成一串?dāng)?shù)字了。

修改root用戶的環(huán)境變量

vi ~/.bashrc

注釋第5行的別名

#alias rm='rm -i'

最后一行添加如下內(nèi)容

mkdir -p ~/.trash

alias rm=trash

alias r=trash

alias rl='ls ~/.trash'

alias ur=undelfile

undelfile()

{

  mv -i ~/.trash/$@ ./

}

trash()

{

  mv $@ ~/.trash/

}

cleartrash()

{

    read -p "clear sure?[n]" confirm

    [ $confirm == 'y' ] || [ $confirm == 'Y' ]  && /bin/rm -rf ~/.trash/*

}

重新加載環(huán)境變量

source ~/.bashrc

使用命令ll -a查看目錄,發(fā)現(xiàn)多了目錄.trash,這個(gè)目錄是用來(lái)存在刪除的文件

drwxr-xr-x.  2 root root       4096 Jun  4 11:31 .trash

刪除一個(gè)文件

[root@localhost ~]# rm percona-xtrabackup_2.2.3.orig.tar.gz

查看目錄,發(fā)現(xiàn)刪除的文件在回收站目錄

[root@localhost ~]# ll .trash/

total 33780

-rw-r--r--. 1 root root 34584359 Jun  2 09:39 percona-xtrabackup_2.2.3.orig.tar.gz

如果需要清空回收站文件

使用以下命令

[root@localhost ~]# cleartrash

clear sure?[n]y

再次查看,發(fā)現(xiàn)空了。

[root@localhost ~]# ll .trash/

total 0

雖然rm用別名定義了,但是可以是用絕對(duì)路徑刪除文件

比如/bin/rm 1.txt

它是不會(huì)保存到.trash目錄的。

如果需要定義自動(dòng)清理7天刪除的文件

可以寫(xiě)一個(gè)腳本

#!/bin/bash

find /root/.trash -ctime 7 -type f -name "*" -exec /bin/rm {} \;

然后在任務(wù)計(jì)劃里面調(diào)用一下就可以了。

如果Linux除了root用戶,還有其他用戶需要登陸服務(wù)器,也想他們使用回收站機(jī)制

可以修改系統(tǒng)環(huán)境變量

vi /etc/profile

最后一行添加

mkdir -p ~/.trash

alias rm=trash

alias r=trash

alias rl='ls ~/.trash'

alias ur=undelfile

undelfile()

{

  mv -i ~/.trash/$@ ./

}

trash()

{

  mv $@ ~/.trash/

}

 

cleartrash()

{

    read -p "clear sure?[n]" confirm

    [ $confirm == 'y' ] || [ $confirm == 'Y' ]  && /bin/rm -rf ~/.trash/*

}

重新加載環(huán)境變量

source /etc/profile

創(chuàng)建普通用戶測(cè)試

useradd a

設(shè)置密碼

passwd a

登陸Linux

查看目錄,發(fā)現(xiàn)會(huì)創(chuàng)建.trash目錄

[a@localhost ~]$ ll -a

total 24

drwx------. 3 a    a    4096 Jun  4 11:45 .

drwxr-xr-x. 5 root root 4096 Jun  4 11:44 ..

-rw-r--r--. 1 a    a      18 Oct 16  2014 .bash_logout

-rw-r--r--. 1 a    a     176 Oct 16  2014 .bash_profile

-rw-r--r--. 1 a    a     124 Oct 16  2014 .bashrc

drwxrwxr-x. 2 a    a    4096 Jun  4 11:45 .trash

創(chuàng)建一個(gè)空文件

[a@localhost ~]$ touch 1.txt

刪除文件

[a@localhost ~]$ rm 1.txt

查看回收站目錄,發(fā)現(xiàn)多了一個(gè)文件

[a@localhost ~]$ ll .trash/

total 0

-rw-rw-r--. 1 a a 0 Jun  4 11:45 1.txt

如果對(duì).trash目錄位置覺(jué)得不爽,可以修改環(huán)境變量,改成其他位置,注意保證目錄可寫(xiě)。

相關(guān)文章

最新評(píng)論

天长市| 自贡市| 上栗县| 三台县| 九龙坡区| 平安县| 馆陶县| 久治县| 临夏县| 新密市| 阿拉善盟| 吴旗县| 满城县| 忻州市| 蓬安县| 武安市| 铜鼓县| 开江县| 青海省| 新巴尔虎左旗| 轮台县| 友谊县| 辉县市| 沅江市| 乌兰县| 云南省| 三亚市| 五大连池市| 吴堡县| 桐梓县| 甘孜县| 茌平县| 安阳县| 乌鲁木齐县| 浦县| 邵东县| 灵宝市| 漾濞| 措美县| 东阿县| 巫溪县|