Folder /var/log/something may have 1 file (test.log) in it or 1000000 different files (and test.log of course). Is there a time difference while accessing file test.log with realpath between those two amounts of files?

for example:

less /val/log/something/test.log

It depends on your filesystem and how it manages directories, but modern filesystems (including ext4) will have an indexed directory structure; so accessing one file in that directory should be quite fast whether there's one or a million files in that directory.

There will be some variation, but not enough to really matter.

Obtaining a list of the files in the directory is another matter entirely, as then the entire index tree needs to be walked.

  • Ok,Thx for that :) . Are You aware of how unix is parsing the file realpath? Is the whole path a one , single memory pointer (etc.) or it's a bunch of pointers (or inodes address) – Mr.TK Jan 22 '15 at 11:12
  • All realpath does is canonicalize the name by removing ./ sequences, resolving ../ parts, and following symlinks. All of that has nothing to do with how many files are in the resulting directory. Your "example" less /val/log/something/test.log also doesn't have anything to do with realpath, so I don't know what you're really asking by supplying that example... – wurtel Jan 22 '15 at 11:16
  • Sorry, You are right. By using realpath I meant fullpath (from OS root folder). – Mr.TK Jan 22 '15 at 11:20
  • 1
    The inode that belongs to the file has to be found. Directories are also inodes. The directory tree is descended one by one (each time performing a lookup for a subdirectory, which in all sane filesystems does some kind of a tree search, meaning a logarithmic dependence on the number of file entries). The last lookup finds the inode of the file (and again, lookup time should increase logarithmically with the number of files in a directory). Thus, a full path lookup may take a tiny bit more time (walking the parent branches) than a relative lookup, but shouldn't be noticeable. – orion Jan 22 '15 at 11:28

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.