濮阳杆衣贸易有限公司

主頁 > 知識庫 > CentOS增加系統(tǒng)回收站功能介紹

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

熱門標(biāo)簽:北京大興區(qū)地圖標(biāo)注中心 北京外呼系統(tǒng)官網(wǎng) AI智能語音外呼系統(tǒng)是什么 新鄉(xiāng)智能電話機(jī)器人有用嗎 荊門真人語音電話機(jī)器人哪個好 海外文化宮地圖標(biāo)注 淮安人工外呼系統(tǒng) 浙江虛擬外呼系統(tǒng)費(fèi)用 ai外呼系統(tǒng)定制

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,這個目錄是用來存在刪除的文件

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

刪除一個文件

[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用別名定義了,但是可以是用絕對路徑刪除文件

比如/bin/rm 1.txt

它是不會保存到.trash目錄的。

如果需要定義自動清理7天刪除的文件

可以寫一個腳本

#!/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)建普通用戶測試

useradd a

設(shè)置密碼

passwd a

登陸Linux

查看目錄,發(fā)現(xiàn)會創(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)建一個空文件

[a@localhost ~]$ touch 1.txt

刪除文件

[a@localhost ~]$ rm 1.txt

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

[a@localhost ~]$ ll .trash/

total 0

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

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

標(biāo)簽:亳州 蚌埠 南通 贛州 阿里 梅州 安陽 盤錦

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《CentOS增加系統(tǒng)回收站功能介紹》,本文關(guān)鍵詞  CentOS,增加,系統(tǒng),回收站,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《CentOS增加系統(tǒng)回收站功能介紹》相關(guān)的同類信息!
  • 本頁收集關(guān)于CentOS增加系統(tǒng)回收站功能介紹的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    台东县| 霍城县| 凯里市| 中宁县| 安徽省| 宿松县| 克什克腾旗| 呈贡县| 柳江县| 杭州市| 南投市| 库车县| 普定县| 栖霞市| 仁寿县| 运城市| 双鸭山市| 辉县市| 宁南县| 新源县| 崇礼县| 东乌珠穆沁旗| 兴文县| 会宁县| 本溪| 长治市| 多伦县| 财经| 贵定县| 阿克陶县| 湘西| 桂东县| 福安市| 运城市| 宜章县| 鄂伦春自治旗| 大安市| 长顺县| 马公市| 凤台县| 马鞍山市|