File size: 904 Bytes
df66a57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Temporary file to hold all tracked and untracked files not ignored by .gitignore
TEMP_FILE_LIST=$(mktemp)

# Get all files tracked by git
git ls-files > "$TEMP_FILE_LIST"

# Add all untracked files not ignored by .gitignore to the list
git ls-files --others --exclude-standard >> "$TEMP_FILE_LIST"

# Find files larger than 100MB
echo "Checking for files larger than 10MB that are not ignored by .gitignore…"
while IFS= read -r file; do
    # Skip if file does not exist (e.g., was deleted)
    if [[ ! -e "$file" ]]; then
        continue
    fi

    # Get file size in bytes using the correct option for Linux
    file_size=$(stat --format=%s "$file")

    # If file size is greater or equal to 100MB (100*1024*1024 bytes)
    if [[ "$file_size" -ge $((10*1024*1024)) ]]; then
        echo "$file is $(($file_size / 1024 / 1024))MB"
    fi

done < "$TEMP_FILE_LIST"

# Cleanup
rm "$TEMP_FILE_LIST"