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?

4
  • 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. Commented Jul 21, 2018 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! Commented Jul 21, 2018 at 6:29
  • @ilkkachu Yeah, I know, but the inodes are not...late night comment. Commented Jul 21, 2018 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. Commented Jul 21, 2018 at 9:10

1 Answer 1

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)

3
  • 1
    I thnk it is a feature, not a bug Commented Jul 21, 2018 at 5:44
  • 5
    Actually it seems to be the bug fix: git.savannah.gnu.org/gitweb/… Commented Jul 21, 2018 at 6:24
  • 1
    Good detective work! Commented Jul 21, 2018 at 7:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.