Clear Error Log Linux
Contents |
Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn linux clear log file in use more about hiring developers or posting ads with us Server Fault Questions Tags Users Badges Unanswered
Linux Clear Log File /dev/null
Ask Question _ Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute: linux errorlog Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Is there a proper way to clear logs? up vote 32 down vote
How To Delete Log Files In Linux Server
favorite 12 I was wondering if there was a proper way to clear logs in general? I'm new to Ubuntu and I'm trying to set up Postfix. The log in question is /var/log/mail.log. I was wondering if there was a correct way to clear it, rather than me going in it and deleting all the lines and saving it. I find that sometimes errors don't get written to it immediately after I clear the log and save it. linux truncate log file Side note: I'm having trouble setting up Postfix and am trying to make it easier for me to read the logs hoping it can help me out, instead of having to scroll all the way down. linux ubuntu logging share|improve this question asked Jun 30 '11 at 16:13 mastofact 263135 1 if you want to just see the end of the file then tail is your friend. tail /var/log/mail.log to display the last 5 lines. tail -f /var/log/mail.log to see all lines written to the end of the file. –Hangin on in quiet desperation Jun 30 '11 at 16:25 serverfault.com/questions/285843/… –poige Apr 20 '12 at 1:29 add a comment| 7 Answers 7 active oldest votes up vote 38 down vote accepted You can use: > /var/log/mail.log That will truncate the log without you having to edit the file. It's also a reliable way of getting the space back. Sometime people make the mistake of using rm on the log then recreating the filename, if another process has the file open then you don't get the space back until that process closes it's handle on it and you can mess up it's permissions. Also if you are watching the contents of the log you might like to use the tail command: tail -f /var/log/mail.log Ctrl-C will break off the tailing. share|improve this answer edited Jun 30 '11
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with
How To Empty A File In Unix Without Deleting It
us Super User Questions Tags Users Badges Unanswered Ask Question _ Super User is a question
Clear Var Log
and answer site for computer enthusiasts and power users. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a linux truncate active log file question Anybody can answer The best answers are voted up and rise to the top How do erase the contents of a error.log file but keep the file intact up vote 16 down vote favorite 6 I want to erase the contents http://serverfault.com/questions/285843/is-there-a-proper-way-to-clear-logs of the file error.log (nginx error log file), but I don't want to actually delete the file. is this possible? running ubuntu ubuntu logging nginx share|improve this question asked Dec 4 '10 at 3:02 user27449 1,655174475 add a comment| 2 Answers 2 active oldest votes up vote 37 down vote You can use this: >error.log (typed just like that - an empty output redirection) or truncate -s0 error.log share|improve this answer answered Dec 4 '10 at 3:16 Dennis Williamson 57.5k10101136 @Ignacio: If the http://superuser.com/questions/218214/how-do-erase-the-contents-of-a-error-log-file-but-keep-the-file-intact file already exists, either will truncate it. If the file doesn't exist, either will create it. –Dennis Williamson Dec 4 '10 at 3:21 You're right, my bad. –Ignacio Vazquez-Abrams Dec 4 '10 at 3:24 The last option worked for me, for some reason sudo >error.log didnt work for me (ubuntu 12.04) –davidkonrad May 19 '14 at 10:38 3 @davidkonrad: You would have to already be root for the redirection to work since it's performed before sudo takes effect. Or you can do sudo bash -c '>error.log' –Dennis Williamson May 19 '14 at 10:56 OK, didnt knew that. Thank you for clarification! –davidkonrad May 19 '14 at 11:01 add a comment| up vote 1 down vote You'll confuse the daemon. Erase the file then send SIGHUP to nginx. share|improve this answer answered Dec 4 '10 at 3:04 Ignacio Vazquez-Abrams 83.2k4111174 SIGHUP? Can't I shut nginx down, purge the file, then start? I want to know how to erase the file for knowledge sake also. –user27449 Dec 4 '10 at 3:14 If you wanted to, sure. But that would disrupt service. –Ignacio Vazquez-Abrams Dec 4 '10 at 3:15 I think both a null redirection and a truncate are atomic, so as long as no seeking is going on (especially if the only operation that's occurring is appending) it shouldn't be disruptive. –Dennis Williamson Dec 4 '10 at 3:25 add a comment| You must log in to answer this question. Not
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of http://stackoverflow.com/questions/12302290/how-to-delete-content-of-a-log-file-from-linux-terminal this site About Us Learn more about Stack Overflow the company Business Learn http://askubuntu.com/questions/706128/ubuntu-clear-apache2-error-log more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up log file How to delete content of a log file from linux terminal? up vote 6 down vote favorite 4 I have a log file on server called writelog which is about 2GB. I want to delete first 100,000 lines from the file. I could open the file and delete those lines but because of the file size it takes me forever to download it. linux clear log So, is it possible to do this from Linux terminal? If yes how? linux terminal share|improve this question asked Sep 6 '12 at 14:24 sushanghimire 1,61082348 1 you can see stackoverflow.com/questions/2112469/… –Jeshwanth Kumar N K Sep 6 '12 at 14:27 add a comment| 3 Answers 3 active oldest votes up vote 3 down vote accepted If you are running a Linux server, you can use ssh: ssh username@mydomain.com sed -i '1,100000d' /path/to/logfile share|improve this answer answered Sep 6 '12 at 14:27 perreal 59.3k56698 add a comment| up vote 13 down vote If you want to clear out the whole file a quick way is cat /dev/null > writelog See also this thread on unix.com. share|improve this answer answered Apr 11 '13 at 23:45 ropata 516521 1 you will get "File exists" error –Bala Dec 6 '13 at 11:03 1 @Bala That depends on your shell settings ... A better way of doing this is: : >| writelog to override the -C/noclobber option ... in C shell, this is: : >! writelog... The : is the built-in "null command", which does nothing, outputs nothing, and alwa
communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Ask Ubuntu Questions Tags Users Badges Unanswered Ask Question _ Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Ubuntu clear Apache2 error log [duplicate] up vote 0 down vote favorite 1 This question already has an answer here: When using sudo with redirection, I get 'permission denied' 5 answers I am new to Ubuntu. I can find my error log here in var/log/apache2/error.log. but i couldn't clear it. i tried to change the permission to edit the content. But couldn't achieve it. Please help me to remove it. I have read some question previously asked. but it does-not help me . this one I read http://askubuntu.com/questions/574725/how-to-clear-system-logs-in-ubuntu. Here is my terminal screen-shot: permissions apache2 error-handling share|improve this question edited May 18 at 9:52 Pierre.Vriens 6671615 asked Dec 5 '15 at 5:33 Kvvaradha 1299 marked as duplicate by David Foerster, Eric Carvalho, Videonauth, RPi Awesomeness, muru May 19 at 20:15 This question was marked as an exact duplicate of an existing question. Please post text files and program output listings as text, not as images (see How do I save terminal output to a file?). –David Foerster May 18 at 8:42 add a comment| 2 Answers 2 active oldest votes up vote 0 down vote accepted Most files in /var/log are owned by root. So, if you want to modify them, you will have to use sudo. To clear the error file, give command: sudo bash -c 'echo > /var/log/apache2/error.log' If that doesn't work, then very likely the apache process keeps the file locked and you have to stop apache before you can clear the file. This goes as follows: sudo service apache2 stop sudo bash -c 'echo > /var/log/apache2/error.log' sudo service apache2 start Note: You can't use sudo echo > /va