Since Insync takes quite a while to scan on startup or resuming from pause, I thought I’d write a script to help me identify what folders are causing the biggest delay, and selectively delete / unsync them. If you’re using cloud storage for all your documents, then it’ll probably get cluttered with tons of unused files and folders over the years. I had over 130,000 files in my OneDrive folder, but with the help of the script, I brought it down to around 28,000. This has already improved scanning speed.
If you’re on Linux, it’ll be simple to use this script. I named it
dirfind and put it in my local scripts folder. All it does is loop through the current folder and print out the total number of sub-files and sub-folders contained within it. You might be surprised with what you can prune away. I deleted some from my OneDrive entirely, but I simply unsynced most. If you’re using Windows, you can still use the script if you run it in Windows Subsystem for Linux, or rewrite it with equivalent PowerShell/batch commands.
# !/usr/bin/sh if [ "$#" -lt 1 ]; then echo "Usage: dirfind (directory path)" echo "Example: dirfind ." exit 1 fi for file in $1/* do if [ -d "$file" ]; then count=`find "$file" -type f -print | wc -l` printf " %-6d %s\n" $count "$file" fi done | sort -k1,1nr count=`find "$1" -type f -print | wc -l` echo "Total in folder: $count"
drak@pop-os:/media/drak/DATA/OneDrive$ dirfind . 7987 ./CloudMedia 7063 ./Documents 6090 ./Projects 3939 ./Pictures 3610 ./School 2 ./Desktop 0 ./Creative Cloud Files Total in folder: 28693