-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbin bash Find Large Files.sh
More file actions
52 lines (42 loc) · 1.12 KB
/
bin bash Find Large Files.sh
File metadata and controls
52 lines (42 loc) · 1.12 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
49
50
51
52
#!/bin/bash
# Find Large Files Script
# Locates the largest files in a specified directory
# Set default values
DIRECTORY="${1:-.}"
NUMBER="${2:-10}"
echo "Finding the $NUMBER largest files in $DIRECTORY..."
echo ""
# Find and display largest files
find "$DIRECTORY" -type f -exec du -h {} + 2>/dev/null | \
sort -rh | \
head -n "$NUMBER" | \
awk '{printf "%s\t%s\n", $1, $2}'
echo ""
echo "Usage: $0 [directory] [number_of_files]"
echo "Example: $0 /home/user 20"
```
### portcheck.sh
```bash
#!/bin/bash
# Port Checker Script
# Tests if ports are open on a specified host
# Check if host is provided
if [ $# -lt 2 ]; then
echo "Usage: $0 [port2] [port3] ..."
echo "Example: $0 google.com 80 443 8080"
exit 1
fi
HOST="$1"
shift # Remove first argument (host) from the list
echo "Checking ports on $HOST..."
echo ""
# Loop through all provided ports
for PORT in "$@"; do
# Use timeout to prevent hanging
timeout 2 bash -c "echo >/dev/tcp/$HOST/$PORT" 2>/dev/null
if [ $? -eq 0 ]; then
echo "✓ Port $PORT is OPEN"
else
echo "✗ Port $PORT is CLOSED or filtered"
fi
done