how to clean a textfile in Linux

DON'T post new tutorials here! Please use the "Pending Submissions" board so the staff can review them first.
Post Reply
User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

how to clean a textfile in Linux

Post by bad_brain »

alright, this is just a very tiny HowTo, but I think it is very useful.
when you're working on Linux there are plenty of log files, some of them grow really big after a while (especially the logs for apps you installed by hand, they don't use any log rotation in many cases).
usually you download the logs and analyze/store them, and to save space it would be the best to empty the old log file, right?
I use the vi editor, but there is no way to flush the whole content of a file, you can only delete lines, like:

Code: Select all

1000dd
this would delete 1000 lines below the cursor, but that's not very comfy especially because you don't know how many lines the file has.

but yesterday I found a nice solution, seems it was too easy to discover it earlier.. :lol: :roll:
let's say the logfile is named some_log, you can flush the whole content simply by:

Code: Select all

> some_log
what it does? it simply writes "nothing" to the file and overwrites anything in it.
and voila: file is nice and clean again... :)

User avatar
computathug
Administrator
Administrator
Posts: 2693
Joined: 29 Mar 2007, 16:00
17
Location: UK
Contact:

Post by computathug »

cheers b_b, im sure this will come in handy :wink:

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

agreed ^^ will have to try this later, thanks b_b

Post Reply