0

I know that ls lists the names of the files in a given directory and ls -i shows the names and the inode numbers.

But why is it slower?

EDIT: This happens with big directories

The names and the inode numbers are stored in the directory information block together, hence why does it take more time to query the inode numbers?

  • 2
    All the information is not lumped together, and you are not telling us how big is your directory. I suspect you are dealing with a very big directory, slow machine/VM lacking on RAM maybe? If you add more data to your questions, you may get more interesting answers. – Rui F Ribeiro Jul 21 '18 at 4:02
  • @RuiFRibeiro, the file names and inode numbers are together in the directory contents, they kinda need to be since the point of a directory is to tell the inode number corresponding to a name... Also, of course it only happens on big directories: on small ones nobody would notice! – ilkkachu Jul 21 '18 at 6:29
  • @ilkkachu Yeah, I know, but the inodes are not...late night comment. – Rui F Ribeiro Jul 21 '18 at 7:16
  • @RuiFRibeiro, the difference between ls and ls -i is just that the latter prints the inode numbers too, it shouldn't need the contents of the inodes any more than plain ls does or doesn't. – ilkkachu Jul 21 '18 at 9:10
8

strace shows me that ls -i is calling lstat() on each filename

That would explain the extra work.

Given that readdir() has already returned the inode number this appears to be sub-optimal

while this feels like a bug, this behaviour is for consistency with mount points. (see Thomas' comment)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.