Say I have some process which pipes to a file:
yes > foo
I now want to clear/empty the file
foo, but still want the process to write to the file, i.e. start filling the file again after clearing.
Is this possible?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
yes >> foo instead of
yes > foo and separately
:>foo to clear the file
yes >> foo cause
read to open
O_APPEND. This causes the file offset to be positioned at the end of the file before each write.
yes writes to the file
foo, with each write causing the file pointer to be positioned at the end of
: > foo truncates the file to 0 bytes. Now the next
yes write, due to the re-positioning of file pointer at the "end" of the zero-byte
foo induced by
O_APPEND, starts over at the beginning of the zero-byte