-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetlogLargeFiles.sh
More file actions
48 lines (33 loc) · 1.24 KB
/
getlogLargeFiles.sh
File metadata and controls
48 lines (33 loc) · 1.24 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
# Author: Adam Anderson
# Code Repo: https://github.com/84adam/getlogLargeFiles/
# Use this script to locate, list, and log your largest files
# Modify 'size' parameter as needed, i.e. `-size +{###(M/G)}`, e.g. "-size +1G"
# First, create the log file based on today's date.
# This script is intended to be used once a day, for example via a cron job.
# Running this more than once a day will overwrite, instead of appending to, the $LOGFILE
# Exit if not root/sudo user
if [ ! "`whoami`" = "root" ]
then
echo "This script must be run as root. Exiting..."
exit 1
fi
# Location to store the logs, appending today's 'Month-day-Year'
LOGFILE="$HOME/LARGEFILES-$(date -u +%b-%d-%Y).log"
# Create this file for today
touch $LOGFILE
# superfluous delay and formatting
sleep .5
echo "All files larger than 100M, logged to: $(echo "$LOGFILE")"
echo " "
echo "##################################################"
echo " "
sleep .5
# List all files greater than 100M in size;
# print results to terminal
# log to $LOGFILE using `tee`
find / -xdev -type f -size +100M -exec ls -lah {} \; | sort -k 3,3 -k 5rn | awk '{print $5,$3,$4,$9}' | tee $LOGFILE
echo " "
echo "##################################################"
echo " "
echo "Have fun!"