Add newline to end of file

From Freephile Wiki
Revision as of 08:22, 26 September 2025 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

For yaml files, there should always be a newline character at the end of the file. It's easy to overlook, and some editors are misconfigured to remove trailing newlines, meaning it can be a battle to keep your yaml syntactically correct. When you can't use tools like yamllint to fix things, here's a one-liner that does the job.

find . -name "*.yaml" -exec sh -c 'if [ -n "$(tail -c 1 "$1")" ]; then echo "" >> "$1"; fi' _ {} \;