File types

There is a wide variety of checks which we can use to get information about a file and the filesystem. They have been explained in this lesson.

We'll cover the following

By using the following predicates, you can easily ask for the type of file.

{title=“The file types of the filesystem”}

file types Description
is_block_file Checks if the path refers to a block file.
is_character_file Checks if the path refers to a character file.
is_directory Checks if the path refers to a directory.
is_empty Checks if the path refers to an empty file or directory.
is_fifo Checks if the path refers to a named pipe.
is_other Checks if the path refers to another file.
is_regular_file Checks if the path refers to a regular file.
is_socket Checks if the path refers to an IPC socket.
is_symlink Checks if the path refers to a symbolic link.
status_known Checks if the file status is known.

Getting the type of a file

The predicates give you the information on the type of a file. More than one predicate may be right for one file. In the next example, a symbolic link referencing a regular file is both: a regular file and a symbolic link.

Get hands-on with 1000+ tech skills courses.