Monday, July 16, 2007

zero-sized a file without permission / ownership changes

Let us assume we have 120GB mail spool file named "bigfile" located somewhere in /var/spool/mail .

The objective here is to initialize the file, so that it would have zero (0) filesize. This should be achieved with the following conditions without changing the file's permission and ownership , or even deleting and re creating the file.

Here is an old one liner trick that does the job:

Just CD to that working directory and view the file first like so

# cd /var/mail
# ls -la

-rw-rw---- 1 vertito mail 120000000000 2007-07-16 16:24 bigfile

Simply as root

# cp /dev/null bigfile

This would copy nothing and just overwrite the file with zero-sized data.

# ls -la

-rw-rw---- 1 vertito mail 0 2007-07-16 16:24 bigfile

See the difference?

:)

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy