shell脚本只删除一个目录下的文件,或只删除一个目录下的文件夹
参考链接:
https://www.cnblogs.com/mingyue605/p/10704108.html
#!/bin/sh RM="rm -rf" function delete_all_dir() { for i in `ls` do if [ -d $i ];then $RM $i fi done } function delete_all_file() { for i in `ls` do if [ -f $i ];then $RM $i fi done } case $1 in f) delete_all_file ;; d) delete_all_dir ;; esac
用法:
删除文件夹 [root@192 Desktop]# ./test.sh d
删除文件 [root@192 Desktop]# ./test.sh f
本人亲测有效:
cd /***/jenkins/jenkins_home
for i in `ls`
do
if [ -d $i ];then
echo $i
fi
done