首页 > 解决方案 > 我想通过 shell 删除所有文件,除了少数 as 但导致语法错误:“(”意外

问题描述

rm -rf  * ! ( "update.sh" | "new_update"  )    #or


rm -rf   ! ( "update.sh" | "new_update"  )     #or


rm -rf   ! ( update.sh | new_update  )         #or

我想删除所有文件,除了update.shnew_update

我已经厌倦了shell脚本中的所有行,但返回错误

意外的标记 (

当直接在终端上运行时,有时会执行,有时会出现与上述相同的错误

标签: linuxbashshellubuntu

解决方案


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)

推荐阅读