Why cd does not change current directory in crontab?

The commands are being run independently, so it is not the same as expecting them to run in the same shell/environment. You would probably be better served by creating a shell script that performs the desired commands and then calling the script from the crontab.

Update: The above was a guess, and/or proposed possibilty (as a comment so tersely and aggressively pointed out). So I decided to test on CentOS 6.6 and... I was wrong... The following crontab entry worked properly:

* * * * * echo \`pwd` |logger; cd /home; echo `pwd` |logger;

So that should have worked for you... I still maintain that you would be best serverd by calling scripts not individual commands in your crontab... but that is a preference (so please be kind in the comments...).


The following should work:

58 12 * * * (cd /home/joe/dev; echo `pwd` | logger)

By wrapping the commands in parentheses, you should force them all to run in the same subshell.


As per this Unix&Linux SE answer, you can replace ; with && as different versions of cron across different Linux distributions handle this type of functionality in different ways:

cd /home/joe/dev && echo `pwd` | logger