【ONE·Linux || 基本工具介绍 】

总言

  Linux下常用工具介绍:vim、gcc\g++、make\makefile、gdb、yum、git。

  

文章目录


  
  

1、编写代码:vim

1.1、是什么和为什么

   1)、对vim的基本介绍:
在这里插入图片描述
  实际使用:推荐IDE集成开发环境(效率非炫技)
  

  2)、为什么使用vim?
  1、需要一个能在Linux下编写代码的工具
  2、通过使用vim感受Linux操作系统
  

  

1.2、怎么用

   1)、vim打开界面:

在这里插入图片描述
  
  

  2)、vim是一种多模式的编辑器:

在这里插入图片描述

  
  1、vim默认打开的模式是命令模式,输入i进入插入模式,按esc返回到命令模式
  2、在编辑模式下编写好代码后,如果要退出,需要在底行模式进行。命令模式转换到底行模式的方法:“shift+;” ,即“ ”。
  3、底行模式下,按esc可回退到命令模式。
  4、问题:插入模式下是否可以直接“shift+;”进入底行模式?回答:不行。同理,一般情况下也不能从底行模式直接进入插入模式。
  
  
  

1.3、vim常见命令介绍:命令模式下

1.3.1、复制、粘贴、行删除、剪切

   1)、如何在底行模式下进行复制粘贴、剪切操作?

  基本介绍:

在这里插入图片描述
  
  

  简单复制粘贴操作:

  注意,也可以使用ny进行连续多行的命令复制。

在这里插入图片描述
  
  

  简单的删除/剪切操作:
    ddndd:使用方法同yy,剪切需要配合pnp使用。

在这里插入图片描述

  
  

   2)、如何在底行模式下进行撤销操作?

  基本介绍:

在这里插入图片描述
  
  

  使用演示:

在这里插入图片描述
  
  
  

1.3.2、光标移动(上下、左右)

   1)、光标的上下定位

  基本介绍

在这里插入图片描述
  
  

  使用场景说明:
  比如:当前拥有一万行命令,我们如何快速找到首行?快速找到尾行?

  shift+ggg使用:

在这里插入图片描述
  
  
  如何直接定位到某个指定的行? 比如666行:n+shift+gg

在这里插入图片描述

  
  
   2)、光标的左右定位

  基本介绍:

在这里插入图片描述
  
  

  左右移动至行头行尾:
  shift+4:$ 行尾
  shift+6:^ 行头

在这里插入图片描述

  
  

  以单词为基准左右移动:
  w、e、b

  

在这里插入图片描述
  
  
  

1.3.3、vim中上下左右、大小写切换

   1)、基础介绍
  左H、下J、上K、右L

在这里插入图片描述
  一个记忆方法: 正规打字时,食指和中指分别放在下、上上,则其左边为左,右边为右。
  
  这样设置的原因:
    1、键盘不一定有104键(老式键盘)。
    2、有些命令不支持上下左右键,只能使用hjkl
  
  

   2)、如何快速进行大小写切换?

  shift+~:大写切换小写,小写切换大写

在这里插入图片描述

  
  
  

1.3.4、替换、字符删除

   1)、如何进行替换?
  注意,这里rR替换的区别。

在这里插入图片描述
  

  2)、如何进行删除?

在这里插入图片描述

  
  
  

1.4、vim常见命令介绍:底行模式下

1.4.1、行号设置、分屏操作

   1)、如何调用行号?

  基本介绍
  行号:set nuset nonu

在这里插入图片描述
  
  

   2)、如何使用分屏操作?

  分屏操作:

  vim可以创建文件,比如此处的直接在命令行中打开文件

[wj@VM-4-3-centos t1101]$ ls
test.c
[wj@VM-4-3-centos t1101]$ vim test.c
[wj@VM-4-3-centos t1101]$ ls
test.c
[wj@VM-4-3-centos t1101]$ vim test2.c
[wj@VM-4-3-centos t1101]$ ls
test2.c  test.c
[wj@VM-4-3-centos t1101]$ 

  
  也可以在vim编辑器中使用分屏操作时创建文件:在底行模式下输入vs + 待打开文件名

在这里插入图片描述
  可以看见此处我们就成功打开两个文件,实现分屏操作。

  相关说明:
  1、光标在哪个文件,就对应当前编辑的是哪个文件。
  2、如果要切换到另一文件,可在命令模式下,按住ctrl键,连按两次w,即ctrl+w+w

在这里插入图片描述
  
  
  3、不退出vim的情况下执行一些命令,操作如下。

: ! ls -al,再回车,就能不退出vim直接执行一些命令
其它用法:
: ! gcc test.c ,直接编译,查看结果,方便修改。
: ! man,直接查询指令

在这里插入图片描述
  
  
  

1.4.2、退出、保存

  介绍如下:

在这里插入图片描述

  
  
  

1.5、vim环境配置

  基本介绍:

在这里插入图片描述
  
  

  相关插件:一般自己配置自己的(普通用户)

在这里插入图片描述
  

在这里插入图片描述

  
  
  

1.6、sudo相关配置

  见权限篇:【ONE·Linux || 权限 】
  
  
  
  

1.7、视图模式

1.7.1、批量注释与批量删除

   1)、一个基本作用,批量注释和批量删除:

  批量注释:ESC底行模式 → CTRL+V命令行模式 → 选中行数 → 大写I → 添加注释// →ESC退出。

  ESC回到命令行模式下,CTRL+V,进入视图模式,相应的,左下角模式处会变为V-BLOCK。

在这里插入图片描述
  此时通过hjkl键左下上右滑动选中需要的行,按I(shif+i,即大写)进入insert模式,再输入注释符//,或者#等。即可:

在这里插入图片描述
  最后再按住ESC回到普通模式,批量注释成功。

在这里插入图片描述
  
  

  批量删除:与上述相同,视图模式下选择要删除的注释行按d即可,注意此处需要选中两列。

在这里插入图片描述
  
  
  
  
  

2、编译:gcc/g++

2.1、安装与基本介绍

  gcc:编译链接C语言的编译器
  g++:编译链接C++的编译器,可向下包容C语言

  1、如下,执行gcc -vg++ -v,可看到当前gcc、g++版本。

在这里插入图片描述
  
  2、若没有g++,则可执行该条命令安装:sudo yum install -y gcc-c++ :
  
  
  

2.2、学习阶段一:预处理、编译、汇编、链接

2.2.0、演示:指针在64位下为8字节

  如下述代码,分别用gcc和g++演示指针大小(64位):

[wj@VM-4-3-centos part1]$ uname -r
3.10.0-1160.62.1.el7.x86_64 //Linux下查看其系统模式:详细学习看常见指令二

[wj@VM-4-3-centos part1]$ vim test01.c
[wj@VM-4-3-centos part1]$ vim test02.cpp
[wj@VM-4-3-centos part1]$ ls
test01.c  test02.cpp

[wj@VM-4-3-centos part1]$ gcc test01.c -o test01.out
[wj@VM-4-3-centos part1]$ g++ test02.cpp -o test02.out
[wj@VM-4-3-centos part1]$ ls
test01.c  test01.out  test02.cpp  test02.out

[wj@VM-4-3-centos part1]$ ./test01.out //可看到指针大小是8
0x8
[wj@VM-4-3-centos part1]$ ./test02.out //可看到指针大小是8
8


[wj@VM-4-3-centos part1]$ cat test01.c
#include<stdio.h>
int main(void)
{
    int *p=NULL;
    printf("%p\n",sizeof(p));
    return 0;
}

[wj@VM-4-3-centos part1]$ cat test02.cpp
#include<iostream>
using namespace std;
int main(void)
{
    int*p=NULL;
    cout<<sizeof(p)<<endl;
    return 0;
}
[wj@VM-4-3-centos part1]$ 

  
  
  
  

2.2.1、预处理

   1)、基本介绍

  预处理阶段:头文件展开、宏替换、删除注释、条件编译等

  整体情况说明如下:
  1、了解预处理阶段完成的事项;
  2、了解预处理阶段涉及的相关指令。

在这里插入图片描述

  
  
  
   2)、-o选项介绍:如何一步到位直接生成可执行程序?如何生成自己命名的可执行程序?

  相关演示如下:需要有系统化的认识

在这里插入图片描述
  
  
  

  相关代码:

  1 
  2 #include<stdio.h>
  3 
  4 #define M 100
  5 
  6 int main(void)
  7 {
  8     printf("M:%d\n",M);
  9     printf("hello world1\n");
 10 
 11     printf("hello world2\n");
 12     //printf("hello world3\n");
 13     //printf("hello world4\n");
 14     //printf("hello world5\n");
 15     printf("hello world6\n");
 16     printf("hello world7\n");
 17 
 18 #ifdef DEBUG 
 19     printf("hello DEBUG!\n");
 20 #else
 21     printf("hello RELEASE!\n");
 22 #endif
 23 
 24     return 0;                                                                                                                                             
 25 }

  gcc test.c

[wj@VM-4-3-centos part2]$ gcc test.c
[wj@VM-4-3-centos part2]$ ls
a.out  test.c
[wj@VM-4-3-centos part2]$ ./a.out
M:100
hello world1
hello world2
hello world6
hello world7
hello RELEASE!
[wj@VM-4-3-centos part2]$ 

  
  gcc test.c -o test01.out
  gcc -o test02.out test.c
  两种写法都可以,注意-o后跟随待生成文件命即可。

[wj@VM-4-3-centos part2]$ ls
a.out  test.c
[wj@VM-4-3-centos part2]$ gcc test.c -o test01.out
[wj@VM-4-3-centos part2]$ ls
a.out  test01.out  test.c
[wj@VM-4-3-centos part2]$ gcc -o test02.out test.c
[wj@VM-4-3-centos part2]$ ll
total 40
-rwxrwxr-x 1 wj wj 8408 Nov  2 11:12 a.out
-rwxrwxr-x 1 wj wj 8408 Nov  2 11:17 test01.out
-rwxrwxr-x 1 wj wj 8408 Nov  2 11:17 test02.out
-rw-rw-r-- 1 wj wj  405 Nov  2 11:12 test.c
[wj@VM-4-3-centos part2]$ ./test01.out
M:100
hello world1
hello world2
hello world6
hello world7
hello RELEASE!
[wj@VM-4-3-centos part2]$ ./test02.out
M:100
hello world1
hello world2
hello world6
hello world7
hello RELEASE!
[wj@VM-4-3-centos part2]$ 

  
  

   3)、-E选项介绍:从现在开始进行程序翻译,如果预处理完成,就停下来
  介绍:上述-o直接一步到位生成了可执行程序,这里我们介绍分步进行的相关指令。
  

在这里插入图片描述

  
  问题:预处理结束后,还是C语言吗?
  回答:是。因此需要下述编译步骤。
  
  

2.2.2、编译

  1)、基本介绍

  编译:上述C语言文件形成汇编语言

在这里插入图片描述
  
   2)、-S选项介绍:从现在开始进行程序翻译,如果编译完成,就停下来
  演示:

在这里插入图片描述
  
  相关代码:gcc -S test01.i -o test01.s

[wj@VM-4-3-centos part2]$ ls
a.out  test01.i  test01.out  test02.out  test.c

[wj@VM-4-3-centos part2]$ gcc -S test01.i -o test01.s

[wj@VM-4-3-centos part2]$ ll
total 64
-rwxrwxr-x 1 wj wj  8408 Nov  2 11:12 a.out
-rw-rw-r-- 1 wj wj 17042 Nov  2 11:31 test01.i
-rwxrwxr-x 1 wj wj  8408 Nov  2 11:17 test01.out
-rw-rw-r-- 1 wj wj   773 Nov  2 11:46 test01.s
-rwxrwxr-x 1 wj wj  8408 Nov  2 11:17 test02.out
-rw-rw-r-- 1 wj wj   405 Nov  2 11:28 test.c

  
  

2.2.3、汇编

   1)、基本介绍

在这里插入图片描述
  
   2)、-c选项介绍:从现在开始进行程序翻译,如果汇编完成,就停下来

  演示:

在这里插入图片描述
  
  
  相关代码:gcc -c test01.s -o test01.o

[wj@VM-4-3-centos part2]$ ls
a.out  test01.i  test01.out  test01.s  test02.out  test.c
[wj@VM-4-3-centos part2]$ gcc -c test01.s -o test01.o
[wj@VM-4-3-centos part2]$ ll
total 68
-rwxrwxr-x 1 wj wj  8408 Nov  2 11:12 a.out
-rw-rw-r-- 1 wj wj 17042 Nov  2 11:31 test01.i
-rw-rw-r-- 1 wj wj  1888 Nov  2 11:52 test01.o
-rwxrwxr-x 1 wj wj  8408 Nov  2 11:17 test01.out
-rw-rw-r-- 1 wj wj   773 Nov  2 11:46 test01.s
-rwxrwxr-x 1 wj wj  8408 Nov  2 11:17 test02.out
-rw-rw-r-- 1 wj wj   405 Nov  2 11:28 test.c
[wj@VM-4-3-centos part2]$ vim test01.o
[wj@VM-4-3-centos part2]$ od test01.o

  
  
  
  

2.2.4、链接

   1)、基本介绍

在这里插入图片描述
  
  
   2)、链接演示

  演示:

在这里插入图片描述
  
  
  
   3)、记忆方法
  ESc 对应 iso

  
  
  
  

2.3、学习阶段二:动静态库

在这里插入图片描述

  
  

2.3.1、动静态库介绍

  1)、问题一:如何验证即使生成了可执行程序,仍旧依赖于C语言的库?
  此处介绍了两个命令,lddfile

在这里插入图片描述

  介绍:一般链接过程中有两种方式
  1、动态链接:需要动态库
  2、静态链接:需要静态库

  
  
  2)、方法声明和方法实现

  ①引入:以下代码是否能编译过?回答:能。

  1 int main()
  2 {
  3     return 0;                                                                                                                                      
  4 }                                                     

在这里插入图片描述

  
  
  ②:一个可执行程序的形成,需要方法声明和方法实现。

#include<stdio.h>

int main()
{
    printf("hello vim!\n");
    return 0;
}

  头文件里只告诉你有这个方法(即方法声明),但没有具体给出方法的实现,那么,方法实现在哪里呢
  回答:C语言一般将方法的实现以库的形式给出。

在这里插入图片描述
  
  说明:系统会把这些函数实现都被做到名为 libc.so.6 的库文件中去了,在没有特别指定时,gcc 会到系统默认的搜索路径“/usr/lib”下进行查找,也就是链接到 libc.so.6 库函数中去,这样就能实现诸如printf的函数了。

在这里插入图片描述
  
  
  3)、Linux下头文件查看

  ①:Linux系统中存在对应的各种头文件,通过以下指令,我们可以查看Linux系系统下的头文件:

[wj@VM-4-3-centos part3]$ ls /usr/include

在这里插入图片描述
  
  
  相关介绍:
  Linux下,.so结尾是动态库,.a结尾是静态库。
  Windows下,.dll结尾是动态库,.lib结尾是静态库。
  
  在Linux下:
  1、动态链接:需要动态库,使用.so动态库文件
  2、静态链接:需要静态库,使用.a静态库文件

在这里插入图片描述
  
  
  延伸1:安装vs2019、vs2022是在做什么?
  回答:下载安装头文件和库。
  
  延伸2:Linux下很多指令也是使用库写的:

[wj@VM-4-3-centos part3]$ ls /usr/bin/ls
/usr/bin/ls
[wj@VM-4-3-centos part3]$ ldd /usr/bin/ls
	linux-vdso.so.1 =>  (0x00007ffd73d13000)
	/$LIB/libonion.so => /lib64/libonion.so (0x00007fc8b9b75000)
	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fc8b9835000)
	libcap.so.2 => /lib64/libcap.so.2 (0x00007fc8b9630000)
	libacl.so.1 => /lib64/libacl.so.1 (0x00007fc8b9427000)
	libc.so.6 => /lib64/libc.so.6 (0x00007fc8b9059000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007fc8b8e55000)
	libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fc8b8bf3000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fc8b9a5c000)
	libattr.so.1 => /lib64/libattr.so.1 (0x00007fc8b89ee000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fc8b87d2000)
[wj@VM-4-3-centos part3]$ 

在这里插入图片描述

  
  

2.3.3、动静态库如何链接

  1)、问题:动静态库是如何链接的?
  简单介绍:
  静态库:将库中方法实现真实拷贝到我们的可执行程序中。
  动态库:将库中我们要的方法实现的地址填入我们的可执行程序中,建立关联。

在这里插入图片描述

  
  
  2)、问题:如何实操?

  前提知识:g++、gcc默认形成的可执行程序是动态链接的。

在这里插入图片描述

  
  问题:如何实现静态库?
  -static指令,使用静态链接的方式形成可执行程序。
  

  说明:
  ①出现以下情况,是因为Linux下没有安装静态库。

[wj@VM-4-3-centos part3]$ gcc -o testbystatic.out test.c -static
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status //出错
[wj@VM-4-3-centos part3]$ ls
test.c  test.out
[wj@VM-4-3-centos part3]$ gcc test.c -o testbystatic.out -static
/usr/bin/ld: cannot find -lc  
collect2: error: ld returned 1 exit status   //出错
[wj@VM-4-3-centos part3]$ 

  相关安装指令:

[wj@VM-4-3-centos part3]$ sudo yum install -y libstdc++-static //C++静态库
[wj@VM-4-3-centos part3]$ sudo yum install -y glibc-static //C静态库

  再次操作:

在这里插入图片描述
  
  
  实际上动态链接和静态链接所获得的程序大小有很大区别:

在这里插入图片描述
  
   相关指令代码:

[wj@VM-4-3-centos code]$ ll
total 180
drwxrwxr-x 3 wj wj   4096 Jun  6 20:49 a1
drwxrwxr-x 3 wj wj   4096 Jun  6 20:49 d1
prw-rw-r-- 1 wj wj      0 Jun  8 13:13 f
-rw-rw-r-- 1 wj wj     76 Jun  9 16:24 test01.c
-rw-rw-r-- 1 wj wj 168908 Jun  7 22:05 test.txt


[wj@VM-4-3-centos code]$ gcc -o testbydanamic.out test01.c
[wj@VM-4-3-centos code]$ gcc -o testbystatic.out test01.c -static


[wj@VM-4-3-centos code]$ ll
total 1036
drwxrwxr-x 3 wj wj   4096 Jun  6 20:49 a1
drwxrwxr-x 3 wj wj   4096 Jun  6 20:49 d1
prw-rw-r-- 1 wj wj      0 Jun  8 13:13 f
-rw-rw-r-- 1 wj wj     76 Jun  9 16:24 test01.c
-rwxrwxr-x 1 wj wj   8360 Jun  9 16:46 testbydanamic.out
-rwxrwxr-x 1 wj wj 861288 Jun  9 16:46 testbystatic.out
-rw-rw-r-- 1 wj wj 168908 Jun  7 22:05 test.txt


[wj@VM-4-3-centos code]$ file testbystatic.out 
testbystatic.out: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=288c6b502993a90057985395771e9f7a7e943d9d, not stripped
[wj@VM-4-3-centos code]$ file testbydanamic.out 
testbydanamic.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=4119b7eb0ca5a268a9911454578b3f33c7060448, not stripped
[wj@VM-4-3-centos code]$

  
  
  
  

3、运行或自动化构建程序:make/makefile

3.1、是什么

   make:一个命令
   makefile:一个文件

在这里插入图片描述
  
  

3.2、怎么用

3.2.1、基本用法说明

   1)、使用makefile、make

  A、makefile创建:
在这里插入图片描述
  补充认识:对makefile的学习只是初步认识,因为实际中我们一般不直接使用它,而是依托于一些能自动生成makefile的工具。
  
  
  B、依赖关系和依赖方法:
  依赖关系:表明谁依赖谁
  依赖方法:表明如何依赖

在这里插入图片描述
  
  
  C、项目清理: 能构建项目,也需要能清理项目

在这里插入图片描述

  
  

   2)、关于makefile文件中多条依赖指令的执行顺序问题

  通常,直接使用make指令,其自顶向下扫描,只会默认执行第一条依赖关系。

在这里插入图片描述
  
  如果要使make执行其它指令,只需要带上对应的目标文件名即可。

[wj@VM-4-3-centos part4]$ ls
Makefile  test.c
[wj@VM-4-3-centos part4]$ cat Makefile
.PHONY:clean	
clean:
	rm -rf mytest
mytest:test.c
	gcc test.c -o mytest
[wj@VM-4-3-centos part4]$ make mytest //带上目标文件名(ps:伪目标也是目标)
gcc test.c -o mytest
[wj@VM-4-3-centos part4]$ ls
Makefile  mytest  test.c
[wj@VM-4-3-centos part4]$ 

  
  

   3)、伪目标介绍: 如何理解“伪目标总是被执行的”这句话?

   演示:

在这里插入图片描述
  
   相关代码:

[wj@VM-4-3-centos part4]$ ls
Makefile  test.c

[wj@VM-4-3-centos part4]$ cat Makefile
mytest:test.c
	gcc test.c -o mytest
.PHONY:clean	
clean:
	rm -rf mytest
	
[wj@VM-4-3-centos part4]$ make
gcc test.c -o mytest
[wj@VM-4-3-centos part4]$ make
make: `mytest' is up to date.
[wj@VM-4-3-centos part4]$ make
make: `mytest' is up to date.
[wj@VM-4-3-centos part4]$ make
make: `mytest' is up to date.

[wj@VM-4-3-centos part4]$ make clean
rm -rf mytest
[wj@VM-4-3-centos part4]$ make clean
rm -rf mytest
[wj@VM-4-3-centos part4]$ make clean
rm -rf mytest


[wj@VM-4-3-centos part4]$ ls
Makefile  test.c
[wj@VM-4-3-centos part4]$ vim Makefile

[wj@VM-4-3-centos part4]$ cat Makefile
.PHONY:mytest
mytest:test.c
	gcc test.c -o mytest
.PHONY:clean	
clean:
	rm -rf mytest
	
[wj@VM-4-3-centos part4]$ make
gcc test.c -o mytest
[wj@VM-4-3-centos part4]$ make
gcc test.c -o mytest
[wj@VM-4-3-centos part4]$ make
gcc test.c -o mytest
[wj@VM-4-3-centos part4]$ 

  
  总结:习惯上,将clean置为伪目标。

  
  
  

   4)、伪目标介绍: makefile如何得知我们的程序是最新的?

相关指令详细:见【ONE·Linux || 常见指令入门(一)】

在这里插入图片描述
  通常,access累积到一定时间才会被修改更新。
  
  
  

   5)、实际运用说明

  通常情况下,我们有main.ctest.ctest.h等各种文件。我们习惯于将main.ctest.c先形成XXX.o可重定向的二进制目标文件,再和动静态库.so/.a链接生成可执行程序。
  以下为它们的依赖关系写法:
  需要注意多文件依赖如何写(中间的空格)。

在这里插入图片描述

  
   PS:实际此处make、make clean的过程类似于VS2019中重新生成解决方案、清理解决方案的过程。
  
  

3.2.2、方法补充

3.2.2.1、目标文件存在多个被依赖文件

  一种简写方法,当存在多个被依赖文件时可以起到简洁方便的作用。

在这里插入图片描述
  
  

3.2.2.2、makefile一次执行多个目标文件

在这里插入图片描述

  
  
  
  
  
  
  

3.3、Linux下的第一个小程序:进度条

3.3.1、预备知识

3.3.1.1、行缓冲区

   1)、行缓冲区

   关于自动补全:

  

在这里插入图片描述

  

   关于sleep在Linux下的使用介绍:

  

在这里插入图片描述
  
  

   实例一:下述代码,先执行sleep,还是先执行打印"hello vim!"?

  1 #include<stdio.h>
  2 #include<unistd.h>                                                                                                                      
  3 int main()
  4 {
  5     printf("hello vim!\n");
  6 
  7     sleep(1);
  8     return 0;
  9 }

  回答:先执行hello vim!

  

   实例二:下述代码,先执行sleep,还是先执行打印"hello vim!"?

  1 #include<stdio.h>
  2 #include<unistd.h>                                                                                                                      
  3 int main()
  4 {
  5     printf("hello vim!");//去掉\n
  6 
  7     sleep(1);
  8     return 0;
  9 }

  回答:先执行sleep。
  
  
  原因解释:

在这里插入图片描述
  
  

  如果要求必须先刷新,可以怎么做?

  用到的相关函数:
  1、fflush:

在这里插入图片描述
  
  2、stdout

在这里插入图片描述

  1 #include<stdio.h>
  2 #include<unistd.h>                                                                                                                      
  3 int main()
  4 {
  5     printf("hello vim!");
  6 	fflush(stdout);
  7     sleep(1);
  8     return 0;
  9 }

  
  

  

3.3.1.2、回车换行

   1)、回车与换行

在这里插入图片描述

  验证方法:
  1、此处使用了\n,在C中表示回车+换行,满足缓冲区刷新条件。

  1 #include<stdio.h>
  2 #include<unistd.h>
  3 
  4 int main(void)
  5 {
  6     int cen=5;
  7     while(cen>=0)
  8     {
  9         printf("当前值:%d\n",cen);//\n能够正常显示
 10         cen--;
 11         sleep(1);                                                                                                                       
 12     }                                                                                          
 13     return 0;                                                                                  
 14 }  

  
  2、此处使用了\r,表示回车,可以看到输出没有显示,数据仍旧在缓冲区。最后一次仍旧显示不出来,是因为当前值:%d\r,结尾\r回车默认光标回到当前行中起始位置。

  1 #include<stdio.h>
  2 #include<unistd.h>
  3 
  4 int main(void)
  5 {
  6     int cen=5;
  7     while(cen>=0)
  8     {
  9         printf("当前值:%d\r",cen);//打印数据在缓冲区中
 10         cen--;
 11         sleep(1);                                                                                                                       
 12     }                                                                                          
 13     return 0;                                                                                  
 14 }  

  
  

3.3.2、逐步形成进度条过程:

3.3.2.1、版本1.0

   1)、倒计时效果
  在上述\r基础上,加入fflush(stdout)

  1 #include<stdio.h>
  2 #include<unistd.h>
  3 int main(void)
  4 {
  5     int cen=5;
  6     while(cen>=0)
  7     {
  8         printf("当前值:%d\r",cen);                                                                                                     
  9         cen--;
 10        	fflush(stdout);
 11         sleep(1);
 12     }
 13     return 0;
 14 }

  
  
   2)、进度条版本1.0

    1 #include<stdio.h>
    2 #include<unistd.h>
    3 #include<string.h>
    4          
    5 #define NUM 102
    6          
    7 int main(void)
    8 {        
    9     char bar[NUM];
   10     memset(bar,0,sizeof(bar));
   11          
   12     int cen=0
   13     while(cen<=100)
   14     {    
   15         printf("%s\n",bar);//使用了换行
   16         bar[cen++]='#';
   17        // fflush(stdout);                                                                                                               
   18         sleep(1);                                                                                      
   19     }                                                                                                  
   20     return 0;                                                                                          
   21 }  

在这里插入图片描述
  
  
  

3.3.2.2、版本2.0

   1)、进度条版本2.0

  1 #include<stdio.h>           
  2 #include<unistd.h>          
  3 #include<string.h>          
  4                             
  5 #define NUM 102             
  6                             
  7 int main(void)              
  8 {                           
  9     char bar[NUM];          
 10     memset(bar,0,sizeof(bar));
 11                             
 12     int cen=0;              
 13     while(cen<=100)         
 14     {                       
 15         printf("%s\r",bar); //使用回车
 16         bar[cen++]='#';     
 17         fflush(stdout);//将fflush显示出来:之前已经讲过原因。                                                                                                                 
 18         sleep(1);
 19     }
 20     return 0;
 21 }

  

   2)、进度条版本2.3

在这里插入图片描述

  1 #include<stdio.h>                 
  2 #include<unistd.h>                
  3 #include<string.h>                
  4                                   
  5 #define NUM 102                   
  6                                                                                                                           
  7 int main(void)                                                                                                            
  8 {                                                                                                                         
  9     char bar[NUM];                                                                                                        
 10     memset(bar,0,sizeof(bar));                                                                                            
 11                                                                                                                           
 12     int cen=0;                                                                                                            
 13     while(cen<=100)                                                                                                       
 14     {                                                                                                                     
 15         printf("%s\r",bar);                                                                                               
 16         bar[cen++]='#';                                                                                                   
 17         fflush(stdout);                                                                                                   
 18         //sleep(1);                                                                                                       
 19         usleep(30000);  //加速                                                                                                  
 20     }                                                                                                                     
 21     printf("\n");   //为了最后结束时指令换行显示                                                                                                                    
 22     return 0;                                            
 23 }
~

  
  
  

3.3.2.3、版本3.0

   1)、进度条版本3.0

  1 #include<stdio.h>                                                                                                            
  2 #include<unistd.h>                                                                                                           
  3 #include<string.h>                                                                                                           
  4                                                                                                                              
  5 #define NUM 102                                                                                                              
  6                                                                                                                              
  7 int main(void)                                                                                                               
  8 {                                                                                                                            
  9     char bar[NUM];                                                                                                           
 10     memset(bar,0,sizeof(bar));                                                                                               
 11                                                                                                                              
 12     int cen=0;                                                                                                               
 13     while(cen<=100)                                                                                                          
 14     {                                                                                                                        
 15         printf("[%s][%d]\r",bar,cen); //对进度条百分比修改                                                                                               
 16         bar[cen++]='#';                        
 17         fflush(stdout);
 18         //sleep(1);
 19         usleep(30000);
 20     }
 21     printf("\n");
 22     return 0;                                            
 23 }

  
  
  
   2)、进度条版本3.2

  1 #include<stdio.h>                                                                                                            
  2 #include<unistd.h>                                                                                                           
  3 #include<string.h>                                                                                                           
  4                                                                                                                              
  5 #define NUM 102                                                                                                              
  6                                                                                                                              
  7 int main(void)                                                                                                               
  8 {                                                                                                                            
  9     char bar[NUM];                                                                                                           
 10     memset(bar,0,sizeof(bar));                                                                                               
 11                                                                                                                              
 12     int cen=0;                                                                                                               
 13     while(cen<=100)                                                                                                          
 14     {                                                                                                                        
 15         printf("[%100s][%d%%]\r",bar,cen);     //结果从右向左跑                                                                                          
 16         bar[cen++]='#';                        
 17         fflush(stdout);
 18         //sleep(1);
 19         usleep(30000);
 20     }
 21     printf("\n");
 22     return 0;                                            
 23 }

  
  
   3)、进度条版本3.4

  1 #include<stdio.h>                                                                                                            
  2 #include<unistd.h>                                                                                                           
  3 #include<string.h>                                                                                                           
  4                                                                                                                              
  5 #define NUM 102                                                                                                              
  6                                                                                                                              
  7 int main(void)                                                                                                               
  8 {                                                                                                                            
  9     char bar[NUM];                                                                                                           
 10     memset(bar,0,sizeof(bar));                                                                                               
 11                                                                                                                              
 12     int cen=0;                                                                                                               
 13     while(cen<=100)                                                                                                          
 14     {                                                                                                                        
 15         printf("[%-100s][%d%%]\r",bar,cen);                                                                                           
 16         bar[cen++]='#';                        
 17         fflush(stdout);
 18         //sleep(1);
 19         usleep(30000);
 20     }
 21     printf("\n");
 22     return 0;                                            
 23 }

  
  
  

3.3.2.4、版本4.0

   1)、进度条版本4.0

    1 #include<stdio.h>  
    2 #include<unistd.h>                            
    3 #include<string.h>                            
    4                                               
    5 #define NUM 102                               
    6                                               
    7 int main(void)                                
    8 {                                             
    9     char bar[NUM];                            
   10     memset(bar,0,sizeof(bar));                
   11                                               
   12     const char*lable="|/-\\";  //实现旋转光标               
   13                                               
   14     int cen=0;                                
   15     while(cen<=100)                           
   16     {                                         
   17         printf("[%-100s][%d%%]%c\r",bar,cen,lable[cen%4]);
   18         bar[cen++]='#';
   19         fflush(stdout);
   20         //sleep(1);
   21         usleep(30000);
   22     }                                                                                                                                 
   23     printf("\n");                                                       
   24     return 0;                                                           
   25 }

在这里插入图片描述

  
  
  
  

4、调试:gdb

4.1、是什么

4.1.1、gcc、g++默认形成的可执行程序版本介绍

   1)、问题引出1:使用gdb调试gcc直接生成的程序会得到什么结果?

  ①准备工作: 我们用于演示的test.c代码如下,是一个计算累加的函数。

  1 #include<stdio.h>
  2 
  3 int AddToTop(int top)
  4 {
  5     int result=0;
  6     int i=0;
  7     for(i=0;i<=top;i++)                                                                                                                                                                 
  8     {
  9         result+=i;
 10     }
 11     return result;
 12 }
 13 
 14 
 15 int main(void)
 16 {
 17     int top=100;
 18 
 19     int res=AddToTop(top);
 20 
 21     printf("res:%d\n",res);
 22 
 23     return 0;
 24 
 25 }

  
  
  ②说明: gcc 、g++默认形成的可执行程序是release,无法直接被调试。
在这里插入图片描述
  相关代码:无法调试,此情况下需要按Q结束调试。

[wj@VM-4-3-centos t1103]$ gdb test.out

GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/wj/one.-studybylinux/study2022/T2211/t1103/test.out...(no debugging symbols found)...done.
(gdb) 

  
  
  这里可以形成一个小考点:
  问题:gcc\g++默认生成的可执行程序具有什么属性?
  回答:gcc、g++默认形成的程序是动态链接的release版本的可执行程序
  
  
  
  ③说明: 如果需要静态链接,则需要添加-static选项,如果需要debug版本,则需要添加-g选项。
  获取debug版本的程序演示如下:
在这里插入图片描述
  相关代码:

[wj@VM-4-3-centos t1103]$ ls
test.c  test.out

[wj@VM-4-3-centos t1103]$ gcc -o testbydebug.out test.c -g

[wj@VM-4-3-centos t1103]$ ls
testbydebug.out  test.c  test.out
[wj@VM-4-3-centos t1103]$ ll
total 28
-rwxrwxr-x 1 wj wj 9640 Nov  3 11:09 testbydebug.out
-rw-rw-r-- 1 wj wj  273 Nov  3 11:01 test.c
-rwxrwxr-x 1 wj wj 8392 Nov  3 11:01 test.out
[wj@VM-4-3-centos t1103]$ 

  

  
  

4.1.2、readelf -S读取可执行程序的工具

  
   1)、基本介绍:
  读取可执行程序的数据段格式工具:readelf -S(读取段)
  可执行程序有各种各样的段。
在这里插入图片描述
  
  为了方便观察,我们做如下操作:
在这里插入图片描述

  
  
  

4.2、怎么做

  说明:gdb是命令行式调试

4.2.1、启动、退出、查看

   1)、启动、退出gdb  

启动:gdb binFile
退出: ctrl + d 或 quit

在这里插入图片描述
  
  

   2)、list、l

list/l 行号:显示binFile源代码,接着上次的位置往下列,每次列10行

在这里插入图片描述
  
  
  
  

4.2.2、运行、断点

   3)、run、r 开始调试

r或run:运行程序。
若没有设置断点,则直接运行结束得到最终结果。

在这里插入图片描述

  
  
  4)、b打断点、info b查看断点 、d删除断点

break(b) +行号:在某一行设置断点
info break :查看断点信息。

在这里插入图片描述
  
  

d、delete +编号:删除断点

在这里插入图片描述

  
  

4.2.3、逐语句&逐过程、变量值&地址值查看、跳出循环

   5)、逐语句、逐过程

n 或 next:单条执行。相当于vs2019里的逐过程F10。
p+变量:打印变量值

在这里插入图片描述
  

s 或 step:进入函数调用。相当于vs2019里的逐语句F11。
breaktrace(或bt):查看各级函数调用及参数(查看当前的调用堆栈)。
finish:执行到当前函数返回(跑完当前函数),然后停下来等待命令。

在这里插入图片描述
  
  

   6)、变量值、地址值查看、跳出循环

display+变量名:跟踪查看一个变量,每次停下来都显示它的值(设置长变量)
undisplay+编号:取消对编号对应的长变量的跟踪(取消长变量)
p+&变量:查看变量地址

在这里插入图片描述
  

until + X行号:跳至X行。
一般不建议非循环过程任意跳动。

在这里插入图片描述

  
  
  

4.2.4、逐段点调试、使能

   7)、逐断点调试

continue(或c):从当前位置开始连续而非单步执行程序,直到遇到下一个断点

在这里插入图片描述
  
  
   8)、使能:断点禁用与启用

disable breakpoints:禁用断点
enable breakpoints:启用断点

在这里插入图片描述

  
  
  
  
  

5、软件包管理器:yum

5.1、软件包

   1)、问题引入

  1、要下载安装一个软件,这个软件是在自己的电脑上吗?
  2、若不在,如何知道在哪里下载?
  3、谁将软件放置在那的?

  
在这里插入图片描述

  
   2)、yum用途
  1、搜索、下载、安装
  2、解决依赖关系
  
  
  

   3)、一些信息认识
  1、一般原生的Linux系统yum内置下载链接基本都是自己配套的国外的网址
  2、我们使用的云服务器使用镜像网址的可能性比较大。
  
  
  

5.2、yum是什么

  1)、基础介绍

[wj@VM-4-3-centos code]$ which yum  
/usr/bin/yum
[wj@VM-4-3-centos code]$ ls /usr/bin/yum -al
-rwxr-xr-x 1 root root 801 Oct  2  2020 /usr/bin/yum
[wj@VM-4-3-centos code]$ vim /usr/bin/yum
[wj@VM-4-3-centos code]$ 

在这里插入图片描述

  问题:yum如何知道具体某个软件需要在哪下载呢?
  回答:这就是接下来我们要讲述的yum源问题。
  
  
  2)、yum源:

  1、yum源就是一个配置文件,用于解决搜索要下载的某个文件该在哪儿寻找的问题。

  2、/etc/yum.repos.d,这是查看yum中yum源的配置路径。

[wj@VM-4-3-centos code]$ ls /etc/yum.repos.d
CentOS-Base.repo  CentOS-Epel.repo  epel.repo  epel-testing.repo

[wj@VM-4-3-centos code]$ ls /etc/yum.repos.d -al
total 44
drwxr-xr-x.  2 root root  4096 Nov  2  2022 .
drwxr-xr-x. 95 root root 12288 Jun  9 13:52 ..
-rw-r--r--   1 root root   614 Aug  8  2022 CentOS-Base.repo
-rw-r--r--   1 root root 12288 Nov  2  2022 .CentOS-Base.repo.swp
-rw-r--r--   1 root root   230 Aug  8  2022 CentOS-Epel.repo
-rw-r--r--   1 root root  1358 Sep  5  2021 epel.repo
-rw-r--r--   1 root root  1457 Sep  5  2021 epel-testing.repo

  
  repo是一些仓库地址。这里我们打开该yun源路径下的一个仓库看看,此处以CentOS-Base.repo为例:需要注意,打开该文件需要使用root权限,因此此处使用了sudo指令。

[wj@VM-4-3-centos t1102]$ sudo /etc/yum.repos.d/CentOS-Base.repo

  相关解释:

在这里插入图片描述
  
  
  3、一些扩展源下载:相关指令

[wj@VM-4-3-centos part5]$ sudo yum install -y epel-release

  
  4、更新yum源:即找一个国内的yum源,替换原先yum源。
  PS:要注意下载后需要将名字替换为原先的CentOS-Base.repo,对于原先的CentOS-Base.repo,可做一个备份(重命名)。
  
  
  
  

5.3、yum三板斧

5.3.1、yum list:如何查看软件

  此处以搜索sl为例。

  1、yum list将所有yum软件包罗列出来。注意,直接使用会出现刷屏现象,取决于你的yum仓库量。

  2、yum有搜索命令,我们可以配合相关查找工具(search)使用,来查找需求的软件。
  例如:搜索sl,可以使用yum search sl
  但其效果也不太好,会直接显示到显示器上,如果输入词条模糊,当相关内容有很多时也不方便查看。

  3、基于上述原因,推荐使用命令:yum list | grep sl

  两者效果图对比:
在这里插入图片描述

  
  
  

5.3.2、yum instal XXX :如何安装软件

  1、yum安装软件需要一定权限,类似于Windows下的管理员身份。

[wj@VM-4-3-centos part5]$ yum install sl //没有使用sudo,普通用户
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
You need to be root to perform this command. //安装失败
[wj@VM-4-3-centos part5]$ 

  
  
  2、sudo yum install XXX
  以安装sl该命令为例:sudo yum install sl

  此处直接输入sl有效是因为一般情况下,yum下载软件时严格匹配名称,虽然上面我们查找出来很多软件,但sl在其中只是名称的一部分。

在这里插入图片描述

  通常情况下,直接使用yum安装软件时,会询问软件占用空间。加入-y选项后表示不必询问直接安装。
  
  2、加入-y选项:

sudo yum install -y sl

  
  
  

5.3.3、yum remove XXX :如何移除已安装软件

  说明:卸载软件仍然是一条命令,仍旧需要root权限:sudo。若加上-y选项,含义同上。

sudo yum remove sl //(需要删除的软件)

sudo yum remove -y sl //不询问是/否,直接卸载

  
  扩展:如何知道哪些软件需要下载?
  回答:随着学习和需求会逐渐了解到。

  扩展:一些有趣的软件/命令下载?
  回答:可网络搜索自行学习。

  
  
  
  
  

6、版本控制器:git

6.0、是什么

  1、多人协作
  2、历史进程
  
  
  
  

6.2、git三板斧

6.0、预先准备:git clone本地克隆

   1)、如何查看自己的git是否已经安装?
   git --version:查看git版本号。

在这里插入图片描述
  
  
  
  
   2)、关于远程仓库的建立?

  step1:

在这里插入图片描述
  
  
  step2:

在这里插入图片描述
  
  
  step3:
在这里插入图片描述
  
  
  step4:克隆到本地Linux下

get clone + 链接地址

  
  例如:git clone https://gitee.com/EPIPHANYECHO/one.-studybylinux.git

[wj@VM-4-3-centos ~]$ ls #原先该目录下文件
install.sh

#使用git clone + https
[wj@VM-4-3-centos ~]$ git clone https://gitee.com/EPIPHANYECHO/one.-studybylinux.git
Cloning into 'one.-studybylinux'...
remote: Enumerating objects: 132, done.
remote: Counting objects: 100% (132/132), done.
remote: Compressing objects: 100% (126/126), done.
remote: Total 132 (delta 39), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (132/132), 383.97 KiB | 0 bytes/s, done.
Resolving deltas: 100% (39/39), done.


[wj@VM-4-3-centos ~]$ ls
install.sh  one.-studybylinux #可以看到远程仓库成功被克隆下来

  
  实际上.git 文件才是主要核心部分。

[wj@VM-4-3-centos one.-studybylinux]$ ls -al
total 28
drwxrwxr-x  4 wj wj 4096 Sep 17 17:31 .
drwx------ 10 wj wj 4096 Sep 17 17:30 ..
drwxrwxr-x  8 wj wj 4096 Sep 20 14:06 .git //.git隐藏文件
-rw-rw-r--  1 wj wj  350 Aug 27 19:37 .gitignore
-rw-rw-r--  1 wj wj  843 Aug 27 19:37 README.en.md
-rw-rw-r--  1 wj wj  932 Aug 27 19:37 README.md
drwxrwxr-x  4 wj wj 4096 Nov  2 22:04 study2022
-rw-rw-r--  1 wj wj    0 Aug 27 19:42 text.c
[wj@VM-4-3-centos one.-studybylinux]$ 

在这里插入图片描述
  

[wj@VM-4-3-centos one.-studybylinux]$ ls -al .git
total 56
drwxrwxr-x 8 wj wj 4096 Jun 10 08:15 .
drwxrwxr-x 5 wj wj 4096 Jun 10 08:19 ..
drwxrwxr-x 2 wj wj 4096 Jun 10 08:15 branches
-rw-rw-r-- 1 wj wj  277 Jun 10 08:15 config
-rw-rw-r-- 1 wj wj   73 Jun 10 08:15 description
-rw-rw-r-- 1 wj wj   23 Jun 10 08:15 HEAD
drwxrwxr-x 2 wj wj 4096 Jun 10 08:15 hooks
-rw-rw-r-- 1 wj wj 6056 Jun 10 08:15 index
drwxrwxr-x 2 wj wj 4096 Jun 10 08:15 info
drwxrwxr-x 3 wj wj 4096 Jun 10 08:15 logs
drwxrwxr-x 4 wj wj 4096 Jun 10 08:15 objects
-rw-rw-r-- 1 wj wj  107 Jun 10 08:15 packed-refs
drwxrwxr-x 5 wj wj 4096 Jun 10 08:15 refs
[wj@VM-4-3-centos one.-studybylinux]$ 

  
  
  
  

6.1、git add:预备提交阶段

   1)、指令介绍:

git add + 你的文件:添加我们的代码到本地仓库

  
  
   2)、相关演示:

  以下为例子:文件study2023为我们待提交文件。

[wj@VM-4-3-centos one.-studybylinux]$ ll
total 16
-rw-rw-r-- 1 wj wj  843 Jun 10 08:15 README.en.md
-rw-rw-r-- 1 wj wj  932 Jun 10 08:15 README.md
drwxrwxr-x 4 wj wj 4096 Jun 10 08:15 study2022
drwxrwxr-x 3 wj wj 4096 Jun 10 08:19 study2023

  git add .可将当前目录下所有文件都预备提交,这里也可指定文件提及比如,git add T2306

[wj@VM-4-3-centos one.-studybylinux]$ cd study2023
[wj@VM-4-3-centos study2023]$ ls
T2306
[wj@VM-4-3-centos study2023]$ git add .  #将当前目录下的所有文件都添加进去

  
  
  

6.2、git commit:本地仓库已经提交阶段

   1)、指令介绍:

get commit -m “ 提交日志xxxxx”

  m是message,后面需要填写提交的日志。在正式工作的场合中,日志内容需要严谨对待。比如,说明你这次提交做了哪些改动,出于什么理由改动等等。即其目的是为了便于了解信息。
  
  
   2)、相关演示:
  以下为例子:信息处内容此处只是随意举例

[wj@VM-4-3-centos study2023]$ git commit -m "博客修改:基本工具介绍章,演示例子"
[master 3bc3250] 博客修改:基本工具介绍章,演示例子
 1 file changed, 10001 insertions(+)
 create mode 100644 study2023/T2306/test.txt
[wj@VM-4-3-centos study2023]$ 

  
  注意:git commit 只是将代码提交到本地仓库里,远程仓库还未同步提交。
  
  

6.3、git push:远程仓库同步阶段

   1)、指令介绍:

get push 

  
  
  
   2)、相关演示:

[wj@VM-4-3-centos study2023]$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

##需要输入账户密码,如需免密可以自行学习
Username for 'https://gitee.com': XXX  ##xxx在这里表示账户
Password for 'https://XXX@gitee.com': ##这里输入账户对应的密码

Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 24.50 KiB | 0 bytes/s, done.
Total 5 (delta 1), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/EPIPHANYECHO/one.-studybylinux.git
   fd0a620..3bc3250  master -> master
[wj@VM-4-3-centos study2023]$ 

  
  
  
  

6.4、其它一些特殊情况介绍

   1)、问题一:第一次使用,需要配置用户名和邮箱
  只需要按照它的要求,把Run下面的那两行指令运行以下就可以,注意邮箱、用户名需要改为自己的信息。

在这里插入图片描述

  
  
  
   2)、问题二:get log 查看提交记录
  以下为演示例子:供显示了三次。

commit 2106aa9f080b6c29bc0d6a2116f92555f40283bf 
Author: 用户名 < 邮箱>
Date:   Tue Sep 20 06:05:14 2022 +0000

    删除文件 study2022/t0914

commit cfa678ae6dc3e041878c1ec4f3f053f96145380d
Author: 用户名 < 邮箱>
Date:   Tue Sep 20 14:04:37 2022 +0800

    修改路径

commit 39d6269fd21c91a9a9706067af6ac58202235ca1
Author: 用户名 < 邮箱>
Date:   Tue Sep 20 13:57:57 2022 +0800

    测试,进程状态与优先级、环境变量

  
  
   3)、问题三:get pull 当无法提交或提交冲突时

[wj@VM-4-3-centos study2022]$ git pull
Already up-to-date.

  一般适用情况是多人协作仓库共享时,需要先同步仓库最新信息。
  
  
  
   4)、问题四:.gitignore的使用

  使用"."来提交当前仓库下所有文件时,会遇到有些不想提交或者不必要提交的后缀文件,这时我们就可以将其添加到.gitignore中。
  在windows下同样如此,需要找到对应的gitignore文件。

在这里插入图片描述

  
  
  
   6.4.5、问题五:git rm XXX 删除某文件
  1、使用git rm删除某文件时,只是在本地仓库删除,实际远程仓库还存在,因此我们还要进行git add、git commit、git push三板斧操作。

  
  
  
  
  
  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值