Skip to main content
Question

EA or Script to Find Large Files & Folders

  • Oct 20, 2022 7:15 PM UTC
  • 8 replies
  • 170 views

Forum|alt.badge.img+22

I'm looking to get some insight into large files and folders on computers before they get to our office. We are seeing a large number of requests come in for not being able to update their macOS dues to low available storage so I'd like to be able to get a report on who has what storage left, easily looking into a device record and see the top 5 or 10 large files and folders. I've been playing with the "du" and "find" commands but struggling to put it together in a useable format for a script or extensions attribute. Does anyone have anything?

8 replies

Forum|alt.badge.img+22
  • Author
  • Honored Contributor
  • Oct 21, 2022 12:40 PM UTC

Nope, not yet.


Forum|alt.badge.img+8
  • Valued Contributor
  • Oct 21, 2022 3:53 PM UTC

what I am using seems to work for us, ymmv. As always test:

#!/bin/sh

LOGGEDIN=`ls -l /dev/console | awk '/ / { print $3 }'`

LARGEFILE=`sudo find /Users/$LOGGEDIN -type f -size +1G`

echo "<result>$LARGEFILE</result>"


Forum|alt.badge.img+22
  • Author
  • Honored Contributor
  • Oct 21, 2022 5:04 PM UTC

what I am using seems to work for us, ymmv. As always test:

#!/bin/sh

LOGGEDIN=`ls -l /dev/console | awk '/ / { print $3 }'`

LARGEFILE=`sudo find /Users/$LOGGEDIN -type f -size +1G`

echo "<result>$LARGEFILE</result>"


Thanks will play with this today. Did you consider searching the whole HD as opposed to the logged in user folder, and did you work on adding the actual file size to the list?


Forum|alt.badge.img+22
  • Author
  • Honored Contributor
  • Oct 21, 2022 7:40 PM UTC

I did add the size to each with below, now playing with searching the whole HD as opposed to just the user folder

#!/bin/sh LOGGEDIN=`ls -l /dev/console | awk '/ / { print $3 }'` LARGEFILE=`sudo find /Users/$LOGGEDIN -type f -size +5G -exec du -hs {} \\; | sort -hr` echo "<RESULTS>$LARGEFILE</RESULTS>"

 


Forum|alt.badge.img+8
  • Valued Contributor
  • Oct 24, 2022 11:45 PM UTC

Hey @TomDay ,

that is what I was going to recommend, got busy prepping for Ventura, good start sir


Forum|alt.badge.img+12
  • Valued Contributor
  • Jun 25, 2023 10:29 PM UTC

I did add the size to each with below, now playing with searching the whole HD as opposed to just the user folder

#!/bin/sh LOGGEDIN=`ls -l /dev/console | awk '/ / { print $3 }'` LARGEFILE=`sudo find /Users/$LOGGEDIN -type f -size +5G -exec du -hs {} \\; | sort -hr` echo "<RESULTS>$LARGEFILE</RESULTS>"

 


Unable to scan all the hard drive, getting operation not permitted on lots of folders. I used "find /" rather using "find /Users/XXX"


jamf-42
Forum|alt.badge.img+17
  • Esteemed Contributor
  • Jun 29, 2023 12:43 PM UTC

I did add the size to each with below, now playing with searching the whole HD as opposed to just the user folder

#!/bin/sh LOGGEDIN=`ls -l /dev/console | awk '/ / { print $3 }'` LARGEFILE=`sudo find /Users/$LOGGEDIN -type f -size +5G -exec du -hs {} \\; | sort -hr` echo "<RESULTS>$LARGEFILE</RESULTS>"

 


running that in an EA is quite an overhead every time you run a recon.. you may be better off moving this to a policy, writing the data out to a file and then using a EA to collect that data. 

 

Alternative is to use a smart group with 'Boot Percentage Full' more than XX percent (80 seems to work), you can then get this to email where needed... 

 


jhbush
Forum|alt.badge.img+27
  • Esteemed Contributor
  • Aug 10, 2023 4:35 PM UTC
#!/bin/bash #Large File Export for Enrolled Devices #Part A: Search for files based on Disk Usage largeFileExport=$(du -achgx / | awk '$1>5 {print $0}' | sort -n | grep -v -e "Operation|not|permitted") echo "<result>$largeFileExport</result>"