linux ls命令,rm命令linux00,Linux限制rm命令

 2023-09-23 阅读 19 评论 0

摘要:常规做法是新建一个垃圾目录,把删除的内容mv到这个目录,在定期清理这个目录。是一样的,我自己动基于alias写了个脚本来限制rm命令,有以下好处:只有一个脚本批量部署非常方便,不需求安装第三方软件每次删除时会提示删除的内容࿰

常规做法是新建一个垃圾目录,把删除的内容mv到这个目录,在定期清理这个目录。是一样的,我自己动基于alias写了个脚本来限制rm命令,有以下好处:

只有一个脚本批量部署非常方便,不需求安装第三方软件

每次删除时会提示删除的内容,删除是将要删除的文件mv到/tmp/.trash/当天日期下,同时会提示是否清理目录,相当于仔细检查

linux ls命令、限制删除内容:只允许删除文件和目录,对于特殊的软链接,设备等文件可以临时删除

其他功能懒得写了,使用方法将脚本丢到/etc/profile.d/即可。

#!/bin/bash

#author: will

rmdir命令可以删除非空目录吗,#website: https://www.52os.net

rm_cmd(){

arg_array=()

for var in $*

linux mkdir命令。do

if [ ! `echo "$var" |grep "^-"` ];then

arg_array+=("$var")

fi

rman命令,done

if [ "$#" -eq "0" ] ;then

echo -e "\e[00;32mYou Are Using Security \"rm\" command \e[00m"

return 0

linux查看文件命令?elif [ ${#arg_array[@]} -eq 0 ];then

echo -e "\e[00;32mYou Are Using Security \"rm\" command \e[00m"

return 0

fi

linux基本命令的使用、echo -e "\033[00;31mYou are going to DELETE: \033[00m"

list_array=()

for element in ${arg_array[@]}

do

linux有什么用,if [ -f $element ];then

echo FILE: $element

list_array+=("$element")

elif [ -d $element ];then

linux?echo DIR: $element

list_array+=("$element")

elif [ -S $element ];then

echo -e "\e[00;32mSOCKET: $element NOT Allow To Delete\e[00m"

linux rm命令详解,return 0

elif [ -p $element ];then

echo -e "\e[00;32mPIPE: $element NOT Allow To Delete\e[00m"

return 0

linux chown命令。elif [ -b $element ];then

echo -e "\e[00;32mBLOCK DEVICE: $element NOT Allow To Delete\e[00m"

return 0

elif [ -c $element ];then

rm命令删除目录下所有文件。echo -e "\e[00;32mCHARACTER DEVICE: $element NOT Allow To Delete\e[00m"

return 0

else

echo -e "\e[00;32mNOT Exist: $element \e[00m"

return 0

fi

done

read -n1 -p $'\033[00;31mAre you sure to DELETE [Y/N]? ' answer

case $answer in

Y | y)

echo -e "\n"

if [ ! -d "/tmp/.trash/`date -I`" ]; then

mkdir -p /tmp/.trash/`date -I`

chmod 777 /tmp/.trash/`date -I`

fi

for element in ${list_array[@]}

do

echo -e "Deleting $element to /tmp/.trash/`date -I`"

#/bin/rm --preserve-root -rf $element

mv $element /tmp/.trash/`date -I`

if [ $? -ne "0" ];then

echo -e "\nDeleted FAILED"

return 0

fi

done

echo -e "\nDeleted FINISHED"

read -n1 -p $'\033[00;31mFree Disk Space ? [Y/N]? ' fanswer

case $fanswer in

Y | y)

/bin/rm --preserve-root -rf /tmp/.trash/*

echo -e "\n"

;;

*)

echo -e "\nFree Disk Space SKIPED"

echo -e "\n"

;;

esac

;;

*)

echo -e "\nDelete SKIPED"

;;

esac

}

alias rm='rm_cmd $@'

alias grep='grep --color=auto'

alias cp='cp -i'

alias l.='ls -d .* --color=auto'

alias ll='ls -l --color=auto'

alias ls='ls --color=auto'

alias mv='mv -i'

alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/89079.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息