How to find out which partition a File Belongs to In Linux

How do we find out which file are belongs to which partition on Linux Operating System?

I think all of us are Familiar with the Command DF

The df command displays information about total space and available space on a file system. The FileSystem parameter specifies the name of the device on which the file system resides, the directory on which the file system is mounted, or the relative path name of a file system. Try it as follows:

df
df -k $HOME
df -k /tmp
df -m /path/to/dir

The syntax is as follows:

df
df /path/to/directory
df /path/to/file

In this example find out partition name for a file called /home/johnson/test.sh, enter:

$ df -T test.sh

Sample outputs:


The above command indicates that the file called “/home/johnson/test.sh” belongs to /dev/vda1 partition. The following command only shows partition name:

df /home/johnson/test.sh | awk '/^/dev/ {print $1}'

OR

awk '/^/dev/ {print $1}' <<<"$(df /home/johnson/test.sh)"

Sample outputs:

/dev/vda1

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *