使用shell脚本删除当前目录下.c文件对应的可执行文件

2119阅读 0评论2009-10-16 ericxlin
分类:

将下面一段程序保存为: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
 
上一篇:使用Shell脚本编译.c源文件
下一篇:vmware installtion and configuration for linux