boredzo / truncate

Tool for creating empty files of a desired size, or shortening or extending files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

truncate

A tool for creating empty files

This tool uses the POSIX ftruncate function to set the length of a file.

  • If the file exists and is longer than that, it will be truncated (bytes after that length cut off).
  • If the file exists and is shorter than that, it will be extended and the new bytes zero-filled. (Whether this actually consists of writing zero-bytes to disk is dependent on your operating system's implementation.)
  • If the file doesn't already exist, it will be created, then extended to the desired length.

This is a very handy way to instantly create raw disk images for emulators. You can do things like truncate 1G oneBEELLIONbytes.img to create a blank disk image that you can then format with either host tools (like newfs_hfs or newfs_msdos) or guest tools (like the built-in Initialize alert in classic Mac OS).

Sizes can be specified as either whole numbers of bytes or whole numbers followed by a suffix:

B (or no suffix)
Bytes
S
Sectors of 512 bytes each)
K
Kibibytes (KiB) of 1024 bytes each
M
Mebibytes (MiB): 1024**2 = 1048576 bytes
G
Gibibytes (GiB): 1024**3 = >1 billion bytes
T
Tebibytes (TiB): 1024**4 = >1 triillion bytes
P
Pebibytes (PiB): 1024**5 = 1024 tebibytes
E
Exbibytes (EiB): 1024**6 = 1048576 tebibytes
Z
Zebibytes (ZiB): 1024**7
Y
Yobibytes (YiB): 1024**8

Compatibility

This works on macOS. It should work on, or at least be portable to, Linux-based operating systems.

About

Tool for creating empty files of a desired size, or shortening or extending files

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:C 98.9%Language:Makefile 1.1%