They are zsh Glob Qualifiers
N sets the NULL_GLOB option for the current pattern
D sets the GLOB_DOTS option for the current pattern
where the meanings are
NULL_GLOB (-G)
If a pattern for filename generation has no matches, delete the
pattern from the argument list instead of reporting an error.
Overrides NOMATCH.
GLOB_DOTS (-4)
Do not require a leading `.' in a filename to be matched explic‐
itly.
You can find more information in the zsh expansion manual page, man zshexpn
and in the zsh options manual page man zshoptions
.
In your:
cp -R dir1/*(DN) dir2/
That means that the hidden files are also copied, but the N
qualifier doesn't make much sense here, as that means that if there's no matching file (if dir1
is empty or not readable), then the command will become:
cp -R dir2/
And while N
suppresses the no match error by zsh, you'll still get
a (more confusing) missing destination file operand error by cp
.
N
(nullglob) is most useful in things like files=( *(N) )
or for file in *(N)...
when it's OK to have an empty expansion.
But in your case, it's better to leave it out.
Alternatively, if you wanted cp
not to be run when there's no match but without reporting an error, you could do:
function { (( $# == 0 )) || cp -R -- "$@" dir2/; } dir1/*(ND)
Where the generated list (allowed to be empty) is passed to an anonymous function which checks its size before calling cp
.