All files are a sequence of bytes under the hood. It doesn't matter what is in them. The system only needs to know how many bytes there are in the file, and to arrange for a place to store these bytes. Whatever the contents of the file are, it's a bunch of bytes.
For each file, the system also stores some metadata. The metadata is independent of the content of the file; in fact, you could say that the content is one of these metadata items (but it's usually considered separately, because the content has a variable size and can potentially be very large). What metadata is stored depends on the filesystem type. Unix filesystems typically provide what you see in ls
: permissions, a modification time, and so on. The file's name is also a piece of metadata with a somewhat special status: it is unique, i.e. there cannot be two files with the same name (in the same directory).
Files are organized in directories. A directory can contain regular files, subdirectories and some special file types such as symbolic links. There is a directory called the root directory which all directories are subdirectories of n times removed.
The path to a file indicates how to find it starting from the root directory. Each directory to be traversed is given in turn, going from the root downwards, with slash /
characters after each directory name. For example, /usr/bin/env
means to start at the root directory /
, go to the usr
subdirectory there, go to the bin
subdirectory there, and look up the entry env
in that subsubdirectory.
When you list the content of a directory, the kernel (which includes the filesystem drivers) does the job of reading the bytes that represent the directory on the disk, and converting that into a list of file names and metadata and content location. The ls
program calls a function called opendir
to open the directory, then makes repeated calls to readdir
to read each entry in the directory in turn, i.e. to obtain the list of file names in that directory (including the subdirectories and other special files). With ls -l
, the ls
program needs more information about the file than just the name, so it also calls stat
to retrieve each file's metadata.
Some operating systems let you view the on-disk representation of a directory with any text viewing program such as cat
. Linux doesn't let you though. You can use the debugfs
program to explore the filesystem (use it only in read-only mode!).
ls
lists file names and meta data. The file content or operating system that created the file does not matter at all.