linux - 我想通过 shell 删除所有文件,除了少数 as 但导致语法错误:“(”意外
问题描述
rm -rf * ! ( "update.sh" | "new_update" ) #or
rm -rf ! ( "update.sh" | "new_update" ) #or
rm -rf ! ( update.sh | new_update ) #or
我想删除所有文件,除了update.sh
和new_update
我已经厌倦了shell脚本中的所有行,但返回错误
意外的标记 (
当直接在终端上运行时,有时会执行,有时会出现与上述相同的错误
解决方案
First, you have to enable extended globbing with
shopt -s extglob
Then you can't have spaces between the parts of the wildcard.
rm -rf !(update.sh|new_update)
推荐阅读
- powershell - 行中的额外字符
- eclipse - 很少有调试点在 Mac 的 Eclipse 中不起作用
- django - Django Profile 不使用 UserModel 保存其他字段
- c# - 尝试按列名获取值时无法将“String”转换为“int”
- php - 如何将 joomla 的日期格式更改为 d/m/Y?
- sql-server - 如何导出选择查询的消息部分(JARED ZAGELBAUM RESTORE for SQL Server Express)
- node.js - AWS Lambda 函数在控制台上测试时有效,但在 CloudWatch 事件触发时无效
- machine-learning - H2O AutoML 如何处理因子变量?
- javascript - 单击对象中最后一个图像之后的图像时,我将如何切换图像?
- c# - 文本框数据在 ddl 中反映两次