The df command report file system disk space usage including file names and directory names. The syntax is as follows:
In this example find out partition name for a file called /users/f/foo/file.txt, enter:
df
df /path/to/dir
df /path/to/file
$ df -T /users/f/foo/file.txt
Sample outputs:
Filesystem Type 1K-blocks Used Available Use% Mounted onThe above command indicates that the file called "/users/f/foo/file.txt" belongs to /dev/sda5 partition. The following command only shows partition name:
/dev/sda5 ext4 472439072 146088944 302351616 33% /
OR
df /users/f/foo/file.txt | awk '/^\/dev/ {print $1}'
Sample outputs:
awk '/^\/dev/ {print $1}' <<<"$(df /users/f/foo/file.txt)"
/dev/sda5I recommend that you place the following bash function in your ~/.bashrc file
Sample usage:
# find partition name for a given filename
findpart() { [ -e "$1" ] && df -P "$1" | awk '/^\/dev/ {print $1}' || echo "$1 not found"; }
$ findpart /foo/bar
$ findpart /etc
$ findpart /home/vivek/test.txt
Sample session:
No comments:
Post a Comment