linux - 当文件 xz 存在时,删除所有 xy 形式的文件
问题描述
我想删除所有名为foo .o 的文件,仅当存在相应的foo .asm 文件时,对于所有foo。
我可以用这样的for
循环来做到这一点:
for asmfile in *.asm; do
prefix=${asmfile%".asm"}
echo "Processing $asmfile ($prefix)"
rm -f "${prefix}.o"
done
...但是 bash 中是否有一些不那么尴尬或更惯用的东西?
解决方案
您可以这样做来获取前缀:
PREFIX=`basename $ASMFILE .asm`
推荐阅读
- gitkraken - 在 GitKraken 中提交。使摘要成为必填项
- ansible - anislble with_items with_nested 在角色任务内的循环中
- ios - 快速从一个模态 VC 转换到另一个模态 VC
- github - 如何向我只有他的电子邮件的人发送拉取请求
- c# - 尽管有全局范围,但 Unity 刚体拒绝存在
- css - SquareSpace 的 SASS Escape Calc
- microservices - 使用 Ribbon 和 Hystrix 自定义重试行为
- javascript - HTML5 视频的自定义控件不起作用
- c# - 如何使用 C# 调用队列客户端 sendasync 方法
- regex - 正则表达式捕获:和@