Skip to main content

List Hive Table Sizes in HDFS with a Single Shell Command

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

Why Is Customer Obsession Disappearing?

Many companies trade real customer-obsession for automated, low-empathy support. Through examples from Coinbase, PayPal, GO Telecommunications and AT&T, this article shows how reliance on AI chatbots, outsourced call centers, and KPI-driven workflows erodes trust, NPS and customer retention. It argues that human-centric support—treating support as strategic investment instead of cost—is still a core growth engine in competitive markets. It's wild that even with all the cool tech we've got these days, like AI solving complex equations and doing business across time zones in a flash, so many companies are still struggling with the basics: taking care of their customers. The drama around Coinbase's customer support is a prime example of even tech giants messing up. And it's not just Coinbase — it's a big-picture issue for the whole industry. At some point, the idea of "customer obsession" got replaced with "customer automation," and no...

How to scale MySQL perfectly

When MySQL reaches its limits, scaling cannot rely on hardware alone. This article explains how strategic techniques such as caching, sharding and operational optimisation can drastically reduce load and improve application responsiveness. It outlines how in-memory systems like Redis or Memcached offload repeated reads, how horizontal sharding mechanisms distribute data for massive scale, and how tools such as Vitess, ProxySQL and HAProxy support routing, failover and cluster management. The summary also highlights essential practices including query tuning, indexing, replication and connection management. Together these approaches form a modern DevOps strategy that transforms MySQL from a single bottleneck into a resilient, scalable data layer able to grow with your application. When your MySQL database reaches its performance limits, vertical scaling through hardware upgrades provides a temporary solution. Long-term growth, though, requires a more comprehensive approach. This invo...

What the Heck is Superposition and Entanglement?

This post is about superposition and interference in simple, intuitive terms. It describes how quantum states combine, how probability amplitudes add, and why interference patterns appear in systems such as electrons, photons and waves. The goal is to give a clear, non mathematical understanding of how quantum behavior emerges from the rules of wave functions and measurement. If you’ve ever heard the words superposition or entanglement thrown around in conversations about quantum physics, you may have nodded politely while your brain quietly filed them away in the "too confusing to deal with" folder.  These aren't just theoretical quirks; they're the foundation of mind-bending tech like Google's latest quantum chip, the Willow with its 105 qubits. Superposition challenges our understanding of reality, suggesting that particles don't have definite states until observed. This principle is crucial in quantum technologies, enabling phenomena like quantum comp...