File (concept)

From LQWiki
(Redirected from Files)
Jump to: navigation, search

Files are ordered sequences of bytes -- no other interpretation is imposed at the operating system level, although particular applications may depend on the details of formatting. They are connected to programs through the kernel, which mediates capabilities and enforces permissions limits. Such a connection is called a file descriptor. It is common to 'wrap' each file descriptor with a file stream to enable more sophisticated capabilities. In either case, there are functions read, write, and seek, although they may not work on all files. Some files are not capable of seeking. Some files may only be readable, or only be writable.

This flexibility is exploited in the kernel and shells to implement pipes and devices, thus the saying "everything is a file".

Files are accessed through directory entries, each of which points to an inode. The inode contains a set of permissions and attributes such as the file type, and perhaps its length and location.Also, if the filesystem supports it, extended attributes may be present. Extended attributes are obviously not part of the original unix design, but useful. They are essentially arbitrary name:value pairs attached to a file, typically used by advanced security systems in the OS.

You can find out the type of a file using the command in its directory

ls -l

The file type is the first character on each line

-   ordinary file
d   directory
      hard link (shown as the file's type, but multiple links are counted in the second column)
l     soft link
s   socket (internet connection)
p   named pipe (aka FIFO
    special device
b     block special device (disk, pen drive, etc)
c     character special device (memory(!), sound, microphone, keyboard, monitor, GPS receiver, printer, etc.)

All of this information except the filename itself is contained the inode, although some of it may be duplicated in the directory entry on some systems.

See Also

  • mknod create special inodes
  • chmod change permissions (also known as "mode bits")
  • lsattr list extented attributes
  • chattr change extended attributes
  • acl access control list -- a more advanced form of permissions.