On Thu, Nov 21, 2024 at 19:55:04 +0100, to...@tuxteam.de wrote:
> On Thu, Nov 21, 2024 at 06:44:37PM +0000, Darac Marjal wrote:
> 
> [...]
> 
> > If it helps, "sponge" (in the moreutils package) seems to offer the right
> > interface here:
> 
> [...]
> 
> Oh, wow -- thanks for that little gem!

For the record, sponge -a doesn't actually append to the original
file.  As the man page says,

    -a

    Replace the file with a new file that contains the file's original
    content, with the standard input appended to it. This is done
    atomically when possible.


hobbit:~$ ls -li y
847514 -rw-r--r-- 1 greg greg 8 Nov 21 07:18 y
hobbit:~$ echo quux | sponge -a y
hobbit:~$ ls -li y
6684744 -rw-r--r-- 1 greg greg 13 Nov 21 14:11 y

The inode number changed, because it's a new file.  This may be desirable
or not -- it all depends on your needs.  If the file in question is a log
file that some program may still be writing to, then this is absolutely
NOT desirable.

Reply via email to