Skip to content

Instantly share code, notes, and snippets.

@epcim
Created October 20, 2015 09:19
Show Gist options
  • Select an option

  • Save epcim/f4d77d6d167775ed3476 to your computer and use it in GitHub Desktop.

Select an option

Save epcim/f4d77d6d167775ed3476 to your computer and use it in GitHub Desktop.

Some BASH trics, scripts etc.

Disable CTRL+C in script

trap '' 2

Avoid running more than one instance. Check for the

 lockfile -8 -r -1 $LOCKFILE

##logger logger -p daemon.info "[Garbage-Inspector]: Starting at date"

Iterate inside any PID file, open it up and get its VmData "normal" consumption

	PIDS=`ls $PIDSDIR`
	for ipid in $PIDS; do

Find, LS, locate

find . -type f -printf "%Tx %.8TX %p\n" | sort | cut -f 1,3- -d ' '
find . -type f -printf "%-.22T+ %M %n %-8u %-8g %8s %Tx %.8TX %p\n" | sort | cut -f 2- -d ' '

find . -type f -printf "%TY-%Tm-%Td %.8TX %p\n" | sort -r | cut -f 1,3- -d ' '
for i in `ls -d *_dokumenty_*`; do echo "\n"; echo $i; find $i -type f -printf "%TY-%Tm-%Td %.8TX %p\n" | sort | cut -f 1,3- -d ' '|tail; done

ANY FILE MODIFED WITHIN NNdays

sleep 1 && echo -e "\n\nSystem wide modified files::\n" 2>/dev/null&
find / -mtime -120 -type f  2> /dev/null | \
  grep -v '/home\|.svn\|.git\|.hg\|/opt\|/usr/local\|/mnt\|/var\|/selinux\|/tmp\|/proc\|/sys'|\
  grep -v '/root/install\|/root/\.[a-zA-Z0-9]*/\|lock\|log\|/dev\|/var/trac\|/var/svn'|\
  sed -e 's/^/    /';

.PUVODNI .ORIG DIFFs

sleep 1 && echo -e "\n\nSystem wide configuration:\n" 2>/dev/null&
updatedb -e /mnt && for i in `locate '.puvodni' '/etc/**.bak'|grep -v '/mnt'`; do ORIG=`echo $i|\
  sed -e 's/.bak//' -e 's/.puvodni//'`; [[ -f "$ORIG" ]] && \
  echo -e "\n\n$ORIG::\n" ;diff "$ORIG" "$i" 2>/dev/null |\
  grep '^< '|sed -e '/^[ \t]*$/d' -e 's/^< /    /'; done

Find tricks

 for i in `find . -name "*.*" |grep -v xmp | grep -v .bib| grep -v .ini | sed -e 's/\ /XSXSXS/g'|xargs `; do O=`echo $i|sed -e 's/XSXSXS/\ /g'`;
 N=`echo $i|sed -e 's/XSXSXS/_/g'` ; P=`echo $N  | sed -e 's/\(.*\)\/.*$/\1/'`; echo mkdir -p "../../../APe\ NonPhoto/$P" ; echo mv "$O"
 "../../../APe\ NonPhoto/$N"; done

sorting & piping

ps -eo pmem,pcpu,rss,vsize,args | { head -1 ; sort -k 1 -r -n ; } | less

awk group data

Source:
AF:12
SA:909

Awk solution for group by clause implementation:
awk 'BEGIN{FS=":"; print "continent count total avg"} NR!=1 {a[(]++;b[(]=b[(]+[}END{for (i in a) printf("%s %10.0f %10.0f %10.2f\n", i, a[i], b[i], b[i]/a[i])} ' cont_bd.txt

Output:
continent count   total    avg
NA          1       5678    5678.00
OC          3       1003     334.33
AF          4        570     142.50
SA          4       4577    1144.25
EU          2        114      57.00])))

Count my ram

ps -eo rss,cmd| sed -e 's/^ //g' -e 's/ /#/' | awk 'BEGIN{FS="#"; printf "count  \t total  
\t avg \t Command"} NR!=1 {n=substr([,0,80);a[n]++;b[n]=b[n]+(;total=total+(}END{for (i in 
a) printf("%5.0f %10.0f %10.2f     %d      %s\n", a[i], b[i], b[i]/a[i], 
total,substr(i,0,100))} ' | sort -k 2 | tail -n 50; echo -e "count  \t total  \t avg 
\tRAM-CLK  \t  Command"))]

environment get info/attribs

The getent program gathers entries from the specified administrative database using the specified search keys. Where database is one of passwd, group, hosts, services, protocols, or networks.

getent group admin

zalamovani radky

export SHELLOPTS
set -i igncr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment