Skip to content

Instantly share code, notes, and snippets.

@vbarbarosh
Last active May 14, 2019 18:34
Show Gist options
  • Save vbarbarosh/b975cf8d7e51607147bfebac7cd7f6b0 to your computer and use it in GitHub Desktop.
Save vbarbarosh/b975cf8d7e51607147bfebac7cd7f6b0 to your computer and use it in GitHub Desktop.
shell_files_truncate – Truncate files https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# Truncate files
# Shrink existing file to 4096 bytes
truncate -s 4K foo
# https://stackoverflow.com/a/18072642/1478566
# Extend file up to 4096 bytes in total (if file is less than this 4K)
fallocate -l 4K foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment