shell脚本编程实践——指定某个目录删除文件
通常,在linux系统中我们需要经常删除一些临时文件或者垃圾文件,如果我们通过手动一个文件一个文件的删除那会相当麻烦。
最近也正在学习shell脚本编程,因此自己试着写了一个用来指定目录删除文件的应用。
该脚本的功能是:
首先指定要删除的文件所在的目录;然后选择要删除的方式,是指定确切的文件名或者是指定模糊删除抑或是删除所有的文件。
下面是写的shell代码
#!/bin/bash
read -p "please input the dir which you want to del file in:" dir
echo -e "select type:\n p--precis\n r--reg\n a--all"
read identify
if [ $identify == 'p' ]; then
read -p "please input filename" files
elif [ $identify == 'r' ]; then
read -p "please input reg:" reg
files=`ls ${dir}/${reg}* `
elif [ $identify == 'a' ]; then
files=`ls ${dir}`
else
exit 0
fi
for file in $files
do
if [ -e ${file} ]; then
rm -f $file
fi
done
转载请发邮件至 1244347461@qq.com 进行申请,经作者同意之后,转载请以链接形式注明出处
本文地址:
相关文章
发布时间:2024/03/15 浏览次数:358 分类:编程语言
-
本教程说明了从 powershell 脚本运行 bat 文件的不同方法。
解决 linux bash 中的 nodemon 命令未找到错误
发布时间:2024/03/14 浏览次数:223 分类:操作系统
-
本文介绍如何解决 linux bash 中的 nodemon command not found 错误。
解决 linux bash 中的 make command not found 错误
发布时间:2024/03/14 浏览次数:246 分类:操作系统
-
本文介绍如何解决 linux bash 中的 make command not found 错误。
解决 linux bash 中 syntax error near unexpected token newline 错误
发布时间:2024/03/14 浏览次数:408 分类:操作系统
-
本文介绍如何解决 linux bash 中 syntax error near unexpected token newline 错误。