forked from sayan01/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilesize
More file actions
executable file
·47 lines (42 loc) · 720 Bytes
/
Copy pathfilesize
File metadata and controls
executable file
·47 lines (42 loc) · 720 Bytes
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
#!/bin/bash
calc (){
rv=$(echo "scale=2;$1" | bc)
if echo "$rv" | grep -q .00$
then
echo "$rv" | cut -d"." -f1
else
echo "$rv"
fi
}
if [ $# = 0 ]
then
echo "filesize: missing argument" && exit 1
fi
for file in "$@"
do
if [ ! -f "$file" ]
then
echo "filesize: $file does not exist" && exit 1
fi
size=$(stat -c %s "$file")
tb=1099511627776
gb=1073741824
mb=1048576
kb=1024
if [[ $size -ge $tb ]]
then
output="$(calc "$size/$tb") TB"
elif [[ $size -ge $gb ]]
then
output="$(calc "$size/$gb") GB"
elif [[ $size -ge $mb ]]
then
output="$(calc "$size/$mb") MB"
elif [[ $size -ge $kb ]]
then
output="$(calc "$size/$kb") KB"
else
output="$size bytes"
fi
echo "$file: $output"
done