• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • How to exclude multiple directories from du command in Linux

    du command is used to find out the size of directories and files in Linux. It summarizes disk usage of each FILE, recursively for directories.

    But in case you want to skip out any specific directory from the usage calculation you can use the below steps

    Now I have a directory "work". lets check out the size of the files inside this directory
    [root@nfsserver work]# du -sch *
    1.2G    deep
    58M     dir1
    81M     dir2
    18M     dir3
    595M    myfile.txt
    1.9G    total

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

    This gave us an output with size of all the directories inside work. But what if I want to skip "deep" from the calculation?

    Observe the below command
    [root@nfsserver work]# du --exclude=deep -sch *
    58M     dir1
    81M     dir2
    18M     dir3
    595M    myfile.txt
    751M    total

    So as you see "deep" directory was not touched for size calculation. Similarly if you want to exclude multiple directories use the below method
    [root@nfsserver work]# du --exclude=deep --exclude=dir1 --exclude=dir2 -sch *
    18M     dir3
    595M    myfile.txt
    613M    total

    You can also sort the output according to the size of the files using below command
    # du -sch * | sort -h -r
    1.9G    total
    1.2G    deep
    595M    myfile.txt
    81M     dir2
    58M     dir1
    18M     dir3

    I hope I made my self clear.

    Related Articles:
    How to check the lock status of any user account in Linux
    How to exclude some directories from find command in Linux
    How to mount windows share on linux

    Follow the below links for more tutorials

    How to secure Apache web server in Linux using password (.htaccess)
    How to register Red Hat Linux with RHN (Red Hat Network )
    Red hat Enterprise Linux 5.5 Installation Guide (Screenshots)
    15 tips to enhance security of your Linux machine
    Why is Linux more secure than windows and any other OS
    What is the difference between "su" and "su -" in Linux?
    What is swappiness and how do we change its value?
    How to log iptables messages in different log file
    What are the s and k scripts in the etc rcx.d directories
    How to check all the currently running services in Linux
    How to configure PXE boot server in Linux using Red Hat 6
    How to detect new hard disk attached without rebooting in Linux
    How to detect new NIC/Ethernet card without rebooting in Linux

    Deepak Prasad

    is a techie and an author who is still trying to survive in this IT generation with very little knowledge he has on Linux/Unix, VMware, SAN Storage, Automation, networking etc

    You can follow him on Facebook or Google+

    Do you also have something to share here?

    Become an author and be a part of our GoLinuxHub Team, Click here for more information
    How to exclude multiple directories from du command in Linux How to exclude multiple directories from du command in Linux Reviewed by Deepak Prasad on Friday, September 26, 2014 Rating: 5

    1 comment:

    Powered by Blogger.