I have a program on Ubuntu Linux that creates a logs/error.log file with a permissions 660 (rw-rw----) or 640 (rw-r-----). But I want the file permissions always to be 666 (rw-rw-rw-) (including when the program creates the file).


  1. I can't modify the program. Therefore, I can't change 660 mode using by the program for a new files.
  2. The program can recreate the file at any time. Therefore, the solution with a single manual execution of chmod is not suitable.
  3. I need to add a bits of permissions, but not subtract. Therefore, umask and setfacl are not suitable.
  • Can you explain the situation more thoroughly? Why does a log file need to be executable?
    – Natolio
    Dec 21, 2021 at 17:44
  • 1
    Exactly why would you want a logfile to be executable? If some fool does execute it, it will throw a million syntax errors. And, just possibly, it may contain an actual valid command that may be destructive. You can get 666 by exporting your umask as 000, but that would apply to all files, and anyway many applications over-ride that for their own reasons. Dec 21, 2021 at 17:46
  • Additionally, is the program actually setting the log file to 660 or is it just using the default umask? A more thorough explanation of your scenario is necessary. Umask and setfacl can both be used to grant new files more permission. Please explain your 3rd restriction more.
    – Natolio
    Dec 21, 2021 at 17:49
  • Natolio, it is my mistake. I mean 666 (rw-rw-rw-), not 777. I need it for docker. Without rw mode for other I can't edit the mysql log files in mounted as volume folder from host.
    – Mihail H.
    Dec 21, 2021 at 18:07
  • 2
    nah. Making the file world-writable is the wrong solution to this problem. Your actual problem is "how do I give a docker container rights to change a 660 file that belongs to user:group"; changing the file to 666 is simply the wrong approach here; instead, you'd change the group membership of the process trying to access it. Dec 21, 2021 at 18:23

3 Answers 3


You can use inotify to track your file or directory where it is created so you can update its permissions when it is created

  • Thanks, it works! I added the final solution in your answer, if you don't mind.
    – Mihail H.
    Dec 21, 2021 at 20:26
  • @MihailH. I would not suggest a solution with world-writable permissions. Please post this solution as your own answer.
    – AlexD
    Dec 22, 2021 at 9:07

If all other more sane options are out (like choosing a suitable user/group for the mystery log-creating program that is compatible with whatever you want to do from the docker host, or modifying the configuration of the program so it uses the right permissions), you can use the LD_PRELOAD trick:

Hook it whatever syscall your mystery program uses to create the file (probably creat or open, check with strace). Then compare the filename, and modify the mode for your logfile only.

This requires you to know how to program in C.


Final solution for running inside a docker container:

cd logs
umask 0
find . -type f -not -name ".gitignore" -exec chmod 666 \{\} \;
inotifywait -rmq -e attrib -e create -e moved_to --format "%w%f" --exclude "/\.gitignore" . | xargs -n1 -d"\n" chmod 666

Since the solution set world-writable permissions it is not recommended for use as is. Try to find another way that uses a safer permissions.

Thanks to AlexD for the hint!

You must log in to answer this question.

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