0

I am trying to clear the logs and I do not have permission since the file permissions on Apache error logs are like this: -rw-r-----

When I tried to do something like chmod 777 error.log

I got this error: chmod: changing permissions of `error.log.1': Operation not permitted

Any idea how to change my permissions to allow myself to clear out my logs and delete the old error log files?

Thanks, Alex

1

You can change the permission of the file if you use sudo to preface the command:

sudo chmod 777 /var/log/error.log

You will need to add yourself to the sudoers file as the root user:

visudo

Alternatively you could create a logs group and add yourself to the group then change the group ownership of all your log files to the logs group.

1

If I recall correctly, most modern Linux distros have the apache log files owned by root, with group root, by default. Thus, you'll need to have root level access to modify the permissions, or clear the logs. If you don't have that via root login, sudo, su, or some sort of setuid root tool, you're likely out of luck.

If you can use sudo, it should be as easy as:

sudo cat /dev/null > error.log

which will clear the log file entirely (erasing it) but will preserve the permissions.

1

You didn't post the file ownership, but I'm guessing based on what you describe that it is user owned by root and group owned by your group user.

You can't change the permissions mode on a file that your user doesn't own unless you are root and you can't remove a file from a directory that you don't have write permissions to either through the user or group owner of that directory. So unless you have root access, you're going to have to ask your administrator to do it.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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