Linux网络编程 -- Linux常用工具的使用(vim、gcc、gdb、makefile、shell)

一.vim编辑器

vim三种模式:

1.命令行模式

vim打开文件,就是命令行模式
命令行模式指令:
x:删除一个字符 nx:删除n个字符
dd:删除(剪切)一行 ndd:删除(剪切)n行
yy:复制一行 nyy:复制n行
p:粘贴
shift+g:跳到最后一行 gg:跳到第一行
*:查找光标所在的字符串 n:查找下一个
u:撤销
shift+zz:保存退出

2.底行模式

在命令行模式下,按:进入底行模式
底行模式指令:
w:保存 q:退出 wq:保存退出
w!、q!、wq!强制
sp+文件名:打开另一个文件 ctrl+ww:移动光标
/输入字符串进行查找 n:查找下一个 shift+n:查找上一个
:%s/原字符串/新字符串/g:替换全部zifuchuan
:set nonu:关闭行号 :set nu:打开行号

3.插入模式

在命令行模式下,按“a”或者“i”进入插入模式

二.gcc编译器

编译工作过程:

1.预处理

gcc -E hello.c -o hello.i
处理所有以“#”开头的文件,如:(1)头文件(展开)、(2)宏定义(替换)、(3)条件编译
hello.i 是文本文件
注:

#if  0
......
#endif	  //注释中间内容

2.编译

gcc -S-hello.i -o hello.s
将C代码翻译成汇编代码

3.汇编

gcc -c hello.s -o hello.o
将汇编代码翻译成二进制

4.链接

gcc 所有.o文件 -o hello
链接程序需要用到的其他程序

其他工具

1.gcc -I : 指定头文件路径
例:gcc test.c -o test -I /home
2.gcc -static : 静态链接
例:gcc test.c -o test -static

三.make和Makefile

Makefile程序编写:

Target(目标):dependency(依赖)
1.

hello:hello.c
    gcc hello.c -o hello

2 .

Target=hello
Object=hello.o  print.o
$(Target):$(Object)
    gcc $(Object) -o $(Target)

.PHONY:clean
clean:
    rm *.o hello

:make:执行Makefilewenjian
make clean:清除中间文件

四.gdb调试工具

gcc test.c -o test -g
gdb test
(gdb): l(list)显示代码
l+数字:显示该行的上5行和下5行
r(run):运行程序
b(break)+数字:在该行插入断点
c(continue):继续运行
i(info):查看断点
d(delete) b +数字:删除第几个断点
n(next):执行下一步
s(step):执行下一步,遇到函数会进入
p(print)+变量:打印变量的值
q(quit):退出

五.shell脚本

shell脚本的后缀名为.sh

vim hello.sh

#!/bin/bash
echo "helloworld!"
echo "123456" > hello.txt
cat  /mnt/hgfs/share/hello.c  >>hello.txt

TMP="helloworld!"
echo ${TMP}        //(echo $TMP)
echo "第一个参数是:$1"
echo "第二个参数是:$2"
echo $*
echo $#        //显示几个参数

运行脚本文件:./hello.c

脚本循环程序:

circle.sh
1.

#!/bin/bash
for((i=0;i<5;i++))
do
    echo "helloworld!"
down

2 .

for i  in  aaa  bbb  ccc  ddd
do 
    echo $i
done

3 .

for  i  in  $1  $2  $3  $4
do
    mkdir $i
    cd  $i
    echo  >  $i.c "
#include <stdio.h>
int main()
{
    printf(\"helloworld!\\n\");
    return 0;
}"
    cd ..
done

判断数字大小

#!/bin/bash
if [ $1 -eq 0]; then
    echo"第一个参数等于0"
fi

if [ $2 -gt 0];then
    echo"第二个参数大于0"
elif [ $2 -lt 0];then
    echo"第二个参数小于0"
else
    echo"第二个参数等于0"
fi

判断目录/文件

#!/bin/bash
if [ -d $3 ];then
    echo"第三个参数是目录"
elif [ -f $3 ];then
    echo"第三个参数是文件"
fi
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值