Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting file-content

Status
Not open for further replies.

ovince

Programmer
Feb 27, 2007
55
FR
hi

is there an easy way to delete the content of the file but leaving an empty files in the directory?

oliver
 

Try:
Code:
>TheFile
#-- or --
cp /dev/null > TheFile
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
I usually use cat!

cat /dev/null > TheFile

Regards,
Khalid
 
That "null" command only works in Bourne or Korn shell

In which case this is one byte shorter still:

Code:
>TheFile

Unless if Korn shell and the noclobber option is in use (set -o noclobber), then it won't erase existing files... But you can still erase a file by temporarily overriding the noclobber option:

Code:
>|TheFile


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top