[英]move files that no not contain specific string
I would like to move files using mv
that do not contain the letter S
in the filename. 我想使用
mv
移动文件名中不包含字母S
的文件。 Could not find anyhting in the mv manual. 在mv手册中找不到任何内容。 Maybe combination with
find
or grep
? 也许与
find
或grep
相结合? It has to be case-sensitive. 它必须区分大小写。
input: 输入:
file1
fileS1
file2
fileS2
file to move: 要移动的文件:
file1
file2
You can do the selection in pure Bash without any extra software, if you enable extended globbing , which is off by default: 如果启用了Extended Globbing ,则可以在纯Bash中进行选择,而无需任何其他软件,默认情况下该功能处于关闭状态:
shopt -s extglob
mv !(*S*) /target/dir
For more information, search for extglob
in the bash(1)
manual page (the info is at the second match). 有关更多信息,
extglob
在bash(1)
手册页中搜索extglob
(信息位于第二个匹配项)。
You can use find
with the -not
flag for example. 例如,您可以将
find
与-not
标志一起使用。
find /path/to/source/dir -type f -not -name '*S*' \
| xargs mv -t /path/to/target/dir
您还可以使用ls
的Ignore-pattern开关,例如:
mv $(ls -I '*S*') /target/dir
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.