liunx bash将4096个字节回送到一个文件,文件在磁盘上使用8个字节?

liunx bash将4096个字节回送到一个文件,文件在磁盘上使用8个字节?,bash,filesystems,Bash,Filesystems,当我使用bash在liunx终端上编写临时测试文件时 echo text_content>file1 如果设置文本内容的长度为4096个字符(来自[a-Z]的随机字符)长。 结果file1最终使用两个4K块。还有一个inode test@instance-7:~/notes/rust$ du -csh file1 8.0K file1 8.0K totaldu 但为什么要用两个4K块呢?我是说,一个4K街区就够了吗 如果我将文本内容的长度设置为4095个字符长,那么它只使用

当我使用bash在liunx终端上编写临时测试文件时

echo text_content>file1
如果设置文本内容的长度为4096个字符(来自[a-Z]的随机字符)长。 结果file1最终使用两个4K块。还有一个inode

test@instance-7:~/notes/rust$ du -csh file1
8.0K    file1
8.0K    totaldu
但为什么要用两个4K块呢?我是说,一个4K街区就够了吗

如果我将文本内容的长度设置为4095个字符长,那么它只使用了一个4K块

为什么需要使用更多的块?或者我错过了什么

这里是我的liunx机器的一些磁盘信息

test@instance-7:~/notes/rust$ sudo fdisk -l /dev/sda

Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
Disk model: PersistentDisk  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gptDisk identifier: 35BD657D-931E-497E-A86C-D3D7C4F6BD2A
试试这个实验:

  • 写入
    cat>file1
    并按Enter键
  • 然后写
    这个
    ,然后按Ctrl-D两次,而不先按Enter键
  • 写入
    cat>file2
    并按Enter键
  • 然后写下这个,然后按回车键,然后按Ctrl-D键
  • 最后运行
    diff file1 file2
    ls-l文件[12]
试试这个实验:

  • 写入
    cat>file1
    并按Enter键
  • 然后写
    这个
    ,然后按Ctrl-D两次,而不先按Enter键
  • 写入
    cat>file2
    并按Enter键
  • 然后写下这个,然后按回车键,然后按Ctrl-D键
  • 最后运行
    diff file1 file2
    ls-l文件[12]

echo
添加换行符。尝试
echo-n
@tkausl,这样如果我自己写而不是echo,问题就解决了?
echo
添加了一个换行符。尝试
echo-n
@tkausl,如果我自己编写而不是echo,那么问题就解决了?我发现hextump-C也非常有用。我发现hextump-C也非常有用。