In this post I want to list some useful commands to determine specific file system information you sometimes need to manipulate disks, partitions or the file system.

I will update this post on a regular basis.

About extending disk, LVM Logical Volumes and the File System you can also read my following post.

Determine mounted Disk/Partition for a specific given Folder or File in Linux

In case you need to extend a partition or logical volume where a specific folder or file is located, you can use the following commands to quickly determine on which partition or logical volume they are finally located.

df -P /testing/folder1/testfile.txt | tail -1 | cut -d' ' -f 1

-P --portability flag -> Use the POSIX output format. This is like the default format except that the information about each filesystem is always printed on exactly one line; a mount device is never put on a line by itself. This means that if the mount device name is more than 20 characters long (e.g., for some network mounts), the columns are misaligned.


So below if I need to extend the disk, partition or logical volume where e.g. my folder /testing or the file /testing/folder1/testfile.txt is located, I can execute the above commands. Because for /testing is not directly mounted a disk, we won’t see this on the first sight by executing just the df -h command.

Two related commands that every system administrator runs frequently are df and du. While du reports files’ and directories’ disk usagedf reports how much disk space your filesystem is using. The df command displays the amount of disk space available on the filesystem with each file name’s argument.

For a good overview of the du command, read Tyler Carrigan’s article Linux commands: du and the options you should be using. You might also be interested in my article Make du’s output more useful with this neat trick.


Determine the size of a specific Folder in Linux

To determine the size of a specific folder you can use the du command as shown below.

# du -sh /testing/folder1

-s --summarize flag -> display only a total for each argument
-h --human-readable -> print sizes in human readable format (e.g., 1K 234M 2G) 

The du command is a standard Linux/Unix command that allows a user to gain disk usage information quickly. It is best applied to specific directories and allows many variations for customizing the output to meet your needs.



Check your disk space use with the Linux df command

Linux commands: du and the options you should be using