iqbal_cs iqbal_cs - 1 year ago 93
Linux Question

How 'tail' command returns the whole file content using parameters -c+1 or -c-1?

As the question itself, I cannot find out why

acts that way.
I have a file named
and its content is:


So when I use:

tail -c-1 myfile.txt


tail -c+1 myfile.txt



man tail

-c, --bytes = [+] NUM

output the last NUM bytes; or use -c +NUM to output starting
with byte NUM of each file

Answer Source
  • 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; assuming that myfile.txt is properly terminated with a trailing \n, and is 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.

The above applies to both the GNU (typical on Linux) and the BSD/macOS implementations of tail. If you're getting different results - as it sounds you're getting for tail -c-1 - tell us what implementation you're using / what platform you're on.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download