On Linux systems, I can append to a system file like this:

echo "# New data" | sudo dd of=/etc/config_file conv=notrunc oflag=append

But the dd command under OS X doesn't have the oflag option. Is this possible under OS X?


  1. I need root access.
  2. I'm not asking for alternative solutions, I'm asking if dd has the capability.
  • 2
    Install brew and brew/coreutils which provide (GNU) dd - linked as gdd to /usr/local/bin. – klanomath Mar 29 '17 at 17:57

You can seek to the end of the target file:

sudo echo "# New data" |
    dd of=/etc/config_file conv=notrunc bs=1 seek=$(stat -f "%z" /etc/config_file)

Is there any reason you are using dd rather than output redirection?

The following will work:

echo "# New data" >> /etc/config_file

The >> means add to the end of file if it exists, otherwise create a new file.

  • Note sudo for root access. – danorton Mar 29 '17 at 14:43
  • Just add sudo in front of the whole line shown. – Rene Larsen Mar 29 '17 at 17:29
  • Nope, that won't work, either. In any case, I can come up with alternatives. The question is specifically about dd. – danorton Mar 29 '17 at 17:42

I also tried what you mention above , sadly it is not appending the output file as expected. But you can do below method,

First Create temporary file and later use dd command

Create a temp_file and redirect all data/output you want to write to that file and later you can do

sudo dd if=/temp_file_path of=/etc/config_file conv=notrunc

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .