使用shell脚本删除当前目录下.c文件对应的可执行文件
2016-03-04 00:45
851 查看
将下面一段程序保存为:rm_tg.sh,并修改它的执行权限:chmod +x rm_tg.sh,然后执行:./rm_tg.sh
就可以删除当前目录下.c文件对应的可执行文件
#!/bin/sh
# 删除当前目录下.c对应的可执行文件
# 文件逐行处理
# 获取.c文件对应的可执行文件
ls | grep .c | sed -e 's/.c//g' > temp_file
# 逐行处理,判断文件是否存在
cat temp_file | while read line;do
# 存在则删除文件
if test -f $line;then
echo "rm $line"
rm -f $line
else
echo "no $line"
fi
done
就可以删除当前目录下.c文件对应的可执行文件
#!/bin/sh
# 删除当前目录下.c对应的可执行文件
# 文件逐行处理
# 获取.c文件对应的可执行文件
ls | grep .c | sed -e 's/.c//g' > temp_file
# 逐行处理,判断文件是否存在
cat temp_file | while read line;do
# 存在则删除文件
if test -f $line;then
echo "rm $line"
rm -f $line
else
echo "no $line"
fi
done
相关文章推荐
- UNIX shell -- trick and experience (20090423)
- 使用shell脚本比较两个浮点数
- sed 获取shell变量和branch(b)分支的用法
- linux第4天 shell socket
- 51nod 1066 Bash游戏
- Shell脚本中赋值变量时单引号‘和双引号“的区别
- linux shell中单引号、双引号、反引号、反斜杠的区别
- pod install -bash: pod: command not found的解决办法
- shell 控制输出格式 echo printf
- 编程学习第一天,python,powershell
- how to clear screen in python shell
- 利用gitbash上传项目到github
- linux shell 编程笔记 - 后台执行命令crontab
- VNC 登录上去灰屏,没有shell脚本,鼠标变成X
- VNC 登录上去灰屏,没有shell脚本,鼠标变成X
- Linux shell的标准输入、输出和错误
- 利用shell批量更改文件后缀名
- printf 遇到bash重定向
- 使用deb-src包重新编译bash使之能够输出日志到rsyslog的local1
- [备忘][转]使用crontab,让linux定时执行shell脚本