As the question itself, I cannot find out why
tail -c-1 myfile.txt
tail -c+1 myfile.txt
-c, --bytes = [+] NUM
output the last NUM bytes; or use -c +NUM to output starting
with byte NUM of each file
tail -c+1 myfile.txt is the same as
cat myfile.txt: you're telling
tail to start output with the first (
+1) byte (
-c), in other words: the whole file.
tail -c-1 myfile.txt (more typically:
tail -c1 myfile.txt) outputs only the last byte in
myfile.txt is a properly formatted text file that ends with a trailing
\n, and uses either a single-byte encoding such as ASCII or one that has single-byte ASCII encoding as a subset, such as UTF-8, this will output just that
\n, i.e., a blank line.
tail's basic logic in general terms (covers both the GNU and the BSD/macOS implementation):
tail [-<unit-type>] [+-]<unit-count>
-n, meaning lines; since
-<unit-type>is optional, you often see only
<unit-count>specified, which then invariably refers to lines (e.g.,
-crefers to bytes(!) and is not UTF8-aware in either implementation.
-bfor 512-byte blocks.
<unit-count> has no sign (e.g.,
1), or an explicit minus (e.g.,
-1; never necessary),
<unit-count> units are returned from the end of the input.
+-prefixed, the portion of the input that starts at position
<unit-count> - taken as a
1-based(!) index - is returned, notably including that position; e.g.,
tail -n +2 requests everything starting from (and including) the 2nd line.
<unit-count> is possible, and defaults to
10, but that only works if you also omit
-<unit-type>, which implies
tail -n 10 and therefore:
tail's default behavior is to output the input's last
If we apply this logic to the OP's follow-up question regarding the behavior of
-c+0 is treated the same as
-c+1 and therefore outputs the entire input (same as
cat): you're asking for everything starting at the "zeroth" byte, which doesn't exist, but since
0 < 1, with
1 being the first actual byte position, you still get the entire input as output.
-c-0 outputs nothing at all, because you're asking to return zero bytes (in other words: nothing) from the end of the input.