Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

System: Xubuntu 13.10

When I have this crontab entry

*/5 * * * * cat /home/dbk/.bash_aliases &> /home/dbk/Desktop/junk

junk has a byte size of 0.


$ cat /home/dbk/.bash_aliases &> /home/dbk/Desktop/junk

gives a file with a proper size and content.

share|improve this question
up vote 4 down vote accepted

The probem because cron run task with sh. &> is a shortcut to redirect both stderr and stdout to the same file in bash, not in sh.

In sh, your command:

cat /home/dbk/.bash_aliases &> /home/dbk/Desktop/junk

meaning run two commands separately:

  • Run cat /home/dbk/.bash_aliases in background

    cat /home/dbk/.bash_aliases &

  • Truncate the junk file.

    > /home/dbk/Desktop/junk

So you should use bash to run your command in crontab:

*/5 * * * * bash -c "cat /home/dbk/.bash_aliases &> /home/dbk/Desktop/junk"

or using more portable way:

*/5 * * * * cat /home/dbk/.bash_aliases > /home/dbk/Desktop/junk 2>&1
share|improve this answer
Its true that >&1 2>&1 is the analog to &>, but i think that in the portable cat case it is useless - if cat errors it should quit and write nothing anyway so >file is enough. – mikeserv Mar 23 '14 at 20:44
@mikeserv: Yes, you can see man bash, REDIRECTION section for more details. No, if cat produce any errors, these errors will be saved to file. – cuonglm Mar 24 '14 at 1:27
What kind of errors will be saved to the file? – mikeserv Mar 24 '14 at 1:28
@mikeserv: any errors produce by cat, i.e you cat a file which doesn't exist. – cuonglm Mar 24 '14 at 1:31
Much better than that test -e $file && cat $_ >$tgt – mikeserv Mar 24 '14 at 1:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.