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)
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 /*.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With