linux: how to run a command in a given directory
Just specify the path to the script. No need for cd
:
0 12 * * * /path/to/script args
If your script looks for files in .
, then you will have to use cd
:
0 12 * * * cd /some/dir && /path/to/script args
Your question makes little sense. Use cd
. If you ask for the answer not to use cd
because you've tried it and it didn't work, it's likely you didn't enter it correctly in the crontab.
The simplest way would be to write a small shell script that will cd and run your main task, then cron the script.