{"id":583,"date":"2012-02-28T05:05:40","date_gmt":"2012-02-28T11:05:40","guid":{"rendered":"http:\/\/blog.supportpro.com\/?p=583"},"modified":"2026-04-14T01:17:21","modified_gmt":"2026-04-14T07:17:21","slug":"how-to-find-total-size-of-all-files-under-the-ownership-of-a-user","status":"publish","type":"post","link":"https:\/\/www.supportpro.com\/blog\/how-to-find-total-size-of-all-files-under-the-ownership-of-a-user\/","title":{"rendered":"How to find total size of all files under the ownership of a user?"},"content":{"rendered":"\n<p>Linux servers often host multiple users and applications simultaneously. During execution, applications such as Apache or background services may generate temporary files, especially inside directories like <code>\/tmp<\/code>. Over time, these files can consume significant disk space and affect system performance.<\/p>\n\n\n\n<p>System administrators frequently need a method to identify <strong>which user is consuming disk space<\/strong> and calculate the <strong>total size of files created by that user<\/strong>.<\/p>\n\n\n\n<p>This guide explains how to find both <strong>individual file sizes and total disk usage<\/strong> for files owned by a specific user using a powerful combination of Linux commands.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Scenario<\/strong><\/h2>\n\n\n\n<p>Consider a domain hosted on a Linux server.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A user named <strong>test<\/strong> manages the domain.<\/li>\n\n\n\n<li>All domain files are stored inside the user\u2019s home directory:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>~test<\/code><\/pre>\n\n\n\n<p>While running applications or scripts, temporary files may be created inside the system\u2019s <code>\/tmp<\/code> directory. To monitor storage usage, we need to calculate:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Size of each file created by the user<\/li>\n\n\n\n<li>Total disk space used by all those files<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Command<\/strong><\/h2>\n\n\n\n<p>The following command performs this task:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \/tmp\/ -user test -type f -exec du -ch {} +<\/code><\/pre>\n\n\n\n<p>This single command searches for files owned by a user and displays disk usage statistics.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Understanding the Commands<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. <code>find<\/code> Command<\/strong><\/h3>\n\n\n\n<p>The <code>find<\/code> utility searches for files within a directory hierarchy.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \/path -options<\/code><\/pre>\n\n\n\n<p>In this case:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \/tmp\/<\/code><\/pre>\n\n\n\n<p>Searches inside the <code>\/tmp<\/code> directory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. <code>-user<\/code> Option<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>-user test<\/code><\/pre>\n\n\n\n<p>This option filters results to include only files owned by the specified user.<\/p>\n\n\n\n<p>Replace <code>test<\/code> with any username.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-user mobile<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. <code>-type<\/code> Option<\/strong><\/h3>\n\n\n\n<p>Defines the file type to search.<\/p>\n\n\n\n<p>Common file types include:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><div class=\"pcrstb-wrap\"><table class=\"has-fixed-layout\"><thead><tr><th>Option<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td><code>f<\/code><\/td><td>Regular files<\/td><\/tr><tr><td><code>d<\/code><\/td><td>Directories<\/td><\/tr><tr><td><code>l<\/code><\/td><td>Symbolic links<\/td><\/tr><tr><td><code>b<\/code><\/td><td>Block device files<\/td><\/tr><tr><td><code>c<\/code><\/td><td>Character device files<\/td><\/tr><\/tbody><\/table><\/div><\/figure>\n\n\n\n<p>In our command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-type f<\/code><\/pre>\n\n\n\n<p>Only regular files are selected, excluding directories.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. <code>-exec<\/code> Option<\/strong><\/h3>\n\n\n\n<p>The <code>-exec<\/code> option runs a command on files returned by <code>find<\/code>.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-exec command {} +<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>{}<\/code> represents the files found.<\/li>\n\n\n\n<li><code>+<\/code> groups files together when executing the command.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Understanding the <code>du<\/code> Command<\/strong><\/h2>\n\n\n\n<p><code>du<\/code> stands for <strong>Disk Usage<\/strong>. It reports how much disk space files occupy.<\/p>\n\n\n\n<p>Command used:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>du -ch<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Options Explained<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><div class=\"pcrstb-wrap\"><table class=\"has-fixed-layout\"><thead><tr><th>Option<\/th><th>Function<\/th><\/tr><\/thead><tbody><tr><td><code>-c<\/code><\/td><td>Displays grand total<\/td><\/tr><tr><td><code>-h<\/code><\/td><td>Human-readable output (KB, MB, GB)<\/td><\/tr><\/tbody><\/table><\/div><\/figure>\n\n\n\n<p>This provides readable size information along with the overall total.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Why Use <code>+<\/code> Instead of <code>;<\/code> in <code>-exec<\/code><\/strong><\/h2>\n\n\n\n<p>This is an important concept.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using <code>;<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>-exec du -ch {} \\;<\/code><\/pre>\n\n\n\n<p>Runs the command <strong>separately for each file<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>du -ch file1<br>du -ch file2<br>du -ch file3<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Shows size per file<\/li>\n\n\n\n<li>No combined total<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Using <code>+<\/code> (Recommended)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>-exec du -ch {} +<\/code><\/pre>\n\n\n\n<p>Runs the command once:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>du -ch file1 file2 file3<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Individual file sizes<\/li>\n\n\n\n<li>Grand total at the bottom <\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example Usage<\/strong><\/h2>\n\n\n\n<p>Suppose we want to check disk usage of files owned by user <strong>mobile<\/strong> inside:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/var\/mobile\/balu<\/code><\/pre>\n\n\n\n<p>Command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \/var\/mobile\/balu\/ -user mobile -type f -exec du -ch {} +<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Output<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>496K  \/var\/mobile\/balu\/books\/GhostStory.epub<br>1.4M  \/var\/mobile\/balu\/books\/TheWiseMansFear.epub<br>1.3M  \/var\/mobile\/balu\/books\/Wolfheart.epub<br>648K  \/var\/mobile\/balu\/books\/TalionRevenant.epub<br>104K  \/var\/mobile\/balu\/deb\/package.deb<br>3.0M  \/var\/mobile\/balu\/deb\/application.deb<br>293M  \/var\/mobile\/balu\/ipa\/appfile.ipa<br>6.7M  \/var\/mobile\/balu\/sng\/music.mp3<br>311M total<\/code><\/pre>\n\n\n\n<p>The final line shows the <strong>total disk usage<\/strong> of all files owned by the user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Practical Use Cases<\/strong><\/h2>\n\n\n\n<p>This command is extremely useful for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Monitoring <code>\/tmp<\/code> directory growth<\/li>\n\n\n\n<li>Identifying users consuming excessive disk space<\/li>\n\n\n\n<li>Cleaning temporary files safely<\/li>\n\n\n\n<li>Managing shared hosting environments<\/li>\n\n\n\n<li>Troubleshooting storage issues<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Pro Tips<\/strong><\/h2>\n\n\n\n<p>-> Run periodically using cron jobs for monitoring<br>->  Combine with <code>rm<\/code> carefully for cleanup automation<br>->  Use <code>sudo<\/code> if permissions restrict file access<\/p>\n\n\n\n<p>Example cleanup preview:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \/tmp -user test -type f<\/code><\/pre>\n\n\n\n<p>Always verify before deleting files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>Managing disk usage is an essential responsibility for Linux administrators. By combining the power of <code>find<\/code> and <code>du<\/code>, administrators can quickly identify how much storage a specific user consumes and prevent disk space issues before they affect system performance.<\/p>\n\n\n\n<p>The command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \/tmp\/ -user test -type f -exec du -ch {} +<\/code><\/pre>\n\n\n\n<p>provides a simple yet powerful way to monitor user-generated files and maintain server health efficiently.<\/p>\n\n\n\n<p>If you require help, <a href=\"https:\/\/www.supportpro.com\/requestquote.php\">contact SupportPRO Server Admin<\/a><\/p>\n\n\n\n<p class=\"has-text-align-center\"><span id=\"hs-cta-wrapper-9d590242-d641-4383-94b4-8cfd62f0af6b\" class=\"hs-cta-wrapper\"><span id=\"hs-cta-9d590242-d641-4383-94b4-8cfd62f0af6b\" class=\"hs-cta-node hs-cta-9d590242-d641-4383-94b4-8cfd62f0af6b\"><a href=\"https:\/\/cta-redirect.hubspot.com\/cta\/redirect\/2725694\/9d590242-d641-4383-94b4-8cfd62f0af6b\"><\/a><\/span><\/span><\/p>\n\n\n\n<div class=\"wp-block-media-text alignwide has-media-on-the-right is-stacked-on-mobile is-vertically-aligned-center has-white-background-color has-background\"><div class=\"wp-block-media-text__content\">\n<p class=\"has-large-font-size\">Partner with <strong>SupportPRO<\/strong> for 24\/7 proactive cloud support that keeps your business secure, scalable, and ahead of the curve.<\/p>\n\n\n\n<!--HubSpot Call-to-Action Code --><span class=\"hs-cta-wrapper\" id=\"hs-cta-wrapper-3350a795-db50-482f-9911-301930d1b1be\"><span class=\"hs-cta-node hs-cta-3350a795-db50-482f-9911-301930d1b1be\" id=\"hs-cta-3350a795-db50-482f-9911-301930d1b1be\"><!--[if lte IE 8]><div id=\"hs-cta-ie-element\"><\/div><![endif]--><a href=\"https:\/\/cta-redirect.hubspot.com\/cta\/redirect\/2725694\/3350a795-db50-482f-9911-301930d1b1be\" ><img decoding=\"async\" class=\"hs-cta-img\" id=\"hs-cta-img-3350a795-db50-482f-9911-301930d1b1be\" style=\"border-width:0px;\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/2725694\/3350a795-db50-482f-9911-301930d1b1be.png\"  alt=\"Contact Us today!\"\/><\/a><\/span><script charset=\"utf-8\" src=\"https:\/\/js.hscta.net\/cta\/current.js\"><\/script><script type=\"text\/javascript\"> hbspt.cta.load(2725694, '3350a795-db50-482f-9911-301930d1b1be', {\"useNewLoader\":\"true\",\"region\":\"na1\"}); <\/script><\/span><!-- end HubSpot Call-to-Action Code -->\n<\/div><figure class=\"wp-block-media-text__media\"><img fetchpriority=\"high\" decoding=\"async\" width=\"904\" height=\"931\" src=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2022\/09\/Free-server-checkup.png\" alt=\"guy server checkup\" class=\"wp-image-12943 size-full\" srcset=\"https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2022\/09\/Free-server-checkup.png 904w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2022\/09\/Free-server-checkup-291x300.png 291w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2022\/09\/Free-server-checkup-768x791.png 768w, https:\/\/www.supportpro.com\/blog\/wp-content\/uploads\/2022\/09\/Free-server-checkup-585x602.png 585w\" sizes=\"(max-width: 904px) 100vw, 904px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Linux servers often host multiple users and applications simultaneously. During execution, applications such as Apache or background services may generate temporary files, especially inside directories like \/tmp. Over time, these&hellip;<\/p>\n","protected":false},"author":4,"featured_media":16916,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-583","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-miscellaneous"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/comments?post=583"}],"version-history":[{"count":6,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/583\/revisions"}],"predecessor-version":[{"id":16917,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/583\/revisions\/16917"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/media\/16916"}],"wp:attachment":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/media?parent=583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/categories?post=583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/tags?post=583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}