linux版本
linux所有的发行版都是使用linux内核,只是所集成的软件包不同。
| 发行版 | 描述 | 衍生版 |
|---|---|---|
| debian | Debian GNU / Linux是一种强调使用自由软件的发行版,支持多种硬件平台。Debian及其派生发行版使用deb软件包格式,并使用dpkg及其前端作为软件包管理器。 | Ubuntu、Deepin |
| redhat | Red Hat Linux和SUSE Linux是最早使用RPM格式软件包的发行版,如今RPM格式已广泛运用于众多的发行版。这两种发行版后来都分为商业版本和社区支持版本。Red Hat Linux的社区支持版本现称为Fedora,商业版本则称为Red Hat Enterprise Linux。 | CentOS、Fedora |
| ArchLinux | 基于KISS原则,针对x86-64的CPU做了优化,以.pkg.tar.xz格式打包并由包管理器进行跟踪维护,特别适合动手能力强的Linux用户。 | Manjaro |
| slackware | Slackware走了一条同其他的发行版本(Red Hat、Debian、Gentoo、SuSE、 Mandriva、Ubuntu等)不同的道路,它力图成为“UNIX风格”的Linux发行版本。它的方针是只吸收稳定版本的应用程序,并且缺少其他Linux版本中那些为发行版本定制的配置工具。 | openSUSE |
| Gentoo | 这个包采用自己独特的Portage包管理系统,吸引了许多狂热爱好者以及专业人士,由于能自己编译及调整源码依赖等选项,而获得至高的自定义性及优化的软件,在源码包也有相当多新旧版本的选择,是个强调能自由选择的发行版。 | Chrome OS |
| LFS | 全称为Linux From Scratch,最终的系统从源代码直接编译生成。Linux From Scratch 这个项目以及使用 LFS 系统带来的好处是--用户可以控制系统的所有特征,包括目录布局、脚本设置和安全设置等等,用户可以指定在哪里安装、为什么安装以及怎样安装每一个程序,可以完全按照自己的需求定制他们的 Linux 系统,而且使用户对他们的系统有更多的控制权。 | - |
| Alpine | 一个面向安全的轻型 Linux 发行版。它不同于通常 Linux 发行版,Alpine 采用了 musllibc 和 busybox 以减小系统的体积和运行时资源消耗,但功能上比 busybox 又完善的多,只有5M左右大小 | - |
目录及用途
- /boot:引导文件存放目录,内核文件(vmlinuz)、引导加载器(bootloader, grub)都存放于此目录
- /bin:所有用户使用的基本命令;不能关联至独立分区,OS启动即会用到的程序
- /sbin:管理类的基本命令;不能关联至独立分区,OS启动即会用到的程序
- /lib:启动时程序依赖的基本共享库文件以及内核模块文件(/lib/modules)
- /lib64:专用于x86_64系统上的辅助共享库文件存放位置
- /etc:配置文件目录
- /home/USERNAME:普通用户家目录
- /root:管理员的家目录
- /media:便携式移动设备挂载点
- /mnt:临时文件系统挂载点
- /dev:设备文件及特殊文件存储位置
- /opt:第三方应用程序的安装位置
- /srv:系统上运行的服务用到的数据
- /tmp:临时文件存储位置
- /proc: 用于输出内核与进程信息相关的虚拟文件系统
- /sys:用于输出当前系统上硬件设备相关信息虚拟文件系统
- /selinux: security enhanced Linux,selinux相关的安全策略等信息的存储位置
- /usr: 共享的通用程序文件
- /var:可变数据文件
history命令显示时间
# 修改HISTTIMEFORMAT变量
[xingmu@shanghai tt]$ HISTTIMEFORMAT='%F %T '
[xingmu@shanghai tt]$ history
1 2022-04-22 18:37:10 mai
2 2022-04-22 18:37:12 mail
3 2022-04-22 19:07:52 id -u
4 2022-04-22 19:07:54 id -g
5 2022-04-22 19:07:58 id -o
6 2022-04-22 19:08:00 id
7 2022-04-22 20:54:32 ps aux
linux哲学思想
- 一切都是一个文件(包括硬件)
- 小型,单一用途的程序
- 链接程序,共同完成复杂的任务
- 避免令人困惑的用户界面
- 配置数据存储在文本中
linnux命令使用格式
常用Linux命令格式为:command [-option] [parameter]
command表示命令名;
option是命令选项,可以通过指定选项来实现不同的命令执行结果,可用来对命令进行控制,如果没有表示使用命令默认功能;
paramet:是传给命令的参数,可以是零,一个或者多个
# echo是要执行的命令
# n是echo命令的一个选项,表示输出结果最后不换行
# xingmu 就是传递给命令的参数
[xingmu@shanghai tt]$ echo -n xingmu
练习
-
显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录
# 首先复制 etc 到/tmp目录下做这个试验 [xingmu@localhost tmp]$ sudo cp -r /etc ./etc # 由于etc目录下面没有符合条件的文件或文件夹,先创建几个符合条件的文件和文件夹 [xingmu@localhost etc]$ mkdir {1..3}{a..f} [xingmu@localhost etc]$ touch {1..3}{a..f}.txt [xingmu@localhost etc]$ ls -d [^[:alpha:]][[:alpha:]]* 1a 1b 1c 1d 1e 1f 2a 2b 2c 2d 2e 2f 3a 3b 3c 3d 3e 3f 1a.txt 1b.txt 1c.txt 1d.txt 1e.txt 1f.txt 2a.txt 2b.txt 2c.txt 2d.txt 2e.txt 2f.txt 3a.txt 3b.txt 3c.txt 3d.txt 3e.txt 3f.txt -
复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。
[xingmu@localhost etc]$ mkdir /tmp/mytest1 [xingmu@localhost etc]$ cp -a p*[^0-9] /tmp/mytest1 [xingmu@localhost etc]$ ll /tmp/mytest1 [xingmu@localhost etc]$ ls /tmp/mytest1 pam.d passwd passwd- pki plymouth pm popt.d postfix ppp prelink.conf.d printcap profile profile.d protocols python -
将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
[xingmu@localhost bbb]$ cat /etc/issue | tr [a-z] [A-Z] > /tmp/issue.out [xingmu@localhost bbb]$ cat /etc/issue \S Kernel \r on an \m [xingmu@localhost bbb]$ cat /tmp/issue.out \S KERNEL \R ON AN \M -
将当前系统登录用户的信息转换为大写后保存至/tmp/who.out文件中
[xingmu@localhost tmp]$ who am i xingmu pts/1 2022-04-23 17:59 (192.168.44.1) [xingmu@localhost tmp]$ who am i | tr [a-z] [A-Z] > /tmp/who.out [xingmu@localhost tmp]$ cat /tmp/who.out XINGMU PTS/1 2022-04-23 17:59 (192.168.44.1) -
一个linux用户给root发邮件,要求邮件标题为”help”,邮件正文如下:Hello, I am 用户名,The system version is here,please help me to check it ,thanks! 操作系统版本信息
# 发送邮件 [xingmu@shanghai ~]$ echo Hello, I am $(whoami),The system version is here,please help me to check it ,thanks! $(lsb_release -a) | mail -s help root # root 接收邮件 [root@shanghai ~]# mail Heirloom Mail version 12.5 7/5/10. Type ? for help. "/var/spool/mail/root": 7 messages 7 new >N 1 xingmu Sat Apr 23 18:42 18/975 "help" & 1 Message 1: From xingmu@shanghai.centos79.node44.128.study.local Sat Apr 23 18:44:45 2022 Return-Path: <xingmu@shanghai.centos79.node44.128.study.local> X-Original-To: root Delivered-To: root@shanghai.centos79.node44.128.study.local Date: Sat, 23 Apr 2022 18:44:45 +0800 To: root@shanghai.centos79.node44.128.study.local Subject: help User-Agent: Heirloom mailx 12.5 7/5/10 Content-Type: text/plain; charset=us-ascii From: xingmu@shanghai.centos79.node44.128.study.local (xingmu) Status: R Hello, I am xingmu,The system version is here,please help me to check it ,thanks! LSB Version: :core-4.1-amd64:core-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 7.9.2009 (Core) Release: 7.9.2009 Codename: Core -
将/root/下文件列表,显示成一行,并文件名之间用空格隔开
[root@shanghai ~]# ll total 24 -rw-------. 1 root root 1865 Mar 13 19:58 anaconda-ks.cfg -rw-r--r--. 1 root root 17 Apr 23 01:15 color.txt -rw-r--r--. 1 root root 1913 Mar 13 20:38 initial-setup-ks.cfg drwxr-xr-x. 141 root root 8192 Apr 23 16:49 tt [root@shanghai ~]# ls /root | tr "\n" " " anaconda-ks.cfg color.txt initial-setup-ks.cfg tt -
计算1+2+3+...+99+100的总和
[root@shanghai ~]# echo {1..100}| tr ' ' + | bc 5050 -
删除Windows文本文件中的回车字符 ,即“\r”
[root@shanghai ~]# hexdump -C win.txt 00000000 61 0d 0a 62 0d 0a 63 |a..b..c| 00000007 [root@shanghai ~]# tr -d "\r" < win.txt > win2.txt [root@shanghai ~]# hexdump -C win2.txt 00000000 61 0a 62 0a 63 |a.b.c| 00000005 [root@shanghai ~]# file win2.txt win2.txt: ASCII text -
处理字符串“xt.,l 1 jr#!$mn 2 c*/fe 3 uz 4”,只保留其中的数字和空格
# -c 使用匹配项的补集来处理 [root@shanghai ~]# echo 'xt.,l 1 jr#4"mn 2 c*/fe 3 uz 4' | tr -d -c '[:digit:][:space:]' 1 4 2 3 4 -
将PATH变量每个目录显示在独立的一行
[root@shanghai ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin [root@shanghai ~]# echo $PATH | tr -s ":" "\n" /usr/local/sbin /usr/local/bin /sbin /bin /usr/sbin /usr/bin /root/bin -
将指定文件中0-9分别替代成a-j
# 随机生成指定文件 [root@shanghai ~]# echo {0..4}{q..t}{1..9} > test.txt [root@shanghai ~]# cat test.txt 0q1 0q2 0q3 0q4 0q5 0q6 0q7 0q8 0q9 0r1 0r2 0r3 0r4 0r5 0r6 0r7 0r8 0r9 0s1 0s2 0s3 0s4 0s5 0s6 0s7 0s8 0s9 0t1 0t2 0t3 0t4 0t5 0t6 0t7 0t8 0t9 1q1 1q2 1q3 1q4 1q5 1q6 1q7 1q8 1q9 1r1 1r2 1r3 1r4 1r5 1r6 1r7 1r8 1r9 1s1 1s2 1s3 1s4 1s5 1s6 1s7 1s8 1s9 1t1 1t2 1t3 1t4 1t5 1t6 1t7 1t8 1t9 2q1 2q2 2q3 2q4 2q5 2q6 2q7 2q8 2q9 2r1 2r2 2r3 2r4 2r5 2r6 2r7 2r8 2r9 2s1 2s2 2s3 2s4 2s5 2s6 2s7 2s8 2s9 2t1 2t2 2t3 2t4 2t5 2t6 2t7 2t8 2t9 3q1 3q2 3q3 3q4 3q5 3q6 3q7 3q8 3q9 3r1 3r2 3r3 3r4 3r5 3r6 3r7 3r8 3r9 3s1 3s2 3s3 3s4 3s5 3s6 3s7 3s8 3s9 3t1 3t2 3t3 3t4 3t5 3t6 3t7 3t8 3t9 4q1 4q2 4q3 4q4 4q5 4q6 4q7 4q8 4q9 4r1 4r2 4r3 4r4 4r5 4r6 4r7 4r8 4r9 4s1 4s2 4s3 4s4 4s5 4s6 4s7 4s8 4s9 4t1 4t2 4t3 4t4 4t5 4t6 4t7 4t8 4t9 # 按照要求进行替换 [root@shanghai ~]# tr [0-9] [a-j] test.txt tr: extra operand ‘test.txt’ Try 'tr --help' for more information. [root@shanghai ~]# tr [0-9] [a-j] <test.txt aqb aqc aqd aqe aqf aqg aqh aqi aqj arb arc ard are arf arg arh ari arj asb asc asd ase asf asg ash asi asj atb atc atd ate atf atg ath ati atj bqb bqc bqd bqe bqf bqg bqh bqi bqj brb brc brd bre brf brg brh bri brj bsb bsc bsd bse bsf bsg bsh bsi bsj btb btc btd bte btf btg bth bti btj cqb cqc cqd cqe cqf cqg cqh cqi cqj crb crc crd cre crf crg crh cri crj csb csc csd cse csf csg csh csi csj ctb ctc ctd cte ctf ctg cth cti ctj dqb dqc dqd dqe dqf dqg dqh dqi dqj drb drc drd dre drf drg drh dri drj dsb dsc dsd dse dsf dsg dsh dsi dsj dtb dtc dtd dte dtf dtg dth dti dtj eqb eqc eqd eqe eqf eqg eqh eqi eqj erb erc erd ere erf erg erh eri erj esb esc esd ese esf esg esh esi esj etb etc etd ete etf etg eth eti etj -
将文件/etc/centos-release中每个单词(由字母组成)显示在独立一行,并无空行
[root@shanghai ~]# cat /etc/centos-release | tr -s [:space:] "\n" CentOS Linux release 7.9.2009 (Core)