Little tools
来自个人维基
2023年6月1日 (四) 15:52free6d1823(讨论 | 贡献)的版本
- Auto replace old files in current folder with new files in a source folder
#!/bin/sh SOURCE=<abs_path_to_source_dir> DEST=`pwd` cd $SOURCE LIST=`find . -name \*.h` cd $DEST echo "Copy h files..." for f in $LIST do if [ $f -ot $SOURCE/$f ]; then echo "update $f" cp -far $SOURCE/$f $f fi done echo "Copy c files..." cd $SOURCE LIST=`find . -name \*.c*` cd $DEST for f in $LIST do if [ $f -ot $SOURCE/$f ]; then echo "update $f" cp -fa $SOURCE/$f $f fi done
- find file name and line number which contains the specified keyword
#!/bin/sh find . -name \*.h -type f -exec grep $1 -nH {} \; find . -name \*.hpp -type f -exec grep $1 -nH {} \; echo "search c files............................." find . -name \*.c -type f -exec grep $1 -nH {} \; find . -name \*.cpp -type f -exec grep $1 -nH {} \;
- open the file and start from the specified line number. The target is as this form:
<filename>:<line_number>
#!/bin/bash FILE=`echo $1 | cut -d : -f 1` LINE=`echo $1 | cut -d : -f 2` ARG="" REG='^[0-9]+$' if [[ "$LINE" =~ $REG ]]; then ARG="+$LINE" else ARG="" fi if [ -f "$FILE" ]; then vi $FILE $ARG fi