append/append-once/overwrite
Jump to navigation
Jump to search
How to use the append
, append-once
, and overwrite
to append and replace data in files.
Introduction[edit]
- Appends a user-provided line to a text file.
- Includes additional sanity testing (checks if the folder where the file resides is writable; checks if the file is readable and writable).
- Offers an easier-to-use interface. [1]
- Write operations are atomic.
- If called as
append-once
, it avoids duplicating the same content, should the exact same lines have already been appended earlier.[2] - If called as
overwrite
, replaces all of the contents of the file with the provided line. - Its write operation is similar to:
printf "%s\n" "text to append" | sponge -a /file/to/append/to >/dev/null
append
is the primary executable. The append-once
and overwrite
executables are simply symlinks to append
. append
will check what executable it was called as, and adjust its behavior accordingly.
Target Audience[edit]
If append
, append-once
, or overwrite
are used in a security critical context, it should only be used by people capable of reviewing its relatively short and simple source code.
Syntax[edit]
(append|append-once|overwrite) /path/to/file 'line to append'
Example[edit]
append ~/testfile 'some text here'
Exit Codes[edit]
- 0: Success.
- Non-Zero: Failure.
Limitations[edit]
- None known at the time of this writing.
Footnotes[edit]
- ↑
[1] No need to use:
grep
- considering special characters in
grep
printf
- pipe
readlink
>/dev/null
redirection.
- ↑
append-once
was previously implemented as a standalone Bash script, whileappend
andoverwrite
did not exist. The new implementation is written in Python, fixes limitations, improves error and edge case handling, and provides the two additional utilities.

We believe security software like Kicksecure needs to remain Open Source and independent. Would you help sustain and grow the project? Learn more about our 13 year success story and maybe DONATE!