Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

up vote 1 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

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.