树莓派Debian Linux正则获取指定目录信息及清除无效挂载的历史遗留目录

xingyun86 2021-11-4 845

正则获取指定目录信息
sudo df -Th | grep -o "/media/pi/.*" | sed "s/\/media\/pi\///g"


清除无效挂载的历史遗留目录

for file in `ls /media/pi/ | tr " " "\?"`
	do
		file=`tr "\?" " " <<<$file`
		file_path=/media/pi"/"$file
		if [ -d "$file_path" ];then
			dst_path=""
			for mfile in `df -Th | grep -o "/media/pi/.*"`
				do
					if [ "$file_path" == "$mfile" ];then
						echo "$file_path"
						dst_path=$file_path
					fi
				done
			if [ -z "$dst_path" ];then
            	if [ -n "$file_path" ];then
					echo "rm $file_path"
					rm -rf "$file_path"
				fi
			fi
		fi
	done


×
打赏作者
最新回复 (0)
查看全部
全部楼主
返回