【发布时间】:2019-10-13 14:53:56
【问题描述】:
我想使用mv 移动文件名中不包含字母S 的文件。在 mv 手册中找不到任何内容。也许与find 或grep 结合使用?它必须区分大小写。
输入:
file1
fileS1
file2
fileS2
要移动的文件:
file1
file2
【问题讨论】:
我想使用mv 移动文件名中不包含字母S 的文件。在 mv 手册中找不到任何内容。也许与find 或grep 结合使用?它必须区分大小写。
输入:
file1
fileS1
file2
fileS2
要移动的文件:
file1
file2
【问题讨论】:
如果您启用 extended globbing,您可以在纯 Bash 中进行选择,而无需任何额外的软件,默认情况下它是关闭的:
shopt -s extglob
mv !(*S*) /target/dir
如需更多信息,请在bash(1) 手册页中搜索extglob(信息在第二个匹配项中)。
【讨论】:
您也可以使用ls 中的忽略模式开关,例如:
mv $(ls -I '*S*') /target/dir
【讨论】:
例如,您可以将find 与-not 标志一起使用。
find /path/to/source/dir -type f -not -name '*S*' \
| xargs mv -t /path/to/target/dir
【讨论】: