0

Just a Cron test command to consider, create an empty file in the user's home directory every minute:

* * * * * touch ${HOME}/example.example

Will touch behave the same in all systems (overriding an existing file)?

Have you ever came across a Linux in which touch will not override a file but rather create versions such as filename(1), file_name(2), etc. ?

1 Answers1

2

All touch does is create a file if none exists, or update the mtime on an existing one. It does not create versions. Both provided permissions & path allow.

And having ${HOME} in the cron line, is asking for trouble.

Bib
  • 2,380
  • There's an obvious problem in that that $HOME is not quoted (and cron jobs are run by sh by default where an unquoted parameter expansion invokes split+glob). But otherwise, the HOME environment variable is meant to be set in cron jobs to the home directory of the owner of the crontab. So using touch ~/example.example or touch "$HOME/example.example" should be fine. – Stéphane Chazelas Nov 23 '21 at 13:16
  • "And having ${HOME} in the cron line, is asking for trouble." -- I'm not sure a statement like this is really helpful without also including what kind of trouble might come up, and why. So, why do you think it's asking for trouble? – ilkkachu Nov 23 '21 at 15:18