我正在使用macOS,创建一个Bash脚本。
我将这些文件放在某个/path/to/inc/文件夹中:
./lorem-ipsum.php
./dolor-sit.amet.php
./config-prod.php
./enqueue.php
./config.php
./setup.php
./config-uat.php
./config-some-other-thing.php
Run Code Online (Sandbox Code Playgroud)
现在,我想有这些文件config*.php的名称,并删除他们除了命名一个config-prod.php,所以该文件夹最终看起来是这样的:
./lorem-ipsum.php
./dolor-sit.amet.php #Still here
./config-prod.php
./enqueue.php
./config.php #Removed
./setup.php
./config-uat.php #Removed
./config-some-other-thing.php #Removed
Run Code Online (Sandbox Code Playgroud)
有什么办法可以使用find或类似的方法吗?
您可以使用扩展的glob:
$ shopt -s extglob
$ echo config!(-prod).php
config-some-other-thing.php config-uat.php config.php
Run Code Online (Sandbox Code Playgroud)
然后删除文件
rm config!(-prod).php
Run Code Online (Sandbox Code Playgroud)
!(pattern)匹配所有,但pattern。
| 归档时间: |
|
| 查看次数: |
48 次 |
| 最近记录: |