Lui*_*ipe 3 linux bash centos7 rhel7
我想chown在文件夹上递归运行,但我不想包含名为"ssl.cert.webmintmp.26599"或 的文件"ssl.cert.webmintmp.356849",因此我需要用通配符替换末尾的数字。而且该文件之前的文件夹应该是通配符,因为有几个不同的文件夹名称。
我尝试过运行:
sudo chown -R user:apache /home/ !({ssl.cert.**,**/ssl.cert.**})
Run Code Online (Sandbox Code Playgroud)
根据我对这个问题的发现,这是行不通的;(在 Linux 中执行文件操作(即 cp、mv、rm 和 chown 等)时如何排除文件夹)
当我遇到错误时;
./chowntest.sh: line 2: syntax error near unexpected token `('
./chowntest.sh: line 2: `sudo chown -R user:apache /home/ !({ssl.cert.**,**/ssl.cert.**})'
Run Code Online (Sandbox Code Playgroud)
这可行吗?
chown -R不会对您传入的内容执行任何解释。任何使用类似内容的尝试!(...)都会由 shell 解释。如果您想在递归中支持奇特的逻辑,请使用类似以下内容的内容find:
find /home ! -name 'ssl.cert.*' -exec chown user:apache '{}' \;
Run Code Online (Sandbox Code Playgroud)