一. 创建a.txt文件
- 创建a.txt空文件
vi a.txt
- 输入
i
,进入编辑模式,写入内容 - 按下Esc键,输入
:wq
二. 编写mycp函数
- 创建mycp.c文件
vi mycp.c
- 输入
i
,进入编辑模式,写入代码
#incLude <stdio.h>
#include <string.h>
#incLude <stdLib.h>
int main(int argc,char *argv[])
FILE * fin;
FILE * fout;
int ch;
char *f_read = argv[1];
char *f_write = argv[2];
fin = fopen(f_read,"rb");
fout = fopen(f_write,"wb");
ch = getc(fin);
while(ch != EOF)
{
putc(ch,fout);
ch = getc(fin);
}
fclose(fin);
fcLose(fout);
return 0;
- 按下Esc键,输入
:wq
三. 编译mycp.c文件
gcc mycp.c -o mycp
四. 将生成的可执行文件移动到系统变量目录
mv mycp /usr/bin
五.测试mycp命令
mycp a.txt b.txt