Question: What Is Offset in Linux?
Contents

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).

What is offset of a file?

An offset into a file is simply the character location within that file, usually starting with 0; thus “offset 240” is actually the 241st byte in the file. See relative address. (3) In word processing, the amount of space a document is printed from the left margin.

How do I find the offset of a file?

To get the current offset of an open file, you use lseek() :

  1. off_t offset;
  2. offset = lseek (fd, 0, SEEK_CUR);
  3. if (offset == (offset_t) -1) {
  4. perror(“lseek”);
  5. return -1;
  6. }
  7. printf(“fd is currently at offset %jdn”, (intmax_t) offset);
Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest