更新
sudo apt-get update
安装
sudo apt-get install vim
检查编译器
gcc -v
查看路径
pwd
新建文件
touch
删除文件
rm
显示文件夹内容,前缀是 -
表示文件,第一个字母是 d
表示文件夹
--- CODE » ls -l
total 0
drwxr-xr-x 3 deacyn staff 102 Dec 8 15:32 Intern
drwxr-xr-x 11 deacyn staff 374 Jan 17 2015 Swift Weather
-rw-r--r-- 1 deacyn staff 0 Dec 8 23:05 abcd
drwxr-xr-x@ 8 deacyn staff 272 Dec 8 16:18 leetcode-master
vi插入模式,默认在当前光标之前插入一个字符 i
vi插入模式,默认在当前光标之后插入一个字符 a
vi插入模式,默认在下一行插入一个字符 o
vi插入模式,默认在上一行插入一个字符 shift + o
vi插入模式,行尾插入一个字符 shift + a
vi插入模式,行首插入一个字符 shift + i
vi命令模式,跳转到第10行 shift + g + 10
vi命令模式,删除光标所在字符 x
vi命令模式,删除一行 dd
vi命令模式下保存write退出 全部文件 wqa vi
查看文件权限,x
表示可执行,随后执行
--- Intern/les1 » ls -l
total 32
-rw-r--r-- 1 deacyn staff 72 Dec 8 23:17 a.c
-rwxr-xr-x 1 deacyn staff 8456 Dec 8 23:17 a.out
--- Intern/les1 » ./a.out
hello word!
vim中打开多个文件
:sp max.c
切换打开的文件
ctrl + w + up/down
打开行号
set: nu
当定义和声明没有分开时,include 相当于复制代码,gcc 只需要编译一个文件
--- Intern/les2 » gcc -c max.c -o max.o
--- Intern/les2 » ls -l
total 48
-rwxr-xr-x 1 deacyn staff 8488 Dec 8 23:41 a.out
-rw-r--r-- 1 deacyn staff 166 Dec 8 23:39 hello.c
-rw-r--r-- 1 deacyn staff 63 Dec 8 23:39 max.c
-rw-r--r-- 1 deacyn staff 672 Dec 8 23:43 max.o
max.o 不能执行 引入头文件,再编译
--- Intern/les2 » gcc max.o min.o hello.c
--- Intern/les2 » ls
a.out hello.c max.c max.h max.o min.c min.h min.o
--- Intern/les2 » ./a.out
max value is 33,min value is 21
make把大型文件整理源文件
--- Intern/les2 » make
gcc -c max.c
gcc -c min.c
gcc max.o min.o hello.c -o hello.out
--- Intern/les2 » ls
Makefile a.out hello.c hello.out max.c max.h max.o min.c min.h min.o