Bash Examples

# =>  remove some kinds of files under dir and subdir
$ find dir -name '*.[oa]' -print | xargs rm -f

# =>  copy or rename some files with pattern 'prbs'
$ ls *prbs* | sed  -n -r 's/(.*)prbs(.*)/cp & \1PRBS\2/ p' | sh
$ ls *prbs* | sed  -n -r 's/(.*)prbs(.*)/mv & \1PRBS\2/ p' | sh
$ find ./ -name '*PRBS*' -print | sed  -n -r 's/(.*)PRBS(.*)/mv & \1prbs\2/ p' | sh

# => sort and unique some lines and fields in a file
$ awk 'BEGIN { FS = ":" } ; {print $1, $3}' ./ts_changes.txt | sort -u
# => similar command can be used in VIM, also can change sequence of field
:105,112 !awk 'BEGIN { FS = ":" } ; {print $3, $1}' | sort -u
#!/bin/bash
for i in `seq 1 16`; do
  for j in `seq 1 10`; do
    echo  $[1280+i*16]M;
    done
done
  • cscope info
find . -name "*.h" -o -name "*.c" -o -name "*.cpp" -o -name "*.cc"  -o -name "*.hh" > cscope.files
cscope -bkq -i cscope.files

cscope commands:
    add  : Add a new database             (Usage: add file|dir [pre-path] [flags])
find : Query for a pattern            (Usage: find c|d|e|f|g|i|s|t name)
    c: Find functions calling this function
    d: Find functions called by this function
    e: Find this egrep pattern
    f: Find this file
    g: Find this definition
    i: Find files #including this file
    s: Find this C symbol
    t: Find assignments to
    help : Show this message              (Usage: help)
    kill : Kill a connection              (Usage: kill #)
    reset: Reinit all connections         (Usage: reset)
show : Show connections               (Usage: show)