forked from bmrf/standalone_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Linux one-liners.sh
57 lines (41 loc) · 2.21 KB
/
Linux one-liners.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Matrix text scrolling effect in the terminal
echo -e "\e[1;40m" ; clear ; while :; do echo $LINES $COLUMNS $(( $RANDOM % $COLUMNS)) $(( $RANDOM % 72 )) ;sleep 0.05; done|awk '{ letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()"; c=$4; letter=substr(letters,c,1);a[$3]=0;for (x in a) {o=a[x];a[x]=a[x]+1; printf "\033[%s;%sH\033[2;32m%s",o,x,letter; printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,letter;if (a[x] >= $1) { a[x]=0; } }}'
# Calculate cost of lines of code in a directory
sloccount ./
# List all services/daemons that run at startup (run level 3)
/sbin/chkconfig --list |grep '3:on'
# Release and renew IP addresses
dhclient -r
dhclient
# Determine if system is 32 or 64 bits
cat /proc/cpuinfo | grep -Gq "flags.* lm " && echo '64bit' || echo '32bit'
# Monitor disk i/o
iostat -x 1
# Disk usage summary by directory
du -chs /*
# Disk usage summary by directory, alternate (sometimes more effective)
du -h / | grep '[0-9\.]\+G'
du -h / | grep '^\s*[0-9\.]\+G' # only directories larger than 1.0 GB
du -ch -d 1 | sort -hr # uses util ncdu
# Find average size of all files on the entire drive (/)
find / -type f -print0 | xargs -0 ls -l | gawk '{sum += $5; n++;} END {print "Total Size: " sum/1024/1024 " MB : Avg Size: " sum/n/1024 " KB : Total Files: " n ;}'
# Kill all processes whose name contains this string ("minion" in this example)
kill `ps -A|awk '/minion/{print $1}'`
# Verify no non-root users have UID 0 (root)
awk -F: '($3 == "0") {print}' /etc/passwd
# Follow a log file in real-time
tail -f /var/log/maillog
tail -f /var/log/messages
tail -f /var/log/httpd
# Useful tools for watching NIC traffic/throughput
vnstat -l -i eth1
iptraf
ntop # Self-contained webGUI traffic monitor, with graphs and detailed tables. Runs by default on port 3000
# Add static route for a specific host
route add -host 192.168.1.83 gw 172.16.1.1
# Add static route for a specific subnet
route add -net 192.168.1.0/24 gw 172.16.1.1
# Add static route for a specific subnet and specify a metric
route add -net 192.168.1.0/24 gw 172.16.1.1 3
# RHEL/CentOS: Show all installed packages and the date of last update
rpm -qa --qf '%{INSTALLTIME} %-40{NAME} %{INSTALLTIME:date}\n' | sort -n | cut -d' ' -f2-