[[shell]]
 

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

shell [2013/10/04 17:36]
dblume
— (current)
Line 1: Line 1:
-====== shell tips ====== 
- 
-Useful bash command for finding strings within python files... 
- 
-<code bash> 
-find . -name \*.py -type f -print0 | xargs -0 grep -nI "timeit" 
-</code> 
- 
-Interesting way to use ''grep -v'' to remove paths from a list generated by ''find''.  Not sure about the escaped ''|'' character, though... 
- 
-<code bash> 
-#!/bin/bash 
-find $PWD -regex ".*\.[hcHC]\(pp\|xx\)?" | \ 
-    grep -v " \|unwantedpath/unwantedpath2\|unwantedpath3" > cscope.files 
-cscope -q -b 
-</code> 
- 
-Here's how to find if a symbol is in a library, and how to search lots of object files and print the filename above the search... 
- 
-<code bash> 
-nm obj-directory/libmyobject.a | c++filt | grep Initialize_my_obj 
-find bindirectory/ -name \*.a -exec nm /dev/null {} \; 2>/dev/null | \ 
-    c++filt | grep -P "(^bindirectory.*\.a|T Initialize_my_obj)" 
-</code> 
- 
-Also handy to merge two streams together... 
- 
-<code bash> 
-( cat file1 && cat file2 ) | sort 
-</code> 
- 
-When a little quick math is needed, use ''bc'' 
-<code bash> 
-$ bc <<< "obase=16;ibase=10;15" 
-F 
-$ bc -l <<< 1/3 
-.33333333333333333333 
-$ bc <<< "scale=2; 1/3" 
-.33 
-$ bc <<< "obase=10;ibase=16;B" 
-11 
-</code> 
- 
-and, when coverting from hex to dec... 
- 
-<code bash> 
-echo $((0x2dec)) 
-</code> 
- 
-But, then again, does that really seem easier than, 
- 
-<code> 
-python -c "print int('B',16)" 
-</code> 
- 
-There's a bash way to calculate how many days ago a date was: 
- 
-<code bash> 
-$ echo $(( ($(date +%s) - $(date -d "2012-4-16" +%s)) / 86400 )) 
-</code> 
- 
-And a Python way... 
- 
-<code python> 
-python -c "import datetime; print (datetime.date.today() - datetime.date( 2012, 4, 16 )).days" 
-</code> 
- 
-And for displaying lines clipped at the right edge of the window instead wrapped: 
- 
-<code bash> 
-cat_one_line_per_row() { 
-  cat "$@" | expand | cut -b1-$COLUMNS 
-} 
-</code> 
- 
-or a "clip" command like so: 
- 
-<code bash> 
-alias clip="expand | cut -b1-\$COLUMNS" 
-</code> 
- 
-ctags's man page says that one of its bugs is that it has too many options.  Ain't that the truth.  Make note of the obscure flag here, ''--c++-kinds=+p'', that tells ctags to process prototypes and method declarations. 
- 
-<code bash> 
-ctags -n --if0=yes --c++-kinds=+p --langmap=c++:+.inl.lst \ 
-    --langmap=asm:+.inc --file-tags=yes -R --extra=fq \ 
-    --exclude=unwanted_file.lst \ 
-    --exclude='*unwanted-directory*/*' \ 
-    --regex-C++='/^.*CINIT.(.+),.*,.*,.*/CURLOPT_\1/' 
-</code> 
- 
-When you want to repeat a command a few times... 
-<code bash> 
-seq 1 50 | xargs -I{} -n1 echo '{} Hello World!' 
-</code> 
- 
-Keywords: bash shell sh zsh 
- 
-====== .vimrc tips ====== 
- 
-Here's an alternative way to automatically save backups (with dates in the filename) everytime you save a file. 
-<code> 
-set backup 
-set backupdir=~/.vim/backup/ 
-au BufWritePre * let &bex = '-' . strftime( "%Y%m%d-%H%M%S" ) 
-</code> 
- 
-That makes a lot of files, so you can clean out the backups with a cron job like this: 
- 
-<code> 
-# at 3 in the morning on Mondays, delete files older than 30 days 
-0 3 * * 1 find $HOME/.vim/backup/ -type f -mtime +30 -delete 
-</code> 
  
shell.1380933391.txt.gz · Last modified: 2013/10/04 17:36 by dblume
 
Recent changes RSS feed Driven by DokuWiki