bashtips
 

# while always

while [ 1 ]
do
ls -lrt
echo ----
sleep 100
done

########################################

sort -u|grep -v paralog |awk '{print $2}'|sort|uniq -c
sort -u|grep -v paralog|awk '{print $1}'|sort|uniq -c|awk '$1>1'

########################################

while read i; do echo $1; done

########################################

for PKG in $(find . -maxdepth 1 -mindepth 1 -type d | cut -b 3- | sort); do
N_FIXME=$(find $PKG -iregex '.*\.\(c\|h\|py\|cpp\|cc\|hh\|cs\)$' -exec grep -i FIXME {} \; | wc -l); printf "% 5d %s\n" $N_FIXME $PKG;
done | sort -n -r

 ########################################

find . -type f -not -regex '\./\.git/.*' | wc -l 

find . -type f -not -regex '\./\.git.*' | xargs cat | wc -l (find . -name *.[hcS] -not -regex '\./\.git.*' | xargs cat | wc -l)

########################################

# delete in dir _but_ something
ls | grep -v abc | xargs rm

########################################

mkdir -p bedrock/{rubble/{betty,barney},flintstone/{wilma,fred}}

# print all lines but last

echo '1,$-1 p' | ed -s file

All lines but last 15 lines echo '1,$-15 p' | ed -s file
The 10th to the 5th last line echo '$-10,$-5 p' | ed -s file





#####

# spaces and tabs
grep -e "[[:space:]]ortholog_one2one[[:space:]]Amniota" gp.39.22.txt | less
grep -e "[[:space:]]22[[:space:]]" gp.dist.40.tab | less

grep -E [[:space:]]22[[:space:]] gp.dist.one2one.39.tab | less

# NOT
grep -v NULL

# OR
grep -e alfa -e beta

####


ssh and sort top by memory

ssh my-host top -b -n1 | tail -n+8 | sort -n -k1.46,1.50

#####

If you need to read the environment variables of an arbitrary process,
the /proc filesystem makes this super easy on Linux. The environment
variables are shown in /proc/PID/environ:

$ cat /proc/19065/environ
DISPLAY=localhost:0.0SHELL=/bin/bashPWD=/home/phil...

#####

# How to do a grep-if with "grep -q" and "||":

for i in `seq 1 10`; do j=$RANDOM; echo $RANDOM > /tmp/delete.txt; grep -q 0 /tmp/delete.txt && echo "Random number has a zero" || echo "Random number doesnt have a zero"; done