Cheats

A cheat sheet containing scripts that I normally use (shell, sql, python .etc)

replace component names (one per line) with bower.json git url (when git user/organization is the same):
replace: ([a-z\-]*)\n
with: "\1": : "https://github.com/thelmanews/\1.git",\n

check git status in all child directories:
find . -name 'th*' -type d -depth 1 -exec sh -c 'echo "\n \x1B[0;33m CHECKING STATUS IN {} \x1B[0m \n"' \; -exec git -C {} status \;

count number of unique words in a text

tr -sc 'A-Za-z' '\n' < efluc.txt | sort | uniq -c | less

order by count

tr -sc 'A-Za-z' '\n' < efluc.txt | sort | uniq -c | sort -n -r| less

case insensitive:

tr 'A-Z' 'a-z' < efluc.txt | tr -sc 'A-Za-z' '\n' |  sort | uniq -c |sort -nr | less

rename files to indexed filenames
cc=0; for i in `ls`; do let cc=$cc+1;  echo $i; echo $cc ; cp $i $cc.png; done

extract all images:
for i in `find . -name images.zip`;do d=`echo $i | sed 's/\/images.zip//g'| sed 's/\.\///g'`; unzip -o -d $d $i ; done

remove extra .wav extention from .WAV.wav files:
for i in `find . -name '*.wav'`; do echo $i; d=`echo $i | sed s/\.wav//g`; echo $d; cp $i $d; done

change .html files to .jsp:
for i in *;do d=`echo $i | sed s/'.html'//g` ; echo $d ; cp $d{.html,.jsp}; done

zip all images
cd [directory]
for i in ` ls .. `;do echo $i’images’;  cd ../$i; 7z.exe a -tzip images.zip images/* ; done

list unix users
cat /etc/passwd

find process using a port:
netstat -o | grep 1098

postgres number of tcp connections:
netstat -an|grep 5432

postgres connect to db with psql
psql -h localhost -U *** -W -d resellers

postgres psql run query and write to file
$ psql -h [host] -U *** -W -d resellers -c “select …” > wrapQuery.txt

surround email addresses with !!
sed -e ‘s/\([A-Za-z0-9._%+-]\+@[A-Za-z0-9.-]\+\.[A-Za-z]\{2,4\}\)/!!\1!!/g’  < email1.txt > new.txt
then extract them:
cat new.txt| grep @ |  sed -e ‘s/.*!!\(.*\)!!.*/\1/g’  | less

searches for package names for pattern
apt-cache search <pattern>

iterating over file names and concating  to each:
for i in `ls`; do echo sepans$i; done > filenames.txt

removing blank from filenames:
for i in *; do mv “$i” `echo “$i” | tr ‘ ‘ ‘_’`; done

change jars to jar.zip
for i in *.jar; do mv “$i”{,.zip}; done

replace breaklines enters returns with ;
tr ‘\r\n’ ‘;’ < filenames.txt > filename2.txt

files created / modified after a certain time

touch -t `date +%m%d0000` /tmp/$$
or touch -t 200701310846.26 /tmp/$$ (yyyyMMddhhmm.ss)
find /tmefndr/oravl01 -type f -newer /tmp/$$
rm /tmp/$$

remove files older than a year – purge:
find . -type f -mtime +365 -exec rm {} \;

find string in files newer than a time ordered by modified time:
find . -name ‘…Logger.log*’  -newer /tmp/$$ | xargs ls -rt | xargs grep WaitingForContent > messages.txt

find the order number replace it with # in the first line of messages.txt
sed -n ’1p;1q’ messages.txt | sed ‘s/\(SO00[0-9]*\)/#/g’
or more precise: sed -n ’1p;1q’ messages.txt | sed ‘s/\(SO00\([0-9]\)\{6\}\)/#/g’

apache restarting
/etc/init.d/httpd [start/stop/restart]

apache error logs:
/var/log/httpd/error_log

config:
/etc/httpd/conf/httpd.conf

extract tar.gz archive
tar -xzf archive.tar

compress tar
tar cf – target | gzip -c > target.tgz

rmove non empty folders
rm -rf  (use with care!)

remove svn data (disconnects source from svn server)
find . -name ‘.svn’ -type d | xargs rm -rf  (use with extra care!!!!!!!!!!!)

files larger than 1Mb:
du . | grep “[0-9]\{7\}”

list only directory folder directories
ls -dl */

export project names,

get all the files
cd Projects/[random_project_id]

for i in ${projectIds[@]}; do  cd ../$i; ls –format=single-column $PWD/*; done

write all h files with path in a file for classpath setting:
for i in ‘*.jar’; do echo ${PWD}/$i | sed s/’jar ‘/’jar;’/g ; done > alljars.txt

invalid non iso characters:
’ ” – “

 

← Back