Posted by: ibmadmin | October 4, 2011

How to empty the file content

Some time, we may need to delete the file content with out deleting the file. In this case we need to use the following command to empty the SystemOut.log file content.

cat /dev/null > SystemOut.log

The above command nullify the SystemOut.log file content. So after that we will get the new file entries in the SystemOut.log.

This process will help us to retain the process id which is attached to the file. If we delete the file with out stopping the Application Server process (i.e. JVM), then the original file handle was removed from the particular process id. So the JVM won’t write any more logs entries to the SystemOut.log file.

We need to note that, if we copy the /dev/null file content into SystemOut.log file, then also we will lose the file handle. So we need to be very care full in nullifying the file content.

cp /dev/null SystemOut.log  – This will delete the SystemOut.log file content. But this is wrong approach as we are replaying the SystemOut.log file with /dev/null file.

You can do the same in other ways also. You can send one word to the SystemOut.log file with > file redirect operator.

echo “ibmadmin” > SystemOut.log


echo `date` > SystemOut.log

After the above command execution, the SystemOut.log file will have new entries only.

If you want to add your own File content identification location to debug some issue in the SystemOut.log or SystemErr.log files, then you can use the following commands to append your own text in log files.

echo “######### DEBUG MESSAGE Start ##########” >> SystemOut.log

echo “######### DEBUG MESSAGE End ##########” >> SystemOut.log

Note: Use the following command to identify the file handle for a particular file. You can verify the file handle for the SystemOut.log file before and after nullify the file content. If you see the same process id, then the file content deletion worked fine.

/usr/sbin//fuser SystemOut.log

SystemOut.log:    29566o
In the above output 29566 - Is the corresponding JVM Process id
  o - It is mode of the process ie input or output.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: