Recursive touch to fix syncing between computers [closed]

江枫思渺然 提交于 2019-12-04 11:45:09

问题


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)


回答1:


You could use find along with xargs to touch every file in the current or specified directory or below:

find . -print0 | xargs -0 touch

for the current directory. For a specified directory:

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

The -print0 option to find along with the -0 option to xargs make the command robust to file names with spaces by making the delimeter a NULL.

Edit:

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

find . -exec touch {} \;

Edit by 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 /*.




回答2:


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

In the root of the directory in question

find . -print -exec touch {} \;

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



来源:https://stackoverflow.com/questions/12460728/recursive-touch-to-fix-syncing-between-computers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!