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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

rm命令改为移动到回收站

發(fā)布時間:2023/12/20 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 rm命令改为移动到回收站 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

環(huán)境:

Ubuntu16.04 64位有效

ubuntu18.10下面無效(18.10的在文末補(bǔ)充)

xfce4

rm.sh來自:

https://github.com/a14m/rm/blob/master/rm.sh

具體代碼如下:

#!/bin/bash# VARIABLES VERSION="0.3" TO_DELETE=() RECURSIVE=false FOREVER=false VERBOSE=false# FUNCTIONS function show_help() {echo -e ""echo -e "This is custom script used to avoid deleting files forever"echo -e "instead files will be moved to $HOME/.Trash folder"echo -e "and this script only works if you invoked it directly from the terminal"echo -e "it doesn't work if for example git used rm or if you used rm in other scripts"echo -e ""echo -e "usage: rm [OPTION]...FILE..."echo -e "Move FILE(s) to $HOME/.Trash folder"echo -e ""echo -e "Options:"echo -e " -h, --help \t\tdisplay this help text and exit."echo -e " --version \t\toutput version information and exit."echo -e " -r, -R, --recursive,\tmove the directories and their content to the Trash folder."echo -e " -f, --forever,\tremove the directories and their content to the Trash folder."echo -e " \tuse this to delete files or empty trash it calls the /bin/rm"echo -e ""echo -e ""echo -e "Script source 'https://github.com/artmees/rm'"echo -e "github page 'https://artmees.github.io/rm'"echo -e ""echo -e "Install :"echo -e " sudo cp rm.sh /usr/local/bin/rm"echo -e "Uninstall :"echo -e " sudo rm /usr/local/bin/rm"echo -e ""echo -e "you need to restart the termial for this to work"echo -e "or you can use source ~/.bashrc or source ~/.bash_profile"echo -e ""echo -e "Use Old rm :"echo -e " /bin/rm"exit 0 }function check_flags() {# check the flags user usedif [ $# -le 0 ];thenshow_helpfiwhile test $# -gt 0; docase "$1" in-h|--help) show_help;;-r|-R|--recursive)shiftRECURSIVE=true;;-f|--forever)shiftFOREVER=true;;--version)echo -e "$VERSION"exit 0;;-v|--verbose)shiftVERBOSE=true;;-a|-b|-c|-d|-e|-g|-h|-i|-j|-k|-l|-m|-n|-o|-p|-q|-s|-t|-u|-w|-x|-y|-z|-A|-B|-C|-D|-E|-F|-G|-H|-I|-J|-K|-L|-M|-N|-O|-P|-Q|-S|-T|-U|-V|-W|-X|-Y|-Z)echo -e ""echo -e "Invalid Argument"show_help;;*)get_to_delete $1shift;;esacdone }# Helper method to populate the TO_DELETE array function get_to_delete() {while test $# -gt 0; doTO_DELETE=("${TO_DELETE[@]}" $1)shiftdone }function check_trash_directory() {# check that global system trash exists# if not create itif [ ! -d ~/.Trash/ ];thenmkdir ~/.Trashfi# check the files and flags passedcheck_flags $@if $FOREVER ;then# use the common system rm -r passing the same argumentsif $VERBOSE ;thenecho -e "`/bin/rm -r -v ${TO_DELETE[@]}`"else/bin/rm -r ${TO_DELETE[@]}fielsemove_to_trashfiexit 0 }# Move the deleted files to the trash # show output if -V option was specified function move_to_trash() {for i in "${TO_DELETE[@]}";doFILENAME=$iFILENAME+="_"FILENAME+=$(date +"%H_%M_%S")if [ -d $i ] && $RECURSIVE ;thenif $VERBOSE ;thenecho -e "`mv -v $i ~/.Trash/$FILENAME`"elsemv $i ~/.Trash/$FILENAMEfielif [ -d $i ] ;thenecho -e "$i is a directory please use --recursive to remove directories and their content"elif [ -f $i ] ;thenif $VERBOSE ;thenecho -e "`mv -v $i ~/.Trash/$FILENAME`"elsemv $i ~/.Trash/$FILENAMEfielse# TODO add other option similar to rm -f to not output this errorecho -e "No such file or directory '$i'"fidone }# Refer to http://stackoverflow.com/questions/20572934/get-the-name-of-the-caller-script-in-bash-script # to understand the next funtion # usage: determine if the script was invoked by a user or other script # if it was invoked by other scripts then use the system rm instead # to avoid messing with other scripts behaviour. function check_invoker() {PARENT_COMMAND=$(ps $PPID | tail -n 1 | awk "{print \$5}")if [ $PARENT_COMMAND == '-bash' ]; thencheck_trash_directory $@else/bin/rm $@exit 0fi }# Main check_invoker $@ exit 0

?

root權(quán)限下:

cp rm.sh?/usr/bin

chmod u+x /usr/bin/rm.sh

chmod 777 /usr/bin/rm.sh

?

$HOME/.bashrc中加入下面一句

alias rm=/usr/bin/rm.sh

效果如下:

rm rm.sh

(python2.7) appleyuchi@ubuntu:~/.Trash$ ls
rm.sh_16_13_38

?

?

?

###################################################################################

下面方法在18.10和20.04測試通過

第一步:

#安裝trash-cli工具,其實(shí)就是回收站的命令行模式:? ? ? ? ? ? ?

$ sudo apt-get install trash-cli

?


第二步:
#給trash命令添加別名”rm”,覆蓋系統(tǒng)rm命令? ? ? ? ? ??

$ vi ~/.bashrc

#在最后一行加入:

alias rm="trash"

?#保存并退出? ? ? ? ? ??

$ source ~/.profile

?

以后不必刪文件夾時加參數(shù) -r 直接使用 rm file or ?rm filedirectory

刪除文件或文件夾,且刪除后,它就會自動跑去回收站了!

?

總結(jié)

以上是生活随笔為你收集整理的rm命令改为移动到回收站的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 亚洲AV无码成人精品国产一区 | 亚洲成人激情在线 | 成人a毛片久久免费播放 | 久久精品中文闷骚内射 | 国产日韩欧美激情 | 国产精品电影在线观看 | 农村妇女愉情三级 | 久久亚洲一区 | 老妇荒淫牲艳史 | sm捆绑调教视频 | 国产成人精品一区二区色戒 | 日韩av福利| japanese24hdxxxx中文字幕 | 国产欧美日韩在线视频 | 国产精品国产三级国产aⅴ无密码 | 国产成人久久精品 | 久久国产精品久久 | 成人看片泡妞 | 中文字幕2021 | 草草视频在线播放 | 夜夜草网 | 韩国av中文字幕 | 国产精品久久国产精麻豆96堂 | 天降女子在线观看 | 婷婷色五 | 天天躁狠狠躁 | 综合激情亚洲 | 中文字幕欧美日韩 | www夜插内射视频网站 | 逼特逼在线视频 | 国产青青 | 在线a视频 | 亚洲综合免费观看高清完整版 | 欧美色狠 | 亚洲一区二区三区四区五区xx | 久草福利在线观看 | 在线观看亚洲色图 | 亚洲精品视屏 | wwwxx在线 | 欧美精品在线观看视频 | 美女露出粉嫩尿囗让男人桶 | 日韩av在线天堂 | 小泽玛利亚一区二区三区 | 国产一区二区视频免费观看 | 欧美精品亚洲精品 | 苍井空浴缸大战猛男120分钟 | 午夜精品网 | 女人下边被添全过视频 | 国产精品网站在线观看 | 91亚洲精品国偷拍自产在线观看 | 黄色网络在线观看 | 手机在线看a| www,久久久 | 中国av在线 | 蜜乳av 懂色av 粉嫩av | 亚洲AV无码一区二区三区蜜桃 | 亚洲男人的天堂av | 在线免费观看黄视频 | 日韩免费影视 | 97精品国产97久久久久久粉红 | 91丨porny丨首页 | 亚洲国产精品成人综合色在线婷婷 | 色七七网站| 日韩精品一区二区av | 国产99久久久国产精品 | 国产成人免费看一级大黄 | 爱如潮水3免费观看日本高清 | 在线观看黄色片网站 | 另类小说久久 | 久久久久亚洲AV | 日韩不卡av在线 | 肥臀熟女一区二区三区 | 99re免费视频精品全部 | 精品精品视频 | 久久精品8 | 天堂av亚洲av国产av电影 | 国产成年人 | 欧美大片免费 | 天堂在线中文资源 | 男人的天堂免费 | 四虎在线观看 | 97caoporn| a级片免费播放 | 欧美一级特黄aaaaaa大片在线观看 | 欧美不卡视频 | 免费无毒av | 久久久香蕉视频 | 懂色av一区二区三区在线播放 | 色欧美88888久久久久久影院 | 欧美第一网站 | 波多野结衣高清视频 | 你懂的视频在线播放 | 在线观看免费视频黄 | 亲嘴脱内衣内裤 | 奇米影视狠狠 | 国产5区| 双乳被四个男人吃奶h文 | 宇都宫紫苑在线播放 | 自拍偷拍精品视频 |