FILE=a.txt
FILE_SIZE = `stat -c %s $FILE`
if [ $FILESIZE >= 1000 ]; then
cp $FILE /tmp/
# How to empty file ?
then
I am trying to get size of file and if the size is over limited and cp those file and empty the same file
How to acheive this ?
You’d probably be better off doing something like:
since that’ll be near-atomic in duration.
Then
mvit to thetmpfilesystem after that while processes will recreate a new${FILE}.Keep in mind that, if you have a long lived process writing to
${FILE}, it will continue to write to${FILE}.stagingafter the first move.But, if you just have a lot of processes which open/write/close your file, the atomic move is probably the safest way to do it.