By trial and error I have found that the following values can be returned by stat "$somepath" --format '%F'
:
regular file
directory
symbolic link
I wish to use stat
to perform recursive directory contents operations and I wish to ensure that I can correctly identify every possible file type. Hardlinks appear to behave as I assumed and stat
returns the target type.
This information does not appear in my man
page; it only says: %F file type
(and it warns that stat
may vary between shells; it would be nice if this particular usage were portable but I'm primarily focused on bash
)
Is this list complete and is stat allowed to change what text it produces in this case depending on the execution environment or version?
NB: I am not knowledgeable about linux, filesystems or commands so I may have missed something obvious here
Beware: the output of stat is convention based and different versions of stat (from different authors and historical usage) as well as different releases of the same stat can and do return different outputs.
The file types that I can remember actually seeing when working with files (YMMV) are:
In general if you care about what the files are it is much better to use a file handling library in a programming language of your choice which will have had some development to be able to accurately identify a file; using command lines and scripts is not a very robust way of doing things
Here are some links to mainly the gnu implementation of stat if you want to dig deeper:
Old GNU Findutils documentation