I would like to know in what filesystem mount point I am currently on, similarly to using pwd to know what directory I am in.

I know you can use df . (or df $(pwd) or many variants), but I find it somehow overkilling to check the file system usage just to know where I am.

So: is there any command showing in what filesystem mount point I am?

  • alias fs="df . | awk 'NR==2{print \$1}'" :^) – confused00 Oct 30 '14 at 10:49
  • @confused00 thanks, but I am not looking for an alias or any workaround: the question is about the existence of a command (builtin maybe) to give this info straight ahead. – fedorqui Oct 30 '14 at 10:51
  • By “what filesystem”, do you mean the filesystem type (e.g. ext4, zfs, …), or the mount point (e.g. /, /home, …), or something else? – Gilles Oct 30 '14 at 23:25
  • @Gilles the mount point. Just updated to give more clarity. – fedorqui Oct 31 '14 at 9:17

I think df . is your best bet. The filesystem usage check is not that expensive (it doesn't have to count any blocks on disk, that information is readily available and stored in memory once the filesystem is mounted).

Alternatives like comparing the current path against mount points by using a script would be more expensive.

  • Interesting... so df does not perform any further calculation? Maybe it is off topic in this question but then, how often and by what procedure is the df info updated? – fedorqui Oct 30 '14 at 11:01
  • @fedorqui The filesystem "driver" keeps track of what blocks it allocates and frees for normal write operations. That information is stored on the disc as well (read in during mount, and can often be recalculated during a filesystem check), but normally a df doesn't have to go to disk to give you the number of Gb free on your disk or other data it displays. – Anthon Oct 30 '14 at 11:36
  • 1
    @fedorqui You may be interested in trying stat -f .. It produces some of the same information as df . but is a more "raw" presentation. Both stat -f and df obtain this information through a single system call, statvfs(), and this system call gives you the usage statistics along with the file system's identification. So even at the system call level, this information comes all together. The usage statistics are expected to be cheap to retrieve. – Celada Oct 30 '14 at 15:29
  • So 1) there is not a "direct" command for this 2) is not that expensive to run. That's what I wanted to know, many thanks! – fedorqui Oct 31 '14 at 13:25

Not sure what you mean by "what filesystem".

If it means what instance of a filesystem, then using df $(pwd) may be your best bet, except when you know that the file you are inspecting actually is a mountpoint on its own, than using mountpoint $(pwd) may be a better idea.

If it means what type of filesystem, then use the common Linux utility stat, it only inspects the files you are giving as arguments and it also supports printing filesystem informations given any type of file, just type

stat -f $(pwd)

If you need to retrieve the type of filesystem to a given file programmatically, try one of these:

LC_ALL=C stat -f $(pwd) | awk '/\<Type: /{print $6}'

sed or plain shell pattern expansion can also be used to parse the Type field from the output of stat.

  • Good one, also stat -f . makes it. Only that it prints the filesystem type, not its name. – fedorqui Oct 30 '14 at 10:56
  • Title is "Is it possible to know what filesystem am I currently working on?", I don't think it is that ambiguous :) – fedorqui Oct 30 '14 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.