How To Empty A Large File In Linux Witout Deleting Shell Command Delete
Posted On Sat Jan 20, 2007 By unix In Linux Forums And Topics Discussions For Wallpaper Websites Running On Linux Servers Forums
Linux General Good Housekeeping
Often when i login into my shell, i get this message:
then to find out how big the size of the file is i send this command:
ok, one meg is not that bad, but lets say i wanted to empty the file, not delete it, so to do that, the process of reducing an existing file to a file with the same name that is 0 bytes large is called "truncating."
For creating a new empty file, the same effect is obtained with the touch command. On an existing file, touch will only update the timestamp. See the Info pages on touch for more details.
so to empty my root mail file, i would send this command:
tail
To "almost" empty a file, use the tail command. Suppose my error.log file becomes rather long because im gettin alot of errors on my web pages. now to remove all but the last 5 lines i can send this command:
first i want to see how large my file is, from this command you can see its 338384078 bytes
Now remove all the lines except the last 5
now i resend the list command and now my error.log file is only 439 bytes
Often when i login into my shell, i get this message:
CODE:
[root@host file]#
You have new mail in /var/spool/mail/root
You have new mail in /var/spool/mail/root
then to find out how big the size of the file is i send this command:
CODE:
[root@host file]#
total 1276
drwxrwxr-x 2 root mail 4096 Jan 20 14:59 .
drwxr-xr-x 14 root root 4096 Nov 21 13:15 ..
-rw------- 1 root root 1284052 Jan 20 14:59 root
total 1276
drwxrwxr-x 2 root mail 4096 Jan 20 14:59 .
drwxr-xr-x 14 root root 4096 Nov 21 13:15 ..
-rw------- 1 root root 1284052 Jan 20 14:59 root
ok, one meg is not that bad, but lets say i wanted to empty the file, not delete it, so to do that, the process of reducing an existing file to a file with the same name that is 0 bytes large is called "truncating."
For creating a new empty file, the same effect is obtained with the touch command. On an existing file, touch will only update the timestamp. See the Info pages on touch for more details.
so to empty my root mail file, i would send this command:
CODE:
tail
To "almost" empty a file, use the tail command. Suppose my error.log file becomes rather long because im gettin alot of errors on my web pages. now to remove all but the last 5 lines i can send this command:
first i want to see how large my file is, from this command you can see its 338384078 bytes
CODE:
[root@ log]# ls -la
total 330792
drwxr-xr-x 2 wallpaperama 4096 Dec 23 13:48 .
drwxr-xr-x 14 wallpaperama 4096 Feb 27 21:49 ..
-rw-r--r-- 1 wallpaperama 338384078 Mar 2 11:53 error.log
total 330792
drwxr-xr-x 2 wallpaperama 4096 Dec 23 13:48 .
drwxr-xr-x 14 wallpaperama 4096 Feb 27 21:49 ..
-rw-r--r-- 1 wallpaperama 338384078 Mar 2 11:53 error.log
Now remove all the lines except the last 5
CODE:
tail -5 error.log > error.log
now i resend the list command and now my error.log file is only 439 bytes
CODE:
[root@ log]# ls -la
total 12
drwxr-xr-x 2 wallpaperama 4096 Dec 23 13:48 .
drwxr-xr-x 14 wallpaperama 4096 Feb 27 21:49 ..
-rw-r--r-- 1 wallpaperama 439 Mar 2 11:55 error.log
total 12
drwxr-xr-x 2 wallpaperama 4096 Dec 23 13:48 .
drwxr-xr-x 14 wallpaperama 4096 Feb 27 21:49 ..
-rw-r--r-- 1 wallpaperama 439 Mar 2 11:55 error.log
hammudi Fri Apr 08, 2011
solve my problem. thanks for share...
Moon Wed Aug 11, 2010
thanks alot ...it realy realy helps . I manage to clear out all my log ...and redeem back the space
vatbier Mon May 31, 2010
NO !
on a CentOS 5 the command
tail -1000 pixall > pixall
makes the file totally empty.
on a CentOS 5 the command
tail -1000 pixall > pixall
makes the file totally empty.
genner Thu Oct 08, 2009
goood it was so util for me. is what i was looking for thanks
dsldatasolutions.net
dsldatasolutions.net
indrek Sun Sep 13, 2009
you can also try this:
echo "" >| ./yourfile
echo "" >| ./yourfile
willie Fri Jan 02, 2009
thank you for showing me how to remove last lines linux tail wallpaperama
Rob Wed Aug 13, 2008
dude! thank god for i-nodes eh?
ovizii Fri Mar 07, 2008
that almost worked for me, if i do cat myfile i only see the alst 5 lines with the above example but the file size did not change huh? any ideas?
eddie Sun Oct 28, 2007
timeless classiscs in the clst
pankaj Tue Apr 10, 2007
plse give me more momand
Related Content
Information
Forums »
Linux Forums And Topics Discussions For Wallpaper Websites Running On Linux Servers »
How To Empty A Large File In Linux Witout Deleting Shell Command Delete
Linux Forums And Topics Discussions For Wallpaper Websites Running On Linux Servers »
How To Empty A Large File In Linux Witout Deleting Shell Command Delete
Title: How To Empty A Large File In Linux Witout Deleting Shell Command Delete
Description: How To Empty A Large File In Linux Witout Deleting Shell Command Delete
Tags: how ,to ,empty ,a ,large ,file ,in ,linux ,witout ,deleting ,shell ,command ,delete
Info: This Post Has Been Viewed 0 Times Since
Date: Sat Jan 20, 2007
Author unix Received 10 Replies #2879
Date: Sat Jan 20, 2007
Author unix Received 10 Replies #2879
Share
URL: 

Embed: 

To embed this topic, just copy the code from the "Embed" box. Once you've copied the code, just paste it into your website or blog to embed it
BBCODE:: 

BBCODE is use on forums. You can put this code on all your BBCODE enabled forums like PhpBB, vBulletin® and others. Just Copy and Paste this code on your Posts and Replies on your forums
wallpaperama | Wallpapers | Forums | Terms Of Service
copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Mon May 06, 2013 (-8 GMT)
Powered by: Webune Forums V5
copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Mon May 06, 2013 (-8 GMT)
Powered by: Webune Forums V5