I have created an empty file in linux and added a character to it. But it is showing up as a 2 bytes file
It seems it is appending a (char)10 to the end of the file. Note that I am doing this in Nautilus, not programmatica开发者_开发技巧lly. Why does this happen? How to prevent it?
ASCII 0x0A is the newline '\n'.
If that file of yours has been created with echo 1 >file
there's a newline added to it. If you're looking to skip that behavior, do echo -n 1 >file
.
The ASCII character with the decimal code 10 (0x0a in hex) is '\n' i.e. the new line (LF - Line Feed) character in Unix-like systems. How did you create the file?
EDIT:
If you use echo, you should probably try the -n
flag which suppresses the final newline that is emitted by default:
echo -n X > file
精彩评论