5

The command df [-h] gives the used/remaining space on all disks.

Can I somehow pipe this output to a different command and get the usage for my current disk (current disk = disk where my current working directory) is located?

1
  • 4
    df reports on filesystems, not disks. If you need to know the usage of the entire disk, you'll likely need to do some scripting to sum the usage of each partition (and do something sensible with unused/swap/other-os partitions). Dec 9, 2022 at 13:50

2 Answers 2

17

You can tell df to operate on any directory you like; thus

df -h .

will report the available space on the filesystem containing the current directory.

0
-1

where my current working directory) is located?

running du -sh in your current working directory gives very simple and direct output of how much space is in and under the current working directory... as in 26M for example when I do it in my current working directory that has like couple subfolders and a handful of text files.

unless you must use df for some reason, based on what you are asking it sounds like you should be using du instead

also : https://www.redhat.com/sysadmin/du-vs-df

The (very complicated) answer can be best summarized like this: The df command provides a sweeping ballpark figure for how much space is being utilized on your filesystem as a whole. The du command is a much more accurate snapshot of a given directory or subdirectory.

and : How to remember the difference between du and df?

2
  • thanks ron for your answer. However, no, I should not be using du since I did not need " direct output of how much space is in ". I needed exactly what df does. I just did not want to parse it using a shell script and filter out for the current disk. Stephen's answer does exactly what was needed in a very clearn fashion. Dec 8, 2022 at 14:48
  • 4
    The du command is a much more accurate snapshot of a given directory or subdirectory The problem is deleted files aren't in any "directory or subdirectory" so du misses them. That completely kills the accuracy of du on a file system level. Dec 8, 2022 at 21:48

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.