# Linux源码安装和管理
# 目录
[TOC]
# 1.cmake的使用
# 2.bash脚本的阅读
whoway@XXX:~/arm-classic-flang/classic-flang-llvm-project/clang$ find -name stdalign.h
./lib/Headers/stdalign.h
whoway@XXX:~/arm-classic-flang/classic-flang-llvm-project/clang$ vim $(find -name stdalign.h)
2
3
# 3.环境变量
# Linux中PATH
、 LIBRARY_PATH
、 LD_LIBRARY_PATH
的区别
接触Linux或类Unix的系统多了,就会逃不出环境配置,而各种路径(PATH)就是环境的配置中较为重要的一点
PATH是可执行文件路径,是三个中我们最常接触到的,因为我们命令行中的每句能运行的命令,如ls、top、ps等,都是系统通过PATH找到了这个命令执行文件的所在位置,再run这个命令(可执行文件)。
**实验:**执行echo $PATH
能看到当前环境的PATH都配置哪些路径
LIBRARY_PATH和LD_LIBRARY_PATH
这两个路径可以放在一起讨论,
LIBRARY_PATH
是程序编译期间查找动态链接库时指定查找共享库的路径- library_path
LD_LIBRARY_PATH
是程序加载运行期间查找动态链接库时指定除了系统默认路径之外的其他路径- ld_library_path
两者的共同点是库,库是这两个路径和PATH路径的区别,PATH是可执行文件。
两者的差异点是使用时间不一样。
- 一个是编译期,对应的是开发阶段,如gcc编译;
- 一个是加载运行期,对应的是程序已交付的使用阶段。
参考链接:https://www.imooc.com/article/43747
示例如下:
export LD_LIBRARY_PATH=/home/whoway/work/install/lib:$LD_LIBRARY_PATH
export PATH=/home/whoway/work/install/bin:$PATH
export LIBRARY_PATH=/home/whoway/work/install/lib:$LIBRARY_PATH
2
3
# 4.区分ubuntu apt-get的update和upgrade的区别
apt-get作为包管理器,其实类似于咱们在windows上使用的软件管家类的软件。
当运行
apt-get update
命令的时候,实际上相当于软件管家的“查找更新”操作。它会同步/etc/apt/sources.list
和/etc/apt/sources.list.d
中列出的源的索引信息(软件包的版本信息、系统要求、翻译、依赖关系等等)。当运行
apt-get upgrade
命令的时候,实际上相当于软件管家的“一键更新”操作。它会对已经安装有更新的软件进行自动升级。由于确定要更新的软件包需要对本地安装的版本和列表的版本进行比较,所以要在update以后运行这一条
update
命令只会获得系统上所有包的最新信息,并不会下载或者安装任何一个包。而是 apt upgrade
命令来把这些包下载和升级到最新版本。
# 5.linux软件版本管理命令
update-alternatives
update-alternatives 命令用于处理linux系统中软件版本的切换,在各个linux发行版中均提供了该命令,命令参数略有区别,但大致是一样的。
设置gcc多版本
root@ubuntu:~/huawei# ls /usr/bin/gcc*
/usr/bin/gcc-7 /usr/bin/gcc-ar-7 /usr/bin/gcc-nm-7 /usr/bin/gcc-ranlib-7
/usr/bin/gcc-8 /usr/bin/gcc-ar-8 /usr/bin/gcc-nm-8 /usr/bin/gcc-ranlib-8
/usr/bin/gcc-9 /usr/bin/gcc-ar-9 /usr/bin/gcc-nm-9 /usr/bin/gcc-ranlib-9
root@ubuntu:~/huawei# update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 20 --slave /usr/bin/g++ g++ /usr/bin/g++-9
update-alternatives: using /usr/bin/gcc-9 to provide /usr/bin/gcc (gcc) in auto mode
root@ubuntu:~/huawei# update-alternatives --config gcc
There is only one alternative in link group gcc (providing /usr/bin/gcc): /usr/bin/gcc-9
Nothing to configure.
root@ubuntu:~/huawei# update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 10 --slave /usr/bin/g++ g++ /usr/bin/g++-8
root@ubuntu:~/huawei# update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/gcc-9 20 auto mode
1 /usr/bin/gcc-8 10 manual mode
2 /usr/bin/gcc-9 20 manual mode
Press <enter> to keep the current choice[*], or type selection number: ^Hn^H^H^H^Hq^H
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/gcc-9 20 auto mode
1 /usr/bin/gcc-8 10 manual mode
2 /usr/bin/gcc-9 20 manual mode
Press <enter> to keep the current choice[*], or type selection number:
root@ubuntu:~/huawei# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/9/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=aarch64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~18.04)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
root@ubuntu:~/huawei# update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-9 20
update-alternatives: using /usr/bin/gfortran-9 to provide /usr/bin/gfortran (gfortran) in auto mode
2
3
# 6.重定向-当前年-月-日-时间-秒数
- 输出秒数,比如告诉编译时间
root@ubuntu:~# cat auto.sh
#!/bin/bash
echo 'begin'
echo $(date +%F-%R-%T)
sleep 10s
echo 'end'
echo $(date +%F-%R-%T)
2
3
4
5
6
7
root@ubuntu:~# bash auto.sh
begin
2022-11-18-16:35-16:35:02
end
2022-11-18-16:35-16:35:12
2
3
4
5
Linux打印显示时间
# .gcc使用
# gcc 关闭warning警告
「小写的」-w的意思是关闭编译时的警告,也就是编译后不显示任何warning,因为有时在编译之后编译器会显示一些例如数据转换之类的警告,这些警告是我们平时可以忽略的。
「全称单词」-Wall选项意思是编译后显示所有警告。
「大写的」-W选项类似-Wall,会显示警告,但是只显示编译器认为会出现错误的警告。
2
3
4
# 8.arm换源
## Note, this file is written by cloud-init on first boot of an instance
## modifications made here will not survive a re-bundle.
## if you wish to make changes you can:
## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
## or do the same in user-data
## b.) add sources in /etc/apt/sources.list.d
## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.aliyun.com/ubuntu-ports bionic main restricted
deb-src http://mirrors.aliyun.com/ubuntu-ports bionic main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.aliyun.com/ubuntu-ports bionic-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu-ports bionic-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.aliyun.com/ubuntu-ports bionic universe
deb-src http://mirrors.aliyun.com/ubuntu-ports bionic universe
deb http://mirrors.aliyun.com/ubuntu-ports bionic-updates universe
deb-src http://mirrors.aliyun.com/ubuntu-ports bionic-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://mirrors.aliyun.com/ubuntu-ports bionic multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports bionic multiverse
deb http://mirrors.aliyun.com/ubuntu-ports bionic-updates multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports bionic-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://mirrors.aliyun.com/ubuntu-ports bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu-ports bionic-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu-ports bionic-security main restricted
deb http://mirrors.aliyun.com/ubuntu-ports bionic-security universe
deb-src http://mirrors.aliyun.com/ubuntu-ports bionic-security universe
deb http://mirrors.aliyun.com/ubuntu-ports bionic-security multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports bionic-security multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 12.nohup
root@ubuntu:~# nohup bash test.sh > mylog &
[1] 12977
root@ubuntu:~# nohup: ignoring input and redirecting stderr to stdout
[1]+ Done nohup bash test.sh > mylog
root@ubuntu:~# l
gitee/ huawei/ my-classic-flang-source.sh mylog rollback/ test.sh time-echo.sh
root@ubuntu:~# vim test.sh
root@ubuntu:~# vim mylog
root@ubuntu:~# cat mylog
begin
2022-11-18-18:25-18:25:41
end
2022-11-18-18:25-18:25:51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- 如果不指定,运行方法是
root@ubuntu:~# nohup bash test.sh &
[1] 13130
root@ubuntu:~# nohup: ignoring input and appending output to 'nohup.out'
[1]+ Done nohup bash test.sh
root@ubuntu:~# l
gitee/ huawei/ my-classic-flang-source.sh nohup.out rollback/ test.sh time-echo.sh
root@ubuntu:~# cat nohup.out
begin
2022-11-18-18:29-18:29:39
end
2022-11-18-18:29-18:29:49
2
3
4
5
6
7
8
9
10
11
12
13
不退出
root@ubuntu:~# nohup bash test.sh &
[1] 13220
root@ubuntu:~# nohup: ignoring input and appending output to 'nohup.out'
# 显示上面的时候,我们就可以回车,继续我们的工作了
root@ubuntu:~# whoami
root
root@ubuntu:~# l
gitee/ huawei/ my-classic-flang-source.sh nohup.out rollback/ test.sh time-echo.sh
root@ubuntu:~# l
gitee/ huawei/ my-classic-flang-source.sh nohup.out rollback/ test.sh time-echo.sh
[1]+ Done nohup bash test.sh
2
3
4
5
6
7
8
9
10
11
12
13
14
- 如果想要第1个的那种,不显示啥
nohup: ignoring input and redirecting stderr to stdout
,需要加上2>&1
- 原因,如果不加这个命令,会给我产生两个文件,
temp.txt
来记录你的那个,另一个是nohup.out文件。
- 原因,如果不加这个命令,会给我产生两个文件,
root@ubuntu:~# nohup bash test.sh > mylog 2>&1 &
[1] 13233
root@ubuntu:~# ps
PID TTY TIME CMD
13101 pts/1 00:00:00 bash
13233 pts/1 00:00:00 bash
13235 pts/1 00:00:00 sleep
13236 pts/1 00:00:00 ps
root@ubuntu:~# ps -aux | grep 13233
root 13239 0.0 0.0 5664 648 pts/1 S+ 18:38 0:00 grep --color=auto 13233
[1]+ Done nohup bash test.sh > mylog 2>&1
root@ubuntu:~# l
gitee/ huawei/ my-classic-flang-source.sh mylog nohup.out rollback/ test.sh time-echo.sh
root@ubuntu:~# whoami
root
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 1小时的测试
root@ubuntu:~# nohup bash test.sh > mylog 2>&1 &
[1] 13272⭐️
root@ubuntu:~# l
gitee/ huawei/ my-classic-flang-source.sh mylog rollback/ test.sh time-echo.sh
root@ubuntu:~# cat mylog
nohup: ignoring input
begin
2022-11-18-18:41-18:41:20
root@ubuntu:~# cat test.sh
#!/bin/bash
echo 'begin'
echo $(date +%F-%R-%T)
sleep 1h
echo 'end'
echo $(date +%F-%R-%T)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
关闭他,新增后台
root@ubuntu:~# ps -aux | grep sleep
root 13274 0.0 0.0 4760 436 ? S 18:41 0:00 sleep 1h
root 13372⭐️ 0.0 0.0 5664 628 pts/1 S+ 18:42 0:00 grep --color=auto sleep
2
3
4
# 13.apt啥的install的也可以是编译后的包
# 我的linux软件包
apt install lrzsz
2