How to check size of HDFS directory

+1 vote

In case of Linux filesystems we use du -sh. But is there any way to check directory size in case of HDFS?

May 3, 2018 in Big Data Hadoop by kurt_cobain
• 9,350 points
51,294 views

12 answers to this question.

+1 vote

You can view the size of the files and directories in a specific directory with the du command. The command will show you the space (in bytes) used by the files that match the file pattern you specify. If it’s a file, you’ll get the length of the file. The syntax of the du command is as follows:

hdfs dfs -du -h /"path to specific hdfs directory"

image

Note the following about the output of the du –h command shown here:

The first column shows the actual size (raw size) of the files that users have placed in the various HDFS directories.

The second column shows the actual space consumed by those files in HDFS.

Hope this will answer your query to some extent.

For details, You can even check out Hadoop Ecosystem tools with the Hadoop big data course.

answered May 3, 2018 by nitinrawat895
• 11,380 points
0 votes
hdfs dfs -du [-s] [-h] URI [URI …]

answered Dec 7, 2018 by Nishant
0 votes

hadoop fs -du -s -h /path/to/dir

answered Dec 7, 2018 by abhijeet
0 votes

To get the size in Gb, you can try this:

hdfs dfs -du PATHTODIRECTORY | awk '/^[0-9]+/ { print int($1/(1024**3)) " [GB]\t" $2 }'
answered Dec 7, 2018 by Narayan
0 votes
hadoop fs -du /user/hadoop/dir1 \
    /user/hadoop/file1 \
    hdfs://domain.com/user/hadoop/dir1 
answered Dec 7, 2018 by Nisha
0 votes
hdfs dfs -du -s -h /$DirectoryName
answered Dec 7, 2018 by Chunnu
0 votes

Using the following command, you'll get the size in %:

sudo -u hdfs hadoop fs –df
answered Dec 7, 2018 by Khush
0 votes

To check the size under a particular directory:

sudo -u hdfs hadoop fs -du -h /user
answered Dec 7, 2018 by Bunty
0 votes
hdfs dfs -du -s dir_name
answered Dec 7, 2018 by Yadav
0 votes

Another way to show size in GB:

hadoop fs -dus  /path/to/dir  |   awk '{print $2/1024**3 " G"}' 
answered Dec 7, 2018 by Anil