How to Find File and Directory Size in Mac Terminal


Below are the ways to find the size of a directory and a file using Terminal app on a Mac.


Steps to Know Directory Size on Mac

  • Open Terminal app using Spotlight Search.
  • Move to the directory that you want to know the size of.

    Example:
    du -sh

    You will see the size of the directory displayed in KB/MB/GB.

    Know the size of a directory
  • Now run the command du with the flags "-sh"

    Example:
    cd ~/Desktop


Know the size of a file

  1. Open Terminal App.
  2. Now move to the directory where the file is located.
  3. Run the command ls with flags -lh followed by the filename.

    Example:
    % ls -lh get.py  
      
    -rwx------@ 1 dev  staff   959B Aug  1 14:26 get.py

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap