> for file in $( ls . ); do if [ ! -s $file ]; then rm -f $file; fi; done
Of course you could just get over your fear of find and take a look at that man page. Perfect for a recursive search and delete all in one:
> find . -empty -delete
simple, no?
This is mainly somewhere for me to dump interesting tidbits of tech info. Stuff that I may forget but will need again in the future. For a proper blog, visit my electronics blog (http://www.fangletronics.com) or my wife's pre-school crafty blog (http://www.filthwizardry.com).
> for file in $( ls . ); do if [ ! -s $file ]; then rm -f $file; fi; done
> find . -empty -delete
> mysql -u paulbo -N <<< "SELECT name from proteins" | while read protein_name; do mysql -u paulbo -N "SELECT count(*) FROM data INNER JOIN proteins ON data.protein_id = proteins.protein_id where proteins.name = '${protein_name//\'/\\\'}'"; done
> mysql -u paulbo -N <<< "SELECT name from proteins" | while read protein_name; do echo ${protein_name//[-\/\:\'\"\(\) ]/_};done
ls man page, but I only came across it a couple of days ago.ls's inbuilt flat --hide.
> ls -l
arg.txt
blarg.txt
foo.txt
...
interesting.sh
... # and a ton more *.txt files
zlargyblorg.txt
> ls -l --hide=*.txt
interesting.sh
hidden.csv
ls * | while read file; do mv "$file" ${file// /_}; done
${#array[@]} to get the 'size' of an array, it actually only returns the number of assigned elements in the array.
> array[23]=123
> echo ${#array[@]}
1
> array[0]=1;array[1]=2;array[2]=3;
> echo ${array[*]}
1 2 3
> echo "${array[*]}"
1 2 3
> IFS=","
> echo ${array[*]}
1 2 3
> echo "${array[*]}"
1,2,3
>
> ORIG_IFS=IFS
... do stuff
> IFS=ORIG_IFS
> java -Xmx100m -XX:+HeapDumpOnOutOfMemoryError -XX:HeadDumpPath=/tmp/dump.hprof com.geekbraindump.MyMemoryHoggingClass
> echo $RANDOM | xclip
> xclip -o
4807
> echo $RANDOM | xclip -sel 'clipboard'
> xclip -o -sel 'clipboard'
4807
> (echo $RANDOM) | cat
1297