Using Terminal to Find Large Files and Folders

You can use the Terminal to list files and folders, restrict the lists to only large files and folders, and also just show the ones that use the most space.



Here’s a list of some examples used in the video:

# change directory (drag and drop a folder from the Finder after it)
cd

# show current directory
pwd

# list files
ls

# list files with details
ls -l

# use human-readable file sizes
ls -lh

# find files starting at current location and containing text in name
find . -iname *test*

# case insensitive
find . -iname *test* -d 3

# find files over a certain size
find . -size +200M

# list directories (folders)
du -d1

# use human-readable sizes
du -h -d1

# look down 3 levels and only show folders above a threshold size
du -h -d3 -t10G

# list directories and sort by size
du -h | sort -hr

# only show top 10
du -h | sort -hr | head -n10

#  list directories in current folder, threshold 10G,
# sort with human-readable sizes, top 10
du -h -d1 -t10G | sort -hr | head -n 10

# find files larger than a size, list with details
find . -size +200M -exec ls -lh {} \; 

# find files and folders, list with details
find . -size +200M -exec du -hs {} \;

# find files and folders, list with details, sort
find . -size +200M -exec du -hs {} \; | sort -hr

# find files and folders, list with details, sort, top 10
find . -size +200M -exec du -hs {} \; | sort -hr | head -n 10

Comments: 19 Responses to “Using Terminal to Find Large Files and Folders”

    Razvan Mihai
    4 months ago

    Gary, thanks for another excellent tutorial on finding your documents and folders. On a related note, is there a way to make the Documents folder visible in the main Finder window?

    After syncing this folder to iCloud, I can find it in the sidebar; but I got used to having it in the Finder window, where the rest of the folders reside.

    4 months ago

    Razvan: Not sure what you mean. A Finder window shows you the files and folders inside a folder. You certainly can look at the Documents folder with a Finder window. That's how you do it. I guess I don't understand what you are asking here.

    Razvan Mihai
    4 months ago

    Gary, I am trying to see the Documents (and Desktop folder) as subfolders when in my home directory to move things around easily. After syncing the Desktop and Documents folder to iCloud, I can only see these two folders from the side pane of the Finder or the Terminal but not as subfolders from my home directory. These two folders seem to have gotten hidden somehow from the home directory, probably to flag that they are in sync on iCloud. Thanks.

    4 months ago

    Razvan: Your Home holder is your local folder at /Users/yourname/ If Documents and Desktop are in iCloud Drive, they aren't there but in iCloud Drive. You would see them when you select iCloud Drive from the left sidebar, or Go, iCloud Drive.

    Razvan Mihai
    4 months ago

    I see. Thanks. What is confusing, though, is that these two folders can be accessed in the Terminal directly under the home directory as well under /Users/myusername/, unlike any other iCloud folder, which can be found using at /Users/myusername/Library/Mobile\ Documents/com\~apple\~CloudDocs/.

    I'm guessing that these two locations where you can find Documents and Desktops are symlinked / aliased somehow, which leads me to consider creating alias folders under my home directory.

    4 months ago

    Razvan: That's right. They can be accessed that way. It is for convenience, that's all.

    Thomas Oatman
    4 months ago

    Yes - thanks Gary. 40 years in Windows/DOS so I am having some trouble adjusting to MAC. But your videos, and numerous tools, are helping me cope LOL.

    @Gary: My first reaction was adding some symlinks -- I do this all the time in Windows to aggregate folders from various drives together into one 'view'.
    However, if you reveal the hidden items in home with `Shift`-`Command`-`.`, you can see Desktop, Documents, etc.
    `chflags nohidden Desktop` did not help. That's as far as I've gotten.

    4 months ago

    Thomas: I'm not getting what you are trying to do in the second part of your comment. Missing some context. What are you trying to DO?

    Paul Schwotzer
    4 months ago

    I get a lot of "Operation not permitted" when I run the find command.
    How can I adjust the permissions to avoid this?
    Seems a while back there was a command to "Fix Permissions" globally on a Mac drive.
    e.g find: ./Library/Caches/com.apple.Safari: Operation not permitted

    4 months ago

    Paul: Is your account Standard instead of Admin? Not sure why it would give you the errors, but just ignore them. The idea here is to find large files you can deal with. If it can't see into a library folder it doesn't matter.

    Larry Garrard
    4 months ago

    Suggestion: I would love to see a list of the Term. Commands posted here in the comments. Then we could copy and paste them into a "NOTE" for future use. I love your work and keep it up for our Community!

    4 months ago

    Larry: I added them above.

    JC
    2 months ago

    I had to restart my iMac and now it won't boot up because I don't have enough space left on my hard drive. I want to delete some large files using Terminal, which I accessed using Cmd + R. What command should I use to get to the Documents folder? Pwd gives me: /var/root.

    2 months ago

    JC: First, I would try booting into Safe Mode (https://support.apple.com/guide/mac-help/mh21245/mac) and do it normally. If you still can't boot into Safe Mode, and you really want to do it in Terminal, be careful. No safety net for deleting files like the Trash. Use cd to change directory to get to your documents folder. Like this:
    cd ~/Documents
    See https://www.youtube.com/watch?v=GZyqkGRnKSQ for more.

    JC
    2 months ago

    Unable to boot in safe mode. I have a backup of my files, so not too worried. I tried reinstalling MacOS, but not enough free space. My only option is Terminal.
    I get the following response: /var/root/Documents: No such file or directory.

    2 months ago

    JC: OK. Try "cd /Users" then ls to list the directories. Recognize which is your Home folder. Then "cd homefoldername" then ls again. Then "cd Documents" or whatever folder you want.

    JC
    2 months ago

    There must be something wrong. I did "cd /Users", then "ls" and the only directory displayed is "Shared". I type "cd /Shared" and the response is "No such file or directory". Is my user folder gone?

    2 months ago

    JC: First, realize that starting with / you are indicating you are giving the full path. So cd /Shared means you want the Shared folder at the TOP level. So, if you are in the Users directory already, cd /Shared doesn't care and will still go to "Shared" at the top level. If you want to go to the Shared directory under the current directory, then cd Shared (no slash( is what you need.

    Second, when you are in Users, if you do ls you only see "Shared"? Nothing else? You should see a list of folder names, including your Home directory. Note it isn't one per line, they are separated by spaces.

    JC
    2 months ago

    Thanks for your help Gary!

Leave a New Comment Related to "Using Terminal to Find Large Files and Folders"

:
:
:
0/500 (500 character limit -- please state your comment succinctly and do not try to get around this limit by posting two comments)