【发布时间】:2013-10-20 04:22:36
【问题描述】:
我是 BASH 的新手,我一直在使用这个带有 cron 作业的脚本。我遇到了一些麻烦,最初使用mv,但事实证明它不会与匹配的目录或任何东西合并。所以我被建议使用cp,因为据说它会合并和替换。
/schedule/ = 源目录 /public_html/ = 目标目录
#!/bin/bash
[ignore dot files/hidden files when copying]
cp -a schedule/* public_html/
[empty contents of source directory(schedule/) after copying]
来源:/schedule/(包含文件夹/文件)
/files/
--4.html
--5.html
/assets/
--sitemap.xml
目标:/public_html/(之前的文件夹已经存在)
/files/
--1.html
--2.html
--3.html
/assets/
--sitemap.xml
最终,我试图找出如何在使用cp 时忽略隐藏文件,并在复制后清空源目录。我正在阅读 BASH 参考手册,看到了nullglob,但我不知道是否应该使用它。
谁能提供一个例子或指出正确的方向?
【问题讨论】:
-
是的,
rsync有一个可以过滤隐藏文件的--exclude选项和一个可以过滤空目录的--prune-empty-dirs选项。