Skip to main content

List Hive Table Sizes in HDFS with a Single Shell Command

Struggling with delivery, architecture alignment, or platform stability?

I help teams fix systemic engineering issues: processes, architecture, and clarity.
→ See how I work with teams.


This quick tip shows how to list all Hive tables in a database together with their HDFS locations and human-readable sizes using a single bash one-liner. It still works on classic Hive CLI setups and can be adapted easily for Beeline or modern Hive deployments.

When you run benchmarks, clean up old data or just want to understand how much space each Hive table consumes, it is useful to see HDFS locations and sizes side by side. Instead of clicking through UIs, you can ask Hive for every table location and then call hdfs dfs -du -h on each path.

The Hive + HDFS one-liner

The following bash one-liner queries Hive for table locations, extracts the HDFS paths and then prints a human-readable size for each table directory:

for file in $(hive -S -e "SHOW TABLE EXTENDED LIKE '\*'" \
  | grep "location:" \
  | awk 'BEGIN { FS=":" } { printf("hdfs:%s:%s\n",$3,$4) }'); do
  hdfs dfs -du -h "$file"
done

Typical output looks like this (shortened):

Time taken: 2.494 seconds
12.6m  hdfs://hadoop1:8020/hive/tpcds/customer/customer.dat
5.2m   hdfs://hadoop1:8020/hive/tpcds/customer_address/customer_address.dat
76.9m  hdfs://hadoop1:8020/hive/tpcds/customer_demographics/customer_demographics.dat
9.8m   hdfs://hadoop1:8020/hive/tpcds/date_dim/date_dim.dat
...
3.1m   hdfs://hadoop1:8020/user/alexander/transactions/part-m-00003
1.9m   hdfs://hadoop1:8020/user/hive/warehouse/zipcode_incomes_plain/DEC_00_SF3_P077_with_ann_noheader.csv

What the command does

  • hive -S -e "SHOW TABLE EXTENDED LIKE '\*'" asks Hive for metadata of all tables in the current database.
  • The output contains lines like location:hdfs://hadoop1:8020/....
  • grep "location:" keeps only those lines.
  • awk 'BEGIN { FS=":" } { printf("hdfs:%s:%s\n",$3,$4) }' rebuilds a clean HDFS URL from the colon-separated parts.
  • The for loop iterates over each location and calls hdfs dfs -du -h to print the size in a human-readable format.

Adapting it for Beeline and specific databases

On newer clusters you might prefer Beeline and HiveServer2. The pattern stays the same; only the Hive call changes. For example:

for file in $(beeline -u "jdbc:hive2://hs2-host:10000/default" --silent=true \
  -e "USE tpcds; SHOW TABLE EXTENDED LIKE '\*'" \
  | grep "location:" \
  | awk 'BEGIN { FS=":" } { printf("hdfs:%s:%s\n",$3,$4) }'); do
  hdfs dfs -du -h "$file"
done

Key tweaks:

  • Add USE your_db; before SHOW TABLE EXTENDED if you only want table sizes for a single database (for example, tpcds).
  • Use --silent=true or similar options so Beeline outputs only query results, not banners.

Limitations and caveats

  • This inspects the table location directory, not logical row counts or column sizes.
  • Partitioned tables may have many subdirectories; the HDFS -du output will reflect the total across all files under the path.
  • If you are heavy on external tables, make sure you understand that sizes may include shared locations used by multiple tables.
  • On large warehouses, running du for every table will generate some load on the NameNode and DataNodes; use with care in peak hours.

When to still use this approach

Even with modern observability, table statistics and catalogs, a small shell snippet like this remains useful for quick sanity checks, cluster cleanups, migration planning or just understanding where your HDFS space went. It is simple, transparent and works anywhere you have Hive CLI or Beeline plus HDFS access.

If you need help with distributed systems, backend engineering, or data platforms, check my Services.

Most read articles

Building a Model-Agnostic Multi-Agent System with OpenClaw

Over one week we rebuilt our AI stack around OpenClaw’s multi-agent architecture to avoid provider lock-in and stop wasting premium tokens. By aligning models to tasks, diversifying fallbacks across providers, enforcing minimal tool access, and switching to memory-first workflows with ephemeral sessions, we reduced token usage per task by about 70% and cut our monthly bill by 77% while improving operational resilience. How We Achieved 77% Cost Reduction and Provider Independence Over the past week, we rebuilt our AI infrastructure around OpenClaw’s multi-agent architecture. The result was a 77% cost reduction , provider independence , and a delegation system that routes work to the most cost-effective model for each job. Below is the technical journey of optimizing a 7-agent squad with OpenClaw. The Challenge: Model Provider Lock-In We started with a simple problem: our entire squad defaulted to a single model provider. This created three issues: Cost inefficiency beca...

BacNet => MQTT in Production: The Real Cost of Bridging BACnet to MQTT at Scale

bacnet2mqtt looks simple in a README and expensive in production. Once BACnet polling, reconnection behavior, stale state, and MQTT publishing collide, teams discover they are not deploying a lightweight adapter but operating infrastructure. This article breaks down where bacnet2mqtt works, where it becomes a bottleneck, and which production patterns reduce the operational damage before incidents, backlogs, and silent data loss turn a building integration into a long-running engineering problem. I inherited a building controls integration problem 18 months ago. Three office floors. 217 BACnet sensors covering temperature, occupancy, and HVAC actuators. The data was trapped inside the building automation network while the business wanted analytics, reporting, and compliance visibility in the data platform. The obvious answer looked easy enough: deploy bacnet2mqtt, bridge BACnet into MQTT, and push the stream into the lakehouse stack. The repository made it sound like a w...

Get Apache Flume 1.3.x running on Windows

Since we found an increasing interest in the flume community to get Apache Flume running on Windows systems again, I spent some time to figure out how we can reach that. Finally, the good news - Apache Flume runs on Windows. You need some tweaks to get them running. Prerequisites Build system: maven 3x, git, jdk1.6.x, WinRAR (or similar program) Apache Flume agent: jdk1.6.x, WinRAR (or similar program), Ultraedit++ or similar texteditor Tweak the Windows build box 1. Download and install JDK 1.6x from Oracle 2. Set the environment variables    => Start - type " env " into the search box, select " E dit system environment variables ", click Environment Variables, Select " New " from the " Systems variables " box, type " JAVA_HOME " into " variable name " and the path to your JDK installation into "Variable value" (Example:  C:\Program Files (x86)\Java\jdk1.6.0_33 ) 3. Download maven from Apache 4. Set...