获取本机内网IP
/sbin/ifconfig | grep “inet addr” -m 1 | cut -d “:” -f 2 | cut -d ” ” -f 1
输出unix时间戳
date +%s
从路径中获取文件名
basename /usr/bin/sort
Output “sort”.
basename include/stdio.h .h
Output “stdio”.
遍历指定路径文件
file_list=`ls dir`
for file in $file_list
do
echo $file
done
gdb attach指定进程名的进程
#! /bin/sh
if [ $# -lt 1 ]; then
echo “please give a name”
exit 1
fi
ENTRY=`ps x | grep $1 -m 1`
PID=`echo $ENTRY | cut -d ” ” -f 1`
while true; do
echo -e “The following process will be attached by gdb\n\n ${ENTRY}\n”
read -p “Continue? (y or n) ” confirm
case $confirm in
[y] ) gdb attach $PID; break;;
[n] ) exit 1;;
*) echo “Please answer y or n.”;;
esac
done
批量查找替换文本字符串
将当前目录下,所有的.h文件中的wrong替换为right
find . -type f -name “*.h” | xargs perl -pi -e ‘s|wrong|right|g’