-1
$
$  echo "abcd" > a.txt
$  echo "abcd" > aaaaaaaaaaaaaaaaaaaaaaaa.txt
$
$  sha256sum a*
fc4b5fd6816f75a7c81fc8eaa9499d6a299bd803397166e8c4cf9280b801d62c  a.txt
fc4b5fd6816f75a7c81fc8eaa9499d6a299bd803397166e8c4cf9280b801d62c  aaaaaaaaaaaaaaaaaaaaaaaa.txt
$
$  ls -hl
total 0
-rwxrwxrwx 1 erh-unix erh-unix 5 Sep 27 11:13 a.txt
-rwxrwxrwx 1 erh-unix erh-unix 5 Sep 27 11:13 aaaaaaaaaaaaaaaaaaaaaaaa.txt

I created two files: a.txt and aaaaaaaaaaaaaaaaaaaaaaaa.txt, the contents of each are the ascii characters abcd

The filenames are different, the content is identical. Yet they both take up the same space (5 bytes), and both have the exact same sha256 hash.

Where are filenames stored for each of these files?

4
  • 4
    The filenames are not part of their content hence neither size nor hash depends on the filename.
    – tkausl
    Commented Sep 27, 2023 at 18:25
  • 3
    Depends on the filesystem. Here's a reference for ext4 since you look to be using linux ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout
    – squillman
    Commented Sep 27, 2023 at 18:30
  • I think tjis is a perfectly reasonable question and should be reopened.
    – davidgo
    Commented Sep 27, 2023 at 23:36
  • 2
    I don't, it reads like "I got a red and a blue cup. Why does ice melt?" Commented Sep 28, 2023 at 14:02

1 Answer 1

3

In a Linux filesystem (i.e: ext4), the filename of a file is typically stored in the directory entry for that file.

The actual content of the file, on the other hand, is stored in data blocks within the filesystem.

To link them, the filesystem uses an inode (index node) structure. This includes information (metadata) such as the size, permissions, timestamps, and ownership.

For listing the directory entries and their associated inode, you may run ls -i

The "sha256sum" function solely computes the hash value of the content of a file (the stream of data returned by the filesystem calls to the relevant underlying data blocks). This computation excludes any metadata associated with the file present in the directory entries and inode structure.

0

Not the answer you're looking for? Browse other questions tagged .