zsh扩展globbing来创build子目录

% zsh --version zsh 5.0.2 (x86_64-apple-darwin13.0) % ls -l bootstrap/ local_folder/ ssh_confs/ zsh_confs/ 

我想创build一个名为“文件”的目录中的所有目录中的子目录..我想使用zsh通配符function..

 % setopt extendedglob % mkdir -pv */files zsh: no matches found: */files % mkdir -pv **/files zsh: no matches found: **/files 

Globbing用于模式匹配而不用于模式生成 :它只返回与模式匹配的现有文件的列表,而不是与模式匹配的每个名称的列表。

*/files只是意味着“当前工作目录中任何目录中名为'文件'的任何现有实体”。

可以使用globbing通过使用/ * globbing限定符来获取当前工作目录中的目录(仅限目录)的列表:

 ls -ld *(/) 

为了在每个文件中创build'files'子目录,你可以使用for -loop:

 for directory in *(/); do mkdir "$directory/files"; done