Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 Unix 批处理脚本,它将一个目录(称为 dir A)的内容复制到另一个(称为 dir B)。
这是我目前的副本声明。
cp -urL /path/to/dir/A /path/to/dir/B
但是,此语句会复制隐藏文件。
如何排除任何和所有隐藏文件被复制?
将星号 (*) 放入以复制但忽略隐藏文件
cp -urL -r /path/to/dir/A/* /path/to/dir/B
如果bash用作您的 shell,请取消设置dotglobshell 选项。
bash
dotglob
man bash
dotglob如果设置,bash 包含以“.”开头的文件名 在路径名扩展的结果中。
#!/bin/bash shopt -u dotglob cp -urL /path/to/dir/A /path/to/dir/B