-
Notifications
You must be signed in to change notification settings - Fork 15
/
ls-by-min
executable file
·32 lines (27 loc) · 1.39 KB
/
ls-by-min
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
#!/usr/bin/env bash
#########################################################################
# LS By Min #
# #
# Sorts the output of `ls` by file size, descending. #
# #
# If you want to sort ascending, try `ls-by-min | sort -r` #
# #
# Part of HopeSeekr's BashScripts Collection #
# https://github.com/hopeseekr/BashScripts/ #
# #
# Copyright © 2020 Theodore R. Smith <[email protected]> #
# GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690 #
# #
# License: Creative Commons Attribution v4.0 International #
#########################################################################
if [ -z "$1" ]; then
echo "Error: You must specify a minimum file size (in MB)."
exit 1
fi
FILE_SIZE=$1
if [ "$2" = "-r" ]; then
MAXDEPTH=512
else
MAXDEPTH=1
fi
find . -maxdepth ${MAXDEPTH} -type f -size "+${FILE_SIZE}M" -exec du -sm {} \; | sort -rnk1 | sed 's/^[0-9]\+\t*//g'