加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

安全的rm

发布时间:2020-12-15 07:13:52 所属栏目:安全 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 ### by 3haku.netfunction saferm() {ops_array=($*)if [[ -z $1 ]] ;thenecho 'Missing Args'returnfiJ=0offset=0# for zshif [[ -z ${ops_array[0]}

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

### by 3haku.net
function saferm() {
	ops_array=($*)
	if [[ -z $1 ]] ;then
		echo 'Missing Args'
		return
	fi
	J=0
	offset=0
	# for zsh
	if [[ -z ${ops_array[0]} ]] ; then
		offset=1
	fi
	while [[ $J -lt $# ]] ; do
		  p_posi=$(($J + $offset))
		  dst_name=${ops_array[$p_posi]}
		  if [[ `echo ${dst_name} | cut -c 1` == '-' ]] ; then
			    continue
		  fi
    	# garbage collect
    	now=$(date +%s)
    	for s in $(ls --indicator-style=none $HOME/.trash/) ;do
        	dir_name=${s//_/-}
        	dir_time=$(date +%s -d $dir_name)
        	# if big than one month then delete
        	if [[ 0 -eq dir_time || $(($now - $dir_time)) -gt 2592000 ]] ;then
            	echo "Trash " $dir_name " has Gone "
           		/bin/rm $HOME/.trash/$dir_name -rf
        	fi
    	done
    
    	# add new folder
    	prefix=$(date +%Y_%m_%d)
    	hour=$(date +%H)
 	    mkdir -p $HOME/.trash/$prefix/$hour
    	echo "Trashing " $dst_name
    	mv ./$dst_name $HOME/.trash/$prefix/$hour
		  J=$(($J+1))
	done
}

alias rm=saferm

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读