I don't understand the difference between path and directory. Could someone explain to me with examples?
A directory is a "folder", a place where you can put files or other directories (and special files, devices, symlinks...). It is a container for filesystem objects.
A path is a string that specify how to reach a filesystem object (and this object can be a file, a directory, a special file, ...).
Example: you have (probably, depending on your system) a file where system messages are logged, called
It normally sits in a directory named
log which is contained in a directory named
var which is in the root directory of your filesystem.
/var/log/syslog is a path to that file (an absolute path in that case), as
/var/log is a path to the directory that contains the file.
/var/spool/../log/syslog is also a path to the
syslog file too (if
Paths can be relative, too. So if your current directory is
/home/user, the path
../../var/log/syslog is a relative path to the same file, too (you know it's relative because it doesn't start with
And in your home directory, if you create a symlink to
/var/log like this:
ln -s /var/log myvarlog
myvarlog/syslog is another path to our file.
Directory is where you are.
Path is how to get there.
pages is a directory
/var/www/public/site/pages/ is the path to files in that directory. This is an absolute path.
/var/www/public/site/ is the path to that directory.
./pages/ may be a path to files in that directory, if you are currently working in
/var/www/public/site/. This is a relative path.
On Linux, The terminology "directory" usually have two different meanings:
A. Unopened directory. Part of a "normal"(can be used to store data freely, like tmpfs or ext4, not used to expose kernel functionality, like procfs or sysfs) filesystem, usually consist of uniquely named pointers to other parts of the filesystem(other files or directories).
B. Open file description of a directory. A kernel object, which is a handler to A or some sort of interface to a kernel functionality.
The terminology "Path" is just a string which let you refer to one instance of A when constructing an instance of B.