How To Empty A Large File In Linux Witout Deleting Shell Command Delete

Mobile
feeds
Welcome Login | Register

How To Empty A Large File In Linux Witout Deleting Shell Command Delete
Reply Your Comments:
Click this button if you are interested in replying to this topic and leave your comments
Sent To Friend
CLick this button if you want to send this page to a friend.
Subsribe To Rss Feeds
Subscribe to RSS
CLick this button if you want to subscribe to this RSS Feed. You can use your browsers feeds burners if you have mozilla or internet explorer 7 or higher and keep up with updates.
  Forums Index
      » Linux Forums
        » » How To Empty A Large File In Linux Witout Deleting Shell Command Delete
How To Empty A Large File In Linux Witout Deleting Shell Command Delete
Post Description: how to empty a large file in linux witout deleting shell command delete Linux
Post Tags:
This Post Has Been Viewed 10037 Times Since Sat Jan 20, 2007 6:28 pm Author unix with 7 replies
How To Empty A Large File In Linux Witout Deleting Shell Command Delete
Advertise On This Page




Linux General Good Housekeeping

Often when i login into my shell, i get this message:


     Code:
[root@host file]#
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


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


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



Leave Your Comments

Your Name
Your Email Address (Will Not Be Published)
Notify Me When Someone Replies to this Page
(An email will be sent to you when someone replies to your comments)
Your Comments
Include A Picture with your comments
Share
| More
Share this page by putting this URL in your comments to other websites like myspace, Facebook, Twitter friendster, Hi5, Groups, Boards, Forum or others. Just Copy and Paste this Code
URL:
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.
Embed:
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
BBCODE:
Subscribe Feeds
Webmasters - Exchange Links With Us. Add related websites to this topic
Add Link:
Links Related to : How To Empty A Large File In Linux Witout Deleting Shell Command Delete

Comments and replies About How To Empty A Large File In Linux Witout Deleting Shell Command Delete
:: 1 :: Reply #1425 Reply By pankaj On Tue Apr 10, 2007 2:43 am
pankaj:
plse give me more momand

:: 2 :: Reply #25940 Reply By eddie On Sun Oct 28, 2007 10:53 am
eddie:
timeless classiscs in the clst
:: 3 :: Reply #44529 Reply By ovizii On Fri Mar 07, 2008 2:23 am
ovizii:
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?
:: 4 :: Reply #66234 Reply By Rob On Wed Aug 13, 2008 6:02 am
Rob:
dude! thank god for i-nodes eh?
:: 5 :: Reply #88591 Reply By willie On Fri Jan 02, 2009 10:47 pm
willie:
thank you for showing me how to remove last lines linux tail wallpaperama
:: 6 :: Reply #115469 Reply By indrek On Sun Sep 13, 2009 11:56 am
indrek:
you can also try this:
echo "" >| ./yourfile
:: 7 :: Reply #117409 Reply By genner On Thu Oct 08, 2009 4:37 am
genner:
goood it was so util for me. is what i was looking for thanks

dsldatasolutions.net