1

S_ISREG() is a macro used to interpret the values in a stat-struct. From man page it states :

S_ISREG(m)
is it a regular file?  // Macro checks, if the file is regular or not.

Questions :

  1. Which file formats are considered regular files in Ubuntu ?
  2. Which file formats are considered non-regulat files in Ubuntu ?

2 Answers2

4

To understand what is a "regular file" you need to understand that in UNIX-like operating systems, "everything is a file".

Basically, a regular file is any file that is not a special file.

To determine whether or not a file is a regular file or not, you can use the command:

ls -ld filename

If the first character of the output is a -, then it is a regular file.

Here are a few examples:

$ ls -ld /dev/null
crw-rw-rw- 1 root root 1, 3 Nov 24 22:26 /dev/null

$ ls -ld /home/ drwxr-xr-x 1 root root 512 Oct 10 21:56 /home/

$ ls -ld /etc/apt/sources.list -rw-r--r-- 1 root root 2743 Aug 4 14:42 /etc/apt/sources.list

/dev/null is a character device file.

/home is a directory.

/etc/apt/sources.list is a regular file.

Nmath
  • 12,664
1

Regular file is backend storage of data for userspace programs like text editor, mp3 player, video player, configs. While non regular files have very different purpose. For instance they are gateways between user program and physical device, or method for interprocess communication, or a pointer to some file in another directory.

Alex
  • 148