bash 递归触摸修复计算机之间的同步

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12460728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 03:17:37  来源:igfitidea点击:

Recursive touch to fix syncing between computers

bashcommand-linesyncdropbox

提问by Gemma Hentsch

I'm looking for a way from the command-line to touch every file in a directory (and subdirectories) due to a mistake of mine a synced repo of mine has gotten a bit out of step on my development machines.

由于我的错误,我正在寻找一种从命令行访问目录(和子目录)中的每个文件的方法,我的同步存储库在我的开发机器上有点不合时宜。

I've now through some unpleasant voodoo managed to get it back into a clean state on one machine, before I do the next sync, I want to prioritise everything time wise on this machine.

我现在已经通过一些令人不快的巫毒教设法让它在一台机器上恢复到干净的状态,在我进行下一次同步之前,我想在这台机器上优先考虑所有时间。

Is there an easy way to touch all the files?

有没有一种简单的方法可以触摸所有文件?

Or am I better doing a manual sync of the directory?

还是我最好手动同步目录?

(I'm using dropbox for syncing for reference)

(我正在使用 dropbox 进行同步以供参考)

回答by imp25

You could use findalong with xargsto touch every file in the current or specified directory or below:

您可以使用findwithxargs来触摸当前或指定目录或以下目录中的每个文件:

find . -print0 | xargs -0 touch

for the current directory. For a specified directory:

对于当前目录。对于指定目录:

find /path/to/dir -print0 | xargs -0 touch

The -print0option to findalong with the -0option to xargsmake the command robust to file names with spaces by making the delimeter a NULL.

-print0选项find与一起-0选项,xargs通过使分隔符为NULL使命令稳健与空格的文件名。

Edit:

编辑:

As Jeremy J Starchar says in a comment, the above is only suitable if your findand xargsare a part of the GNU toolchain. If you are on a system withour GNU tools you could use:

正如 Jeremy J Starchar 在评论中所说,以上仅适用于您find并且xargs是 GNU 工具链的一部分。如果您使用的是带有 GNU 工具的系统,您可以使用:

find . -exec touch {} \;

Edit by dcgregorya:

dcgregorya编辑:

Having to do this against a very large data set I've found this command to be (much) faster.

必须针对非常大的数据集执行此操作,我发现此命令(快得多)。

find ./ -type d -print0 | xargs -I{} -0 bash -c "touch {}/*"

Limits find to finding folders then executes touch against folder /*.

将 find 限制为查找文件夹,然后对文件夹 /* 执行 touch。

回答by Gemma Hentsch

So this is a solution to my immediate problem of touching all files, whether it works with dropbox will have to be seen.

所以这是我接触所有文件的直接问题的解决方案,它是否适用于 dropbox 将不得不被看到。

In the root of the directory in question

在相关目录的根目录中

find . -print -exec touch {} \;

(print is extraneous but it can be helpful for feedback)

(打印是无关紧要的,但它可以帮助反馈)