linux常用shell命令记录

获取本机内网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’

发表评论

电子邮件地址不会被公开。 必填项已用*标注

(为了证明你是人类,请输入两数相加的结果)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">