Empty Error Log Unix
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and
Empty A File In Unix
policies of this site About Us Learn more about Stack Overflow the unix clear log file company Business Learn more about hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges linux empty log file Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a
Linux Empty Log File Dev Null
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 cat /dev/null emptied my log file but size did not change up vote -1 down vote favorite 1 I'm quite new to Unix. Using Solaris 10 I faced the below issue. There is a large log file
How To Empty A File In Linux
with size 9.5G. I tried to empty the file using the below command. # cat /dev/null file_log.txt By doing this I regained space on the file system but the size of the file still shows the same and is increasing. I figured a process is still running into the log file. Is there a way to correct the file size? Is this going to effect my file system? files logs io-redirection cat share|improve this question edited Jul 28 '14 at 22:45 Gilles 370k686731123 asked Jul 28 '14 at 18:17 user78960 1111 5 Did you mean to write cat /dev/null > file_log.txt? –user000001 Jul 28 '14 at 18:25 1 What do ls -l file_log.txt and du file_log.txt say? –Cristian Ciupitu Jul 28 '14 at 18:25 3 Do you try to restart the service? –cuonglm Jul 28 '14 at 18:26 I'm sorry people! I meant cp /dev/null file_log.txt –user78960 Jul 29 '14 at 19:13 But anyway, now I can make sense with the below answers what could have gone wrong. The process was still writing to the file when I ran the
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 how to empty a file in unix without deleting it ads with us Server Fault Questions Tags Users Badges Unanswered Ask Question _ Server Fault is
Linux Truncate Log File
a question and answer site for system and network administrators. Join them; it only takes a minute: Sign up Here's how it works: Anybody can linux truncate active log file 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 favorite 12 I was wondering if there was a proper way to http://unix.stackexchange.com/questions/147044/cat-dev-null-emptied-my-log-file-but-size-did-not-change 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. Side note: I'm having trouble setting up Postfix and am trying to make it easier for me http://serverfault.com/questions/285843/is-there-a-proper-way-to-clear-logs 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 at 16:23 answered Jun 30 '11 at 16:20 davey 5,9712527 1 /bin/csh (common for FreeBSD) would bail out this with "Invalid null command", meanwhile zsh (popular replacement for bash) would wait EOF. See serverfault.com/a/381380/6767
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 http://stackoverflow.com/questions/2423281/how-to-empty-truncate-a-file-on-linux-that-already-exists-and-is-protected-i 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 How to empty (“truncate”) a file on linux that already exists and is protected in someway? up vote 86 down vote favorite 20 I have a file called error.log log file on my server that I need to frequently truncate. I have rw permissions for the file. Opening the file in vi > deleting all content > saving works (obviously). But when I try the below cat /dev/null > error.log I get the message File already exists. Obviously there is some kind of configuration done on the server to prevent accidental overriding of files. Can anybody tell how do I "truncate" the file in a single command? linux file empty a file command-line share|improve this question asked Mar 11 '10 at 7:35 Sumeet Pareek 1,04711016 1 For a non-protected file truncate -s 0 file works. –Pramod Dec 30 '12 at 13:53 add a comment| 7 Answers 7 active oldest votes up vote 126 down vote accepted You have the noclobber option set. The error looks like it's from csh, so you would do: cat /dev/null >! file If I'm wrong and you are using bash, you should do: cat /dev/null >| file in bash, you can also shorten that to: >| file share|improve this answer answered Mar 11 '10 at 7:45 R Samuel Klatchko 55.4k791157 you are right about the shell being csh. How did you know that? –Sumeet Pareek Mar 11 '10 at 8:02 4 @Wikidkaka - based on the error message. csh on my system gives the similar File exists error while bash gives the very different cannot overwrite existing file error. –R Samuel Klatchko Mar 11 '10 at 8:10 6 @Jarmund - because the user has noclobber set, >file does not work. –R Samuel Klatchko May 16 '13 at 0:03 What's the difference between > file and >| file? –Will Jul 28 '14 at 2:27 @Will - if you have the noclobber option set, trying to redirect to an existing file fails. To override for the specific redirection while leaving noclo