-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbash_func
80 lines (58 loc) · 1.73 KB
/
bash_func
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
activ() {
conda activate "$1"; conda env list
}
cmdfreq() {
num=${1:-10}
history | cut -c 8- | sort | uniq -c | sort -rn | head -${num}
}
deact() {
conda deactivate; PS1=$(echo "$PS1" | perl -pe 's/^\(base\)\s*//' ); conda env list
}
ffile() { find . -type f -name "*$1*" -print ; }
gpw() { grep -i "$1" /etc/passwd ; }
laston() { last| grep -i "$1" | head -15; }
llg() { ls -la |grep -i "$1" | grep -v grep ; }
nuke() { set j = `ps x | grep "$1" | grep -v grep`;\ kill -9 $j[1]; echo "kill -9 $j[1]" ; }
pman() { man -t "$1" | open -f -a Preview ; }
psg() { ps aux | grep -i "$1" | grep -v grep ; }
pwg() { grep -i "$1" /etc/passwd ; }
rmfiles() { find . -name "*$1*" -print -exec \rm {} \; ; }
rmf() { find . -name "*$1*" -print -exec \rm {} \; ; }
rmtest() { find . -name "*$1*" -exec \echo 'The file' {} 'will be deleted' \; ; }
seek() { find . -name $1 -print ; }
slay() { set j = `ps1 guw | grep "$@" | grep $USER | grep -v grep` ; echo $j ; k9 $j[2] ; }
whentime() {
# if [ -z "$1" ]; then
# time_str=0
# else
# time_str="$1"
# fi
python -c "
import datetime
import sys
def calculate_time(delta_hours):
current_time = datetime.datetime.now()
delta = datetime.timedelta(hours=delta_hours)
new_time = current_time + delta
return new_time.strftime('%a %b %d %H:%M:%S %Z %Y')
try:
delta_hours = int($1)
except IndexError:
delta_hours = 0
print(calculate_time(delta_hours))"
}
humanbytes()
{
local SIZE=$1
local UNITS="B KiB MiB GiB TiB PiB"
for F in $UNITS; do
local UNIT=$F
test ${SIZE%.*} -lt 1024 && break;
SIZE=$(echo "$SIZE / 1024" | bc -l)
done
if [ "$UNIT" == "B" ]; then
printf "%4.0f %s\n" $SIZE $UNIT
else
printf "%7.02f %s\n" $SIZE $UNIT
fi
}