rsync command is super useful because it could incrementally sync files between locations without the overhead of compressing and transferring. There are heaps of tutorials about how to use it, how very few cover the point that how to sync two folders, which I believe is the most common use.
I’d run rsync -avzP dir1 dir2, but unfortunately, this syncs dir1 under dir2. Some people would then run rsync -avzP dir1 dir2-parent. This could work, but it’s particularly dangerous if you add the --delete option. So how to sync the content of the two folders.
If you run man rsync – not many people would use nowadays, you’d get the very import/useful instructions:
A trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination. You can think of a trailing / on a source as meaning “copy the contents of this directory” as opposed to “copy the directory by name”, but in both cases the attributes of the containing directory are transferred to the containing directory on the destination. In other words, each of the following commands copies the files in the same way, including their setting of the attributes of /dest/foo: rsync -av /src/foo /dest rsync -av /src/foo/ /dest/foo
The instructions are there like forever, right? But the first command is tricky where you could override the destination directory with the content of foo, so I’d recommend you to always use the second way:
在 Unix 中，shell 可不是简单的命令解释器（典型的有 Windows 中的 DOS ），而是一个全功能的编程环境。Shell 是操作系统的一部分，用来与用户打交道，并且可以用来协调各个命令【1】。用Shell编程可以灵活地解决大量重复任务，十分方便。但是，Shell的语法十分怪异（个人意见），不容易记，如果现在熟悉的语言可以用来写shell那就好了——比如php——就可以快速开发Shell程序了（比如我的Preminder的后台程序），于是便有了这篇文章，本文以Linux为例说明php-cli的用法，其它平台的版本类似。