2

I know you can use touch to create a new empty file.

I just learned that touch can be used to update the access and modification time of a file. I don't quite know in what situations and why do you need to update the access and modification time of a file , i.e. the usefulness of this particular function?

Thanks!

2 Answers 2

2

Some utility depends on timestamp of the file.

For example, make uses timestamp to check whether it is required to do something (usually build) based on the timestamp of the source code, and output (executable, object files, ...)

By touching followed by make, the source file, you can force rebuild.

Sign up to request clarification or add additional context in comments.

Comments

0

In addition, touch has a -d option that can fake the modification time. If one "knows what he's doing" she can avoid long build time, due to unnecessary re-compilations.

For example, when adding a declaration to a common header file, that does not change any old API, one can fake the header real modification time, and bypass Makefile's dependencies.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.