日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > linux >内容正文

linux

linux centos 回收站,centos rm 回收站

發(fā)布時(shí)間:2024/10/8 linux 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux centos 回收站,centos rm 回收站 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

桌面版本的linux就默認(rèn)有,非桌面版本貌似沒(méi)(反正我沒(méi)找到)

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

修改root用戶(hù)的環(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 {} ;

如果Linux除了root用戶(hù),還有其他用戶(hù)需要登陸服務(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)建普通用戶(hù)測(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ě)。

總結(jié)

以上是生活随笔為你收集整理的linux centos 回收站,centos rm 回收站的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。