-
Notifications
You must be signed in to change notification settings - Fork 1
/
SearchLargeFiles.sh
35 lines (29 loc) · 1.03 KB
/
SearchLargeFiles.sh
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
#!/bin/bash
# ******************************************************************************
# *
# * Copyright (c) 2021 Phoenix Contact GmbH & Co. KG. All rights reserved.
# * Licensed under the MIT. See LICENSE file in the project root for full license information.
# *
# ******************************************************************************
LargeFileLog="/opt/plcnext/logs/largeFile.log"
if [[ $1 == "help" ]]; then
echo "Usage: SearchLargeFiles.sh startDirectory DisplayXFiles"
echo "Example SearchLargeFiles.sh /var/log/ 20"
exit 255
fi
if [[ $1 == "" ]]; then
STARTDIRECTORY="/var/volatile"
else
STARTDIRECTORY=$1
fi
if [[ $2 == "" ]]; then
LISTXXFILES=20
else
LISTXXFILES=$2
fi
echo "Search Dir:${STARTDIRECTORY} for large files/directories list X=${LISTXXFILES} largest Files in Byte"
if ! [ $(echo $STARTDIRECTORY | grep "/opt/") ] && [ $(whoami) != "root" ] ; then
echo "please switch to root user to search all folders";
else
du -a ${STARTDIRECTORY} | sort -n -r | head -n $LISTXXFILES >> /opt/plcnext/logs/largeFile.log
fi