Monday, 21 May 2012
 Home arrow Blog arrow How to empty or clear the contents of an existing UNIX file
   
Main Menu
Home
News
Blog
Links
Search
FAQs
Spider
Articles
@intrenet
Free Softwares
Break for fun
Friends VIdeos
Techno videos
Contact Us
Disclaimer
Guest Book
Speed test
V.E.C. Calculator
IPv4 Subnet Calc
IPv6 Subnet Calc
Byte Converter
Converter
GMT/UTC Time
Bandwidth Calc
Allinone Calc
IANA Port Numbers
Country Call Codes
Pk Postal Codes
Surf Anonumously
Visitors Counter
mod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_counter
mod_vvisit_counterToday104
mod_vvisit_counterYesterday203
mod_vvisit_counterThis week104
mod_vvisit_counterThis month4653
mod_vvisit_counterAll125329
 
 
 
 


How to empty or clear the contents of an existing UNIX file PDF Print E-mail
User Rating: / 0
PoorBest 
Written by Amanatullah khalil   
Sunday, 24 May 2009

How to empty or clear the contents of an existing UNIX file

 

If you want to empty the contents of a UNIX file, you could delete it and recreate it, but, as is typical of UNIX, there are more elegant alternatives. Here are a couple of ways to dump the innards of a file. If you know of any others, add them to the comments.


The special file /dev/null can and does contain nothing. While most often used as a sink of nothingness, for example writing output to it that you don’t want to keep, it can be used as a source of nothingness, too. To replace the contents of the file blah.txt with nothing, you can use the command

cat /dev/null > blah.txt

This command makes sense as it is using standard UNIX redirection to place the contents of one file (a known empty one) to another file. Another way to do this, although a less obvious way and probably less readable in a shell script by others, is

> blah.txt

courtesy http://www.tech-recipes.com/rx/2993/how_to_empty_or_clear_the_contents_of_an_existing_unix_file/

window.google_render_ad();
 
< Prev   Next >
 
 
 
csatpk Newsflash
Statistics
OS: Linux h
PHP: 5.2.17
MySQL: 5.1.63-community-log
Time: 20:22
Caching: Disabled
GZIP: Disabled
Members: 3
News: 368
Web Links: 5
Visitors: 265566
Popular