vim编辑器
三种模式 ①命令模式:打开文件就是命令模式
x 删除字符 nx 删除n个字符
dd 剪切一行 ndd 剪切n行 p粘贴
yy 复制一行 nyy 复制n行
G 跳到最后一行 gg 回到第一行
* 查找光标所在字符串 n 查找下一个
u 撤销 ZZ 保存退出
②插入模式 按a、i进入插入模式
按esc退出插入模式
③底行模式 数字 跳到数字对应的行
sp+文件名 打开另一个文件
ctrl+ww 在不同文件中上下移动光标
/字符串 跳到底行模式查找字符串 字符串高亮
通过查找不存在的字符串取消高亮
N 查找上一个
%s/字符串/新字符串 替换每行第一个
%s/字符串/新字符串/g 替换全部
set nu 显示行号 set nonu 取消行号
配置文件 /etc/vimrc
syntax on 关键字高亮
tabstop 设置tab字节
autoindent 自动首行缩进
set number 自动显示行号
gcc工具链
gcc hello.c -o hello
1.预处理 gcc -E hello.c -o hello.i
处理所有#开头的代码 ①头文件 展开
②宏文件 替换
③条件编译 #if 0/1 #endif 可以作为注释
2.编译 gcc -S hello.i -o hello.s
3.汇编 gcc -c hello.s -o hello.o
把汇编代码翻译成二进制
4.链接操作 gcc hello.o(链接程序需要的.o文件) -o hello
gcc -I 指定头文件路径
gcc -static 静态链接 (一般默认为动态链接)
make和Makefile工程管理器
make clean 删除中间文件
1 Target=hello
2 Object=hello.o print.o
3
4 $(Target):$(Object)
5 gcc $(Object) -o $(Target)
6
7 #Implicit Rules
8 #hello.o:hello.c
9 gcc hello.c -o hello.o
10 #print.o:print.c
11 gcc print.c -o print.o
12
13 #Declare clean as a pseudo-goal
14 .PHONY: clean
15 clean:
16 rm *.o hello
gdb调试工具
list 打印程序
list+数字 查看数字周围10行代码
l 1 表示从头查看
l - 查看上一个命令查看的代码之前的10行
l 函数名 查看函数周围的10行代码
l x y 查看x行到y行代码
l 文件名 函数名 查看文件中的函数周围10行代码
break 添加断点
b k 在k行添加断点
b 函数名 在函数处添加断点
info b 查看所有断点
delete b n 删除第n个断点
next 下一步(跳过函数)
step 下一步(不跳过函数)
run 运行 quit退出
以上命令均可用首字母代替
shell脚本文件
1 #! /bin/bash
2
3 echo "helloworld"
4 echo "123456" > hello.text
5 cat /home/Makefile/"hello.c" >> hello.text #>>追加
6
7 TMP="Miao" #设置参数Miao
8 echo $TMP /echo ${TMP} #打印参数Miao
9
10 echo "The first number is: $1"
11 echo "The second number is: $2"
12 echo $* (所有参数)
13 echo $# (参数个数)
运行时 ./脚本名 $1 $2 $3 $4
shell脚本中的循环
1 #! /bin/bash
2 for ((i=0;i<5;i++))
3 do
4 echo "Miaowu" #循环5次Miaowu
5 done
6
7 for i in a b c d
8 do
9 echo $i #打出参数abcd
10 done
11
12
13 for q in $1 $2 $3 $4
14 do
15 mkdir $q
16 cd $q
17 echo > $q.c "
18 #include<stdio.h>;
19 int main()
20 {
21 printf(\"loveyou~\\n\");
22
23 return 0;
24 }"
25 cd ..
26 done
.c文件要编译之后才能运行
shell脚本中的判断
1 #!/bin/bash
2 if [ $1 -eq 0 ]; then #判断是否等于0
3 echo "the first number equals to 0"
4 fi
5
6 if [ $2 -gt 0 ]; then #判断是否大于0
7 echo "the second number is bigger than 0"
8 elif [ $2 -lt 0 ];then #若不是,则判断是否小于0
9 echo "the second number is smaller than 0"
10 else #两者都不是则等于0
11 echo "the second number equals to 0"
12 fi
13
14 if [ -d $3 ]; then #判断是否是目录
15 echo "it is a dictionary"
16 elif [ -f $3 ]; then #若不是,判断是否是文件
17 echo "it is a file"
18 fi