基础开发工具(上)

文章目录

    • [1. 软件包管理器](#1. 软件包管理器)
    • [2. 编辑器Vim](#2. 编辑器Vim)
    • [3. 编译器gcc/g++](#3. 编译器gcc/g++)

1. 软件包管理器

  1. 查看软件包
    通过 yum list 命令可以罗列出当前一共有哪些软件包。由于包的数目可能非常之多,这里我们需要使用 grep 命令只筛选出我们关注的包。
c 复制代码
yum list | grep gcc
  1. 安装软件
c 复制代码
yum install -y lrzsz
  1. 卸载软件
c 复制代码
yum remove -y lrzsz
  1. 安装源
    Centos中yum源(就是图中所说的yum的配置文件,配置文件中记录了它应该到哪里去找软件并把它下载安装到我们自己的服务器上)的路径:
c 复制代码
[root@VM-4-3-centos ~]# ll /etc/yum.repos.d
total 8
-rw-r--r-- 1 root root 614 Nov 12  2024 CentOS-Base.repo
-rw-r--r-- 1 root root 230 Nov 12  2024 CentOS-Epel.repo

安装源的代码可以在网上进行查找。(云服务器不用考虑,因为软件源都是国内的了)

2. 编辑器Vim

vim 有很多种模式,要查看所有模式:打开 vim,底行模式直接输入 help vim-modes

移动光标:

  • 按「e」:光标跳到这个字的字尾
  • 按「#l」:光标移到相对于光标现在位置的该行的第#个位置,如:5l,56l
  • 按「ctrl」+「b」:屏幕往"后"移动一页
  • 按「ctrl」+「f」:屏幕往"前"移动一页
  • 按「ctrl」+「u」:屏幕往"后"移动半页
  • 按「ctrl」+「d」:屏幕往"前"移动半页

复制:

  • 「yw」:将光标所在之处到字尾的字符复制到缓冲区中
  • 「#yw」:复制#个字到缓冲区

简单vim配置

配置文件的位置:

  • 在目录 /etc/ 下面,有个名为vimrc的文件,这是系统中公共的vim配置文件,对所有用户都有效。
  • 而在每个用户的家目录下,都可以自己建立私有的配置文件,命名为:".vimrc",这个配置文件只对自己有效,不会影响其他用户。

具体如何配置可以自行查找资料,或者用这个链接中的(只适用于Centos 7,想在哪个用户下让vim配置生效,就在哪个用户下执行这个指令,强烈 "不推荐" 直接在 root 下执行)。


一个普通用户要使用 sudo,需要先在 /etc/sudoers 中添加上自己的用户名。(用 root 账号打开这个文件,增加上这个普通用户的用户名,强制保存退出就可以了)

3. 编译器gcc/g++

c 复制代码
[gsm@VM-4-3-centos lesson6]$ ll
total 0
[gsm@VM-4-3-centos lesson6]$ vim code.c
[gsm@VM-4-3-centos lesson6]$ ll
total 4
-rw-rw-r-- 1 gsm gsm 286 Oct 11 21:27 code.c
[gsm@VM-4-3-centos lesson6]$ gcc code.c 
[gsm@VM-4-3-centos lesson6]$ ll
total 16
-rwxrwxr-x 1 gsm gsm 8360 Oct 11 21:28 a.out
-rw-rw-r-- 1 gsm gsm  286 Oct 11 21:27 code.c
[gsm@VM-4-3-centos lesson6]$ ./a.out 
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
[gsm@VM-4-3-centos lesson6]$ rm a.out 
[gsm@VM-4-3-centos lesson6]$ gcc -o code code.c 
[gsm@VM-4-3-centos lesson6]$ ll
total 16
-rwxrwxr-x 1 gsm gsm 8360 Oct 11 21:29 code
-rw-rw-r-- 1 gsm gsm  286 Oct 11 21:27 code.c
[gsm@VM-4-3-centos lesson6]$ ./code 
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
[gsm@VM-4-3-centos lesson6]$ rm code
[gsm@VM-4-3-centos lesson6]$ ll
total 4
-rw-rw-r-- 1 gsm gsm 286 Oct 11 21:27 code.c
[gsm@VM-4-3-centos lesson6]$ gcc code.c -o code
[gsm@VM-4-3-centos lesson6]$ ll
total 16
-rwxrwxr-x 1 gsm gsm 8360 Oct 11 21:30 code
-rw-rw-r-- 1 gsm gsm  286 Oct 11 21:27 code.c
[gsm@VM-4-3-centos lesson6]$ ./code 
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
[gsm@VM-4-3-centos lesson6]$ ll
total 16
-rwxrwxr-x 1 gsm gsm 8360 Oct 11 21:30 code
-rw-rw-r-- 1 gsm gsm  286 Oct 11 21:27 code.c
[gsm@VM-4-3-centos lesson6]$ rm code
[gsm@VM-4-3-centos lesson6]$ ll
total 4
-rw-rw-r-- 1 gsm gsm 286 Oct 11 21:27 code.c
[gsm@VM-4-3-centos lesson6]$ gcc -o test code.c 
[gsm@VM-4-3-centos lesson6]$ ll
total 16
-rw-rw-r-- 1 gsm gsm  286 Oct 11 21:27 code.c
-rwxrwxr-x 1 gsm gsm 8360 Oct 11 21:31 test
[gsm@VM-4-3-centos lesson6]$ ./test 
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
[gsm@VM-4-3-centos lesson6]$ ll
total 16
-rw-rw-r-- 1 gsm gsm  286 Oct 11 21:27 code.c
-rwxrwxr-x 1 gsm gsm 8360 Oct 11 21:31 test
[gsm@VM-4-3-centos lesson6]$ test
[gsm@VM-4-3-centos lesson6]$ vim code.c 
[gsm@VM-4-3-centos lesson6]$ gcc -o test code.c 
[gsm@VM-4-3-centos lesson6]$ ll
total 16
-rw-rw-r-- 1 gsm gsm  418 Oct 11 21:32 code.c
-rwxrwxr-x 1 gsm gsm 8360 Oct 11 21:32 test
[gsm@VM-4-3-centos lesson6]$ test
[gsm@VM-4-3-centos lesson6]$ ./test 
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
[gsm@VM-4-3-centos lesson6]$ which test
/usr/bin/test
[gsm@VM-4-3-centos lesson6]$ ls /usr/bin/test
/usr/bin/test
[gsm@VM-4-3-centos lesson6]$ ll
total 16
-rw-rw-r-- 1 gsm gsm  418 Oct 11 21:32 code.c
-rwxrwxr-x 1 gsm gsm 8360 Oct 11 21:32 test
[gsm@VM-4-3-centos lesson6]$ ./test 
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
[gsm@VM-4-3-centos lesson6]$ rm test
[gsm@VM-4-3-centos lesson6]$ gcc -o code code.c 
[gsm@VM-4-3-centos lesson6]$ ll
total 16
-rwxrwxr-x 1 gsm gsm 8360 Oct 11 21:33 code
-rw-rw-r-- 1 gsm gsm  418 Oct 11 21:32 code.c
[gsm@VM-4-3-centos lesson6]$ ./code 
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
[gsm@VM-4-3-centos lesson6]$ code
-bash: code: command not found
[gsm@VM-4-3-centos lesson6]$ ll
total 16
-rwxrwxr-x 1 gsm gsm 8360 Oct 11 21:33 code
-rw-rw-r-- 1 gsm gsm  418 Oct 11 21:32 code.c
[gsm@VM-4-3-centos lesson6]$ rm code
[gsm@VM-4-3-centos lesson6]$ ll
total 4
-rw-rw-r-- 1 gsm gsm 418 Oct 11 21:32 code.c
c 复制代码
[gsm@VM-4-3-centos lesson6]$ ll
total 4
-rw-rw-r-- 1 gsm gsm 418 Oct 11 21:32 code.c
[gsm@VM-4-3-centos lesson6]$ gcc -E code.c -o code.i
[gsm@VM-4-3-centos lesson6]$ ll
total 24
-rw-rw-r-- 1 gsm gsm   418 Oct 11 21:32 code.c
-rw-rw-r-- 1 gsm gsm 17201 Oct 11 21:41 code.i
[gsm@VM-4-3-centos lesson6]$ vim code.i
[gsm@VM-4-3-centos lesson6]$ ll
total 24
-rw-rw-r-- 1 gsm gsm   418 Oct 11 21:32 code.c
-rw-rw-r-- 1 gsm gsm 17201 Oct 11 21:41 code.i
[gsm@VM-4-3-centos lesson6]$ gcc -S code.i -o code.s
[gsm@VM-4-3-centos lesson6]$ ll
total 28
-rw-rw-r-- 1 gsm gsm   418 Oct 11 21:32 code.c
-rw-rw-r-- 1 gsm gsm 17201 Oct 11 21:41 code.i
-rw-rw-r-- 1 gsm gsm   934 Oct 11 21:44 code.s
[gsm@VM-4-3-centos lesson6]$ vim code.s
[gsm@VM-4-3-centos lesson6]$ gcc -c code.c -o code.o
[gsm@VM-4-3-centos lesson6]$ ll
total 32
-rw-rw-r-- 1 gsm gsm   418 Oct 11 21:32 code.c
-rw-rw-r-- 1 gsm gsm 17201 Oct 11 21:41 code.i
-rw-rw-r-- 1 gsm gsm  1992 Oct 11 21:48 code.o
-rw-rw-r-- 1 gsm gsm   934 Oct 11 21:44 code.s
[gsm@VM-4-3-centos lesson6]$ vim code.o
[gsm@VM-4-3-centos lesson6]$ ll
total 32
-rw-rw-r-- 1 gsm gsm   418 Oct 11 21:32 code.c
-rw-rw-r-- 1 gsm gsm 17201 Oct 11 21:41 code.i
-rw-rw-r-- 1 gsm gsm  1992 Oct 11 21:48 code.o
-rw-rw-r-- 1 gsm gsm   934 Oct 11 21:44 code.s
[gsm@VM-4-3-centos lesson6]$ ./code.o
-bash: ./code.o: Permission denied
[gsm@VM-4-3-centos lesson6]$ chmod u+x code.o
[gsm@VM-4-3-centos lesson6]$ ll
total 32
-rw-rw-r-- 1 gsm gsm   418 Oct 11 21:32 code.c
-rw-rw-r-- 1 gsm gsm 17201 Oct 11 21:41 code.i
-rwxrw-r-- 1 gsm gsm  1992 Oct 11 21:48 code.o
-rw-rw-r-- 1 gsm gsm   934 Oct 11 21:44 code.s
[gsm@VM-4-3-centos lesson6]$ ./code.o
-bash: ./code.o: cannot execute binary file
[gsm@VM-4-3-centos lesson6]$ chmod u-x code.o
[gsm@VM-4-3-centos lesson6]$ ll
total 32
-rw-rw-r-- 1 gsm gsm   418 Oct 11 21:32 code.c
-rw-rw-r-- 1 gsm gsm 17201 Oct 11 21:41 code.i
-rw-rw-r-- 1 gsm gsm  1992 Oct 11 21:48 code.o
-rw-rw-r-- 1 gsm gsm   934 Oct 11 21:44 code.s
[gsm@VM-4-3-centos lesson6]$ gcc -o code code.o
[gsm@VM-4-3-centos lesson6]$ ll
total 44
-rwxrwxr-x 1 gsm gsm  8360 Oct 11 21:55 code
-rw-rw-r-- 1 gsm gsm   418 Oct 11 21:32 code.c
-rw-rw-r-- 1 gsm gsm 17201 Oct 11 21:41 code.i
-rw-rw-r-- 1 gsm gsm  1992 Oct 11 21:48 code.o
-rw-rw-r-- 1 gsm gsm   934 Oct 11 21:44 code.s
[gsm@VM-4-3-centos lesson6]$ ./code 
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
c 复制代码
[gsm@VM-4-3-centos lesson6]$ ll
total 44
-rwxrwxr-x 1 gsm gsm  8360 Oct 11 21:55 code
-rw-rw-r-- 1 gsm gsm   418 Oct 11 21:32 code.c
-rw-rw-r-- 1 gsm gsm 17201 Oct 11 21:41 code.i
-rw-rw-r-- 1 gsm gsm  1992 Oct 11 21:48 code.o
-rw-rw-r-- 1 gsm gsm   934 Oct 11 21:44 code.s
[gsm@VM-4-3-centos lesson6]$ ldd code
	linux-vdso.so.1 =>  (0x00007ffc259e4000)
	libc.so.6 => /lib64/libc.so.6 (0x00007fe08b792000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fe08bb60000)
[gsm@VM-4-3-centos lesson6]$ ll /lib64/libc.so.6
lrwxrwxrwx 1 root root 12 Jul  8  2024 /lib64/libc.so.6 -> libc-2.17.so
[gsm@VM-4-3-centos lesson6]$ which ls
alias ls='ls --color=auto'
	/usr/bin/ls
[gsm@VM-4-3-centos lesson6]$ ldd /usr/bin/ls
	linux-vdso.so.1 =>  (0x00007fff0c2ef000)
	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fd8e18d2000)
	libcap.so.2 => /lib64/libcap.so.2 (0x00007fd8e16cd000)
	libacl.so.1 => /lib64/libacl.so.1 (0x00007fd8e14c4000)
	libc.so.6 => /lib64/libc.so.6 (0x00007fd8e10f6000)
	libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fd8e0e94000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007fd8e0c90000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fd8e1af9000)
	libattr.so.1 => /lib64/libattr.so.1 (0x00007fd8e0a8b000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fd8e086f000)
[gsm@VM-4-3-centos lesson6]$ which top
/usr/bin/top
[gsm@VM-4-3-centos lesson6]$ ldd /usr/bin/top
	linux-vdso.so.1 =>  (0x00007ffe33dfb000)
	libprocps.so.4 => /lib64/libprocps.so.4 (0x00007f19fd898000)
	libsystemd.so.0 => /lib64/libsystemd.so.0 (0x00007f19fd667000)
	libncurses.so.5 => /lib64/libncurses.so.5 (0x00007f19fd440000)
	libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007f19fd216000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f19fd012000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f19fcc44000)
	libcap.so.2 => /lib64/libcap.so.2 (0x00007f19fca3f000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f19fc73d000)
	librt.so.1 => /lib64/librt.so.1 (0x00007f19fc535000)
	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f19fc30e000)
	liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f19fc0e8000)
	liblz4.so.1 => /lib64/liblz4.so.1 (0x00007f19fbed9000)
	libgcrypt.so.11 => /lib64/libgcrypt.so.11 (0x00007f19fbc58000)
	libgpg-error.so.0 => /lib64/libgpg-error.so.0 (0x00007f19fba53000)
	libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f19fb839000)
	libdw.so.1 => /lib64/libdw.so.1 (0x00007f19fb5e8000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f19fb3d2000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f19fb1b6000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f19fdabf000)
	libattr.so.1 => /lib64/libattr.so.1 (0x00007f19fafb1000)
	libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f19fad4f000)
	libelf.so.1 => /lib64/libelf.so.1 (0x00007f19fab37000)
	libz.so.1 => /lib64/libz.so.1 (0x00007f19fa921000)
	libbz2.so.1 => /lib64/libbz2.so.1 (0x00007f19fa711000)
[gsm@VM-4-3-centos lesson6]$ ldd /usr/bin/whoami
	linux-vdso.so.1 =>  (0x00007ffd577df000)
	libc.so.6 => /lib64/libc.so.6 (0x00007fe83b41f000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fe83b7ed000)
c 复制代码
[gsm@VM-4-3-centos lesson6]$ ll
total 44
-rwxrwxr-x 1 gsm gsm  8360 Oct 11 21:55 code
-rw-rw-r-- 1 gsm gsm   418 Oct 11 21:32 code.c
-rw-rw-r-- 1 gsm gsm 17201 Oct 11 21:41 code.i
-rw-rw-r-- 1 gsm gsm  1992 Oct 11 21:48 code.o
-rw-rw-r-- 1 gsm gsm   934 Oct 11 21:44 code.s
[gsm@VM-4-3-centos lesson6]$ ldd code
	linux-vdso.so.1 =>  (0x00007fff1d3f1000)
	libc.so.6 => /lib64/libc.so.6 (0x00007ff285040000)
	/lib64/ld-linux-x86-64.so.2 (0x00007ff28540e000)
[gsm@VM-4-3-centos lesson6]$ file code
code: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=c9dee9b5e257c3a17d692e41c04f86f2f62453ee, not stripped
[gsm@VM-4-3-centos lesson6]$ ldd code
	linux-vdso.so.1 =>  (0x00007ffcb69b3000)
	libc.so.6 => /lib64/libc.so.6 (0x00007fc57032b000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fc5706f9000)
[gsm@VM-4-3-centos lesson6]$ gcc -o code_static code.s -static
[gsm@VM-4-3-centos lesson6]$ ll
total 888
-rwxrwxr-x 1 gsm gsm   8360 Oct 11 21:55 code
-rw-rw-r-- 1 gsm gsm    418 Oct 11 21:32 code.c
-rw-rw-r-- 1 gsm gsm  17201 Oct 11 21:41 code.i
-rw-rw-r-- 1 gsm gsm   1992 Oct 11 21:48 code.o
-rw-rw-r-- 1 gsm gsm    934 Oct 11 21:44 code.s
-rwxrwxr-x 1 gsm gsm 861216 Oct 12 15:09 code_static
[gsm@VM-4-3-centos lesson6]$ ./code_static 
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
hello bit, hello : 100
[gsm@VM-4-3-centos lesson6]$ file code_static 
code_static: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=7cd8bff7f31e73bfe6397aab4e1a524044474f9f, not stripped
[gsm@VM-4-3-centos lesson6]$ ls /lib64/libc.a
/lib64/libc.a
[gsm@VM-4-3-centos lesson6]$ ls /lib64/libc.a -al
-rw-r--r-- 1 root root 5105516 Jun  4  2024 /lib64/libc.a
相关推荐
Doro再努力1 分钟前
Vim 快速上手实操手册:从入门到生产环境实战
linux·编辑器·vim
wypywyp8 分钟前
8. ubuntu 虚拟机 linux 服务器 TCP/IP 概念辨析
linux·服务器·ubuntu
Doro再努力23 分钟前
【Linux操作系统10】Makefile深度解析:从依赖推导到有效编译
android·linux·运维·服务器·编辑器·vim
senijusene27 分钟前
Linux软件编程:IO编程,标准IO(1)
linux·运维·服务器
忧郁的橙子.35 分钟前
02-本地部署Ollama、Python
linux·运维·服务器
醇氧44 分钟前
【linux】查看发行版信息
linux·运维·服务器
No8g攻城狮1 小时前
【Linux】Windows11 安装 WSL2 并运行 Ubuntu 22.04 详细操作步骤
linux·运维·ubuntu
XiaoFan0122 小时前
免密批量抓取日志并集中输出
java·linux·服务器
souyuanzhanvip2 小时前
ServerBox v1.0.1316 跨平台 Linux 服务器管理工具
linux·运维·服务器
HalvmånEver3 小时前
Linux:线程互斥
java·linux·运维