7

I was using lsof to track down deleted files that were still taking up space and I realized that I wasn't quite sure what an offset is with respect to a file. lsof's man page was less than helpful in this regard and searching around I couldn't get a clear picture of what it is.

What is a file offset and why is it useful to have that piece of information?

2 Answers 2

9

The offset is the current position in the file, as maintained by the kernel for a given file description (see the lseek(2) and open(2) manpages for details).

As to why it's useful in lsof's output, I'm not really sure. It can give some idea of a process's progress through a file, although it won't cover all cases (memory-mapped files won't show offset changes).

6

Stephen Kitt's answer is close, but not quite correct; if we read lseek(2) more carefully, we will see that it actually says (bold mine):

The lseek() function repositions the file offset of the open file description associated with the file descriptor fd [...]

So, what's an "open file description" and how does it relate to a "file descriptor"?

Well, down in the NOTES section, we find:

See open(2) for a discussion of the relationship between file descriptors, open file descriptions, and files.

Perfect! However, rather than pasting a wall of text from the manpage, I'll just link to a good answer to "What is an open file description?" that explains the same thing.

You must log in to answer this question.

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