-4
1
Background
When you run tail -f file
in bash, the file is outputted and then any subsequent appends.
However, when you remove something that has already been displayed, tail
outputs:
tail: nameoffile: file truncated
Your Challenge
When given an input f
, append tail: [value of f]: file truncated
(with trailing & leading newline) to the file f
. You can assume that file f
exists, the device is not full, f
is not empty, and that you have permissions to write to f
.
Test Cases
Input: something
File before:
Some
thing
File after:
Some
thing
tail: something: file truncated
Input relative/path/to/file
File before:
tail: relative/path/to/file: file truncated
File after:
tail: relative/path/to/file: file truncated
tail: relative/path/to/file: file truncated
Reference Implementation (Node.js)
x=>require("fs").appendFileSync(x,`
tail: ${x}: file truncated
`)
Sandbox (deleted) – programmer5000 – 2017-08-04T23:16:19.967
Why the downvotes? – programmer5000 – 2017-08-04T23:30:04.683
I didn't downvote but it doesn't seem too complicated to me. – MD XF – 2017-08-04T23:34:02.643
I'm not sure your "Reference Implementation" would count as a valid answer. You need to require
fs
. – Thomas W – 2017-08-05T13:10:19.267