Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to release space in my server's hd so I'm matching old dates in a log file with sed and it is decreasing but my root partition is now using 98% percent of it's space instead of 91% it was using before I invoke sed. I did this sed -i '/^Jan/ d' file.log and my log file decrease from 6G to 400M. I'm using find / -size +1G trying to search a temporal file or something like that but it's not matching new files. Edit: I did echo -n > file.log to avoid a service crash but it's temporal because the issue remains

share|improve this question
1  
In general, sed -i is non-standard so if in-place file modification is desired, ed(1) is recommended over sed -i instead. –  jw013 Feb 10 '12 at 1:38
add comment

2 Answers

up vote 3 down vote accepted

The --in-place option to sed cannot really edit a file in place, so it actually does the equivalent of:

if sed ... input > /tmp/output$$ ; then
    mv /tmp/output$$ input
else
    rm /tmp/output$$
fi

which means prior to the mv command you can double (or worse) the size of the input file on disk. When file-systems reach nearly full, they become dreadfully less efficient.

It sounds like the larger problem is that you are just plain out of disk-space or you have /var/log and /tmp mounted on the same partition as / and if / is on a small partition, you will overfill it now and next week and the week after that, etc.

Look at mount and df /tmp and df /var/log to see how your disk is set up. You either need to:

  1. fix the disk mounting
  2. get a larger disk
  3. look into logrotate
  4. stop logging so much
  5. or some combination of the above
share|improve this answer
    
6. look into remote logging 7. have a look at insitu (but handle with care) –  sr_ Feb 6 '12 at 15:07
    
The temporary file should go in $TMPDIR, so the user ought to be able to set TMPDIR to point to a partition with more space. Unfortunately, gnu sed 4.1.2 actually doesn't honor TMPDIR and doesn't even go to /tmp, but uses the directory in which the file being worked on resides (this makes some sense, since it guarantees that the tmpfile is on the same partition so the final move is just a rename, but hurts for the current situation.) On the other hand, -i is a complete hack, and the user could just as easily do the file moves. –  William Pursell Feb 6 '12 at 15:19
    
It's true. It didn't move anything to /tmp (sed 4.1.5). I looked for hidden files in the /var/log dir but I didn't find temporary files in there neither. I could use mv or echo instead of sed but I wanted to keep all February logs. So the final solution was remount the partition. (Now is using 30% :D ). Thank you –  altmas5 Feb 6 '12 at 16:35
add comment

Running strace on the sed -i should make it pretty obvious where it's putting the temporary files. But the easiest thing to do is not use -i. Redirect the output to a file on a partition where you have space.

share|improve this answer
    
I will not use the -i option with large files or use tr instead of. thnks –  altmas5 Feb 6 '12 at 16:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.