假设我想复制目录的内容,不包括名称中包含"音乐"一词的文件和文件夹.
cp [exclude-matches] *Music* /target_directory
Run Code Online (Sandbox Code Playgroud)
什么应该代替[exclude-matches]来实现这个目标?
以下是如何列出与bash中的模式匹配的所有文件:
ls *.jar
Run Code Online (Sandbox Code Playgroud)
如何列出模式的补充?即所有文件都不匹配*.jar?
Using the pattern match !("file1") does not work within a bash script but will work on the command line.
For example:
ls !("file1"|"file2")
Run Code Online (Sandbox Code Playgroud)
This will list all files in directory except file1 and file2.
When that line is executed in a script this error is displayed:
./script.sh: line 1: syntax error near unexpected token `('
./script.sh: line 1: ` ls !("file1"|"file2") '
Run Code Online (Sandbox Code Playgroud)
Regardless what is used rm -v !("file1"). The same error takes place. What is going on …