0

What is the main difference between a temporary file ("tempfile") and a regular file in Linux?

The only main difference I recon between these two inodes is that in general, a "temporary file" has a much shorter life cycle than a "regular file", from whatever reason, while both are by principle, practically temporary (at least from the fact this universe is heading to a total heat death).

References:

  1. How does a pipe differ from a temporary file?

  2. How does a FIFO (named pipe) differs from a regular pipe (unnamed pipe)?

  • Feel free to answer your own question, but please separate the Question and the Answer. Don't answer it in the question. This way, others can upvote (or downvote) your answer independently of the question you've asked. – roaima Apr 11 '18 at 12:17
  • I agree, no problem, I just wanted to say what I understand so far. – user9303970 Apr 11 '18 at 12:20
  • "practically temporary"? Some files in my /etc/ are many years old, both by mtime and ctime. I'd hardly call them temporary in practice. – ilkkachu Apr 11 '18 at 12:31
4

There is absolutely no difference between a temporary file and a regular file.

A temporary file is a regular file, and a regular file is "regular" as opposed to being a directory, or a device special file, or named pipe etc.

The only difference is, as you point out, the typical use of the file. When a program or script creates a "temporary file", it is typically a regular file that is used to store temporary data that is not needed beyond the lifetime of the process that created it. Such files are often created in $TMPDIR.

POSIX defines:

File: An object that can be written to, or read from, or both. A file has certain attributes, including access permissions and type. File types include regular file, character special file, block special file, FIFO special file, symbolic link, socket, and directory. Other types of files may be supported by the implementation.

Regular file: A file that is a randomly accessible sequence of bytes, with no further structure imposed by the system.

It does not, however, care to say anything about the definition of a "temporary file", because it's not a specific file type (rather, a way of using regular files).

1

There is no technical difference between a temporary file and a regular file.

Semantically it would be reasonable to assume the following statements:

  1. A temporary file should be short-lived
  2. A temporary file may be intentionally deleted from the filesystem (by the application itself) while it is still in use
  3. A long-lived temporary file may be unexpectedly deleted from the filesystem (by a cleanup process) while it is still in use
  4. A temporary file should usually be created under /tmp or /var/tmp

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.