10

What is the difference between directory structure and file system?
Unix/Linux directories and file system looks as follows:

The following two directories obviously we know directories.

  /home/abc/xyzdir1 --is a directory
  /home/abc/xyzdir2 -- is a directory

the following three samples are saying file system.

/proc -- is a file system
/ -- is a file system
/bin -- is a file system

How can I identify which one is a file system and a directory from the above code snippets?

3
  • A filesystem contains one or more directories. Every directory is part of a filesystem (including /proc, /, and /bin from your examples), so I'm not clear how you want to identify the "difference". Commented May 18, 2015 at 13:18
  • @roaima please find code snippet for sample Commented May 18, 2015 at 15:29
  • Your question is still ambiguous. /proc, / and /bin are directories. They are not "filesystems". Do you perhaps mean you want to identify which directories are also the mount point (root) of their filesystem? Commented May 18, 2015 at 18:02

8 Answers 8

8

People don't use file system too carefully. In your examples, I would say that /, /bin and /proc are file systems because an entire partition (like /dev/sdb1) is mounted on those directories. My Arch linux system doesn't have /bin as a file system so this example isn't perfect but...

% ls -lid /proc /home /boot /
2 drwxr-xr-x  17 root root 4096 Feb 24 12:12 //
2 drwxr-xr-x   4 root root 4096 May 16 14:29 /boot/
2 drwxr-xr-x   5 root root 4096 Mar 14 18:11 /home/
1 dr-xr-xr-x 116 root root    0 May 16 17:18 /proc/

Inode number 2 is traditionally the "root" inode of an entire on-disk file system (which is the other usage of the phrase). /, /boot and /home all have inode number 2, while /proc, which is presented entirely by the kernel and does not have an on-disk presence, has inode 1. Those inode numbers indicates that a whole, on-disk file system, or a virtual file system is mounted using that name.

The sentence '/home/abc/xyzdir1 is a directory" basically means that no on-disk file system is mounted using that name. If you do the same ls -lid command on a directory you get something like this:

 % ls -lid /home/bediger/src
3670039 drwxr-xr-x 29 bediger bediger 4096 May 17 19:57 /home/bediger/src/

Inode number 3670039 is just whatever inode got allocated from in the on-disk file system mounted (on my machine) at /home.

You could also find file systems by invoking the mount command. It lists all mounted file systems and where they are mounted.

3
  • The "magic inode" number is specific to the ext2 series of filesystems. It does not apply to most ( all? ) others, such as xfs or btrfs. Commented May 18, 2015 at 21:03
  • I would say that /, /bin and /proc are file systems because an entire partition ... is mounted on those directories. This is not true for /proc, as the answer later implies. Commented May 18, 2015 at 22:12
  • 1
    @MaxNanasy - given that two meanings of "file system" are in common use (1. The names and arrangement of directories in a tree structure, and 2. The on-disk format and layout of file and directory structured data, along with the code to maintain and use it), it's pretty hard to come up with a term that's both comprehensible, not defined in a circular fashion, and technically correct. I chose to go with comprehensible and used "partition" instead of other terms. I invite you to suggest term(s) that are more correct, I'm at a loss. Commented May 18, 2015 at 22:21
4

At the risk of grossly oversimplifying,

  • A filesystem is like your car's engine and other internal systems,
  • A directory structure is like a map of the places where you drive.

Since I’ve been asked for an encore,

  • Filesystems are like the mechanics (implementation details) of audio/video signal distribution/propagation: analog RF broadcast, digital RF broadcast, cable, Internet, video tape, video disk, etc.
  • Directory structure is like the content of television programming, and the categorization thereof, e.g., into comedy, drama, news, documentaries, games shows, sports, etc.

If you want code, see the first half of this answer to How to determine whether a Linux filesystem belongs to a running system — the part that does validation checks on root_dir.  It’s just doing what Bruce said; verifying that it is a directory and checking whether its inode number is 1 or 2.

1
  • 1
    Good ELI5, but could you add a code snippet answering How can I identify which one is a file system and a directory? Commented May 18, 2015 at 13:16
4

The way I see it, a filesystem, in the UNIX sense, is a way of implementing a directory tree (directory structure), or more precisely, a way of implementing the UNIX filesystem API. The root file system is backed by one particular implementation, and whenever you enter a mountpoint directory, you enter a subtree that's backed by something different.

The interface is always the same, but in one case, you have a particular disk partition at the back end, in another case, there will be a program that never even writes to a storage device. The proc filesystem will be backed by software that exposes kernel internals; an tmpfs will be backed up by software that writes to RAM, and other file systems might write to the network or elsewhere.

In the non-UNIXy sense of the word, a file system is a way of organizing data storage. ext4, btrfs, fat, and ntfs are file systems in this sense, but also in the UNIXy sense—they implement the filesystem API. proc wouldn't classify as a filesystem within this, more limited, paradigm as it doesn't organize data storage.

TL;DR:

  • directory structure/tree = front end
  • file system = back end
0
2

While directory acception is unambiguous when talking about file systems, file system might mean different things depending on what you are talking about.

In your examples, all the listed paths are directories but only some of them are also mount points of file systems.

You can use the df command to known on what file system a given file or directory is, and the mount command on most Unix and Linux implementations to figure out what file systems are present on your machine, their type and their mount points. eg:

$ df /proc
Filesystem     1K-blocks  Used Available Use% Mounted on
proc                   0     0         0    - /proc
$ mount | grep -w /proc
/proc is a file system of type proc

The statement /bin is a file system is dubious, /bin is almost always mounted on /.

$ df -k /bin
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sda5      206292664 180687360  15103212  93% /
$ mount | grep -w /
/dev/sda5 on / type ext4 (rw,errors=remount-ro)
1

First a correction to your assumption about a filesystem and a directory. A filesystem contains one or more directories. Using your examples, /proc, / and /bin are directories. They are not "filesystems" in and of themselves, but they might be the root of their respective filesystems.

If you want to identify which directories are also the mount point (root) of their filesystem you can use something like this:

F="$PWD"    # The directory to be tested
if test -d "$F"
then
    echo "$F is a directory"
    test "X$(stat --format '%m' "$F")" = "X$PWD" && echo "$F is a mountpoint"
fi
1

If you just need a command that tells you if path is a directory or not use mountpoint(1).

For me it prints

$ mountpoint /
/ is a mountpoint
$ mountpoint /bin
/bin is not a mountpoint
$ mountpoint some-file
some-file is not a mountpoint

The good thing is that the exit status indicates the same again so you can use it in your scripts like this:

if mountpoint "$foo" >/dev/null; then
  : do mountpoint stuff
elif [ -d "$foo" ]; then
  : do directory stuff
elif [ -e "$foo" ]; then
  : do file stuff 
else
  echo "$foo does not exist!" >/2
fi
1

File System is a methodology for logically organizing and storing large quantities of data such that the system is easy to manage. a file system consists of files, relationships to other files, as well as the attributes(file type, file name, file size, file owner, file timestamp) of each file.

Directories: for example, the Unix file system is essentially composed of files and directories. Directories are special files that may contain other files. the top-most directory is / (slash), with the directories directly beneath being system directories. [![enter image description here][1]][1]

/ Root of Linux Filesystem

/bin contains binary executable files that are used by all users on the system.

/boot contains files that are used during the boot process of the system.

/dev contains files that represent devices on the system, such as hard drives, CD-ROM drives, and network interfaces.

/etc contains configuration files for the system and installed software

/home Location for the home directories of regular users

/lib contains library files that are used by programs on the system

/mnt directory is used to mount file systems temporarily, for DVD-Rom, USB flash drive.

/opt contains optional software that is not part of the core system.

/proc short for "process", Kernel pseudo(i.e. virtual) filesystem contains information about running processes and the system itself for example, '/proc/cpuinfo', '/proc/meminfo'.

/root Home directory of super user root

/sbin contains binary executable files that are used by the system administrator.

/tmp Temporary files are kept here

/usr contains a variety of files and directories that are used by users and system administrators, such as documentation, library files, and other resources.

/var contains variable files that change over time, such as log files and spool directories.

/srv directory is typically used to store data that is served by the system, such as web pages, email, and file transfer data.

1
  • That diagram is woefully out of date. FHS 3.0 was released in June 2015. It should also be noted that FHS applies only to Linux distributions. Commented Feb 22, 2017 at 4:08
-1
  • Directory is nothing but a another file type. Every file has a inode number
  • Disk copy is called: inode
  • In-memory copy of the same inode is called: in-core inode
  • In-core inode has additional details than its disk copy
  • In-core inode is the place where the kernel makes entry so that we can differentiate the difference b/w a regular directory and mount-point. One of the in-core inode field is "mounted-on". If this is set, then this directory is a mount-point. Any further access to this directory should be consulated with "mount table", translate request into mapped file system and proceed further if this is not set, it is still a regular directory under the current file-system it holds.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.