1.linux基础入门


2022-03-05

1、按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别。
2、安装Centos7.9和ubuntu操作系统,创建一个自己名字的用户名,并可以正常登录,将主要步骤截图。
3、配置环境变量,实现执行history的时候可以看到执行命令的时间。
4、总结Linux哲学思想。
5、总结Linux常用命令使用格式,并用实例说明。例如echo、screen、date、ifconfig、export等命令
6、描述Linux发行版的系统目录名称命名规则以及用途。

1.按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别

1)slackware:SUSE Linux Enterprise Server (SLES) , OpenSuse桌面
2)debian: ubuntu,deepin(深度),mint
3)redhat: RHEL: RedHat Enterprise Linux, 每18个月发行一个新版本
 CentOS: Community Enterprise Operating System 兼容RHEL的格式
 中标麒麟:中标软件
 Fedora:每6个月发行一个新版本
4)Alpine: 一个面向安全的轻型 Linux 发行版。它不同于通常 Linux 发行版,Alpine 采用了 musl 
libc 和 busybox 以减小系统的体积和运行时资源消耗,但功能上比 busybox 又完善的多,只有
5M左右大小
5)ArchLinux:轻量简洁,遵循K.I.S.S.原则( keep it simple and stupid ),Manjaro
6)Gentoo:极致性能,不提供传统意义的安装程序,下载源代码在本机上编译安装软件
7)LFS:Linux From scratch 自制Linux,只是一个说明书
8)Android:kernel+busybox(工具集)+java虚拟机

Linux 分支参考网站:http://futurist.se/gldt/
Linux发行版排名: https://distrowatch.com/dwres.php?resource=popularity Linux
发行版体验: https://distrotest.net/

2.安装Centos和ubuntu操作系统

具体步骤就不写了,网上搜索一堆,对应初学者,可以安装centos6,centos7,ubantu操作系统等等,建议学习centos7和ubantu系统为主,因为生产用得多。

这里完成安装centos7和ubantu系统的截图如下

centos7截图如下:

 ubantu截图如下:

 3.配置环境变量,实现执行history的时候可以看到执行命令的时间

echo 'export HISTTIMEFORMAT="%F %T "' >> /root/.bash_profile
source /root/.bash_profile
history

效果如下:

 4.总结Linux哲学思想

1)一切都是一个文件(包括硬件)
2)小型,单一用途的程序
3)链接程序,共同完成复杂的任务
4)避免令人困惑的用户界面
5)配置数据存储在文本中

5.总结Linux常用命令使用格式,并用实例说明。例如echo、screen、date、ifconfig、export等命令

1)echo最简单用法

[root@centos7-v1 ~]#help echo 
echo: echo [-neE] [arg ...]
    Write arguments to the standard output.
    
    Display the ARGs on the standard output followed by a newline.
    
    Options:
      -n    do not append a newline
      -e    enable interpretation of the following backslash escapes
      -E    explicitly suppress interpretation of backslash escapes

#echo有好多用法,不要死记硬背,记住常见用法即可

[root@centos7-v1 ~]#echo $PATH
/apps/httpd/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin

2)screen

[root@centos7-v1 ~]#yum -y install screen

screen命令常见用法:
创建新screen会话
 
screen –S [SESSION]
加入screen会话
screen –x [SESSION]
退出并关闭screen会话
exit
剥离当前screen会话
Ctrl+a,d
显示所有已经打开的screen会话
screen -ls
恢复某screen会话
screen -r [SESSION]

3)date

[root@centos7-v1 ~]#date --help
Usage: date [OPTION]... [+FORMAT]
  or:  date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Display the current time in the given FORMAT, or set the system date.

[root@centos7-v1 abc]#touch `hostname`-`date +%F`.log
[root@centos7-v1 abc]#ll
total 0
-rw-r--r-- 1 root root 0 Mar  4 22:12 centos7-v1-2022-03-04.log
[root@centos7-v1 abc]#date +%F
2022-03-04
[root@centos7-v1 abc]#hostname
centos7-v1
[root@centos7-v1 abc]#

#date用法好多,具体用上面方法查看帮助
FORMAT controls the output.  Interpreted sequences are:

  %%   a literal %
  %a   locale's abbreviated weekday name (e.g., Sun)
  %A   locale's full weekday name (e.g., Sunday)
  %b   locale's abbreviated month name (e.g., Jan)
  %B   locale's full month name (e.g., January)
  %c   locale's date and time (e.g., Thu Mar  3 23:05:25 2005)
  %C   century; like %Y, except omit last two digits (e.g., 20)
  %d   day of month (e.g., 01)
  %D   date; same as %m/%d/%y
  %e   day of month, space padded; same as %_d
  %F   full date; same as %Y-%m-%d
  %g   last two digits of year of ISO week number (see %G)
  %G   year of ISO week number (see %V); normally useful only with %V
  %h   same as %b
  %H   hour (00..23)
  %I   hour (01..12)
  %j   day of year (001..366)
  %k   hour, space padded ( 0..23); same as %_H
  %l   hour, space padded ( 1..12); same as %_I
  %m   month (01..12)
  %M   minute (00..59)
  %n   a newline
  %N   nanoseconds (000000000..999999999)
  %p   locale's equivalent of either AM or PM; blank if not known
  %P   like %p, but lower case
  %r   locale's 12-hour clock time (e.g., 11:11:04 PM)
  %R   24-hour hour and minute; same as %H:%M
  %s   seconds since 1970-01-01 00:00:00 UTC
  %S   second (00..60)
  %t   a tab
  %T   time; same as %H:%M:%S
  %u   day of week (1..7); 1 is Monday
  %U   week number of year, with Sunday as first day of week (00..53)
  %V   ISO week number, with Monday as first day of week (01..53)
  %w   day of week (0..6); 0 is Sunday
  %W   week number of year, with Monday as first day of week (00..53)
  %x   locale's date representation (e.g., 12/31/99)
  %X   locale's time representation (e.g., 23:13:48)
  %y   last two digits of year (00..99)
  %Y   year
  %z   +hhmm numeric time zone (e.g., -0400)
  %:z  +hh:mm numeric time zone (e.g., -04:00)
  %::z  +hh:mm:ss numeric time zone (e.g., -04:00:00)
  %:::z  numeric time zone with : to necessary precision (e.g., -04, +05:30)
  %Z   alphabetic time zone abbreviation (e.g., EDT)

4)ifconfig

[root@centos7-v1 abc]#ifconfig 
eth0: flags=4163  mtu 1500
        inet 192.168.188.101  netmask 255.255.255.0  broadcast 192.168.188.255
        inet6 fe80::2c50:318f:2e29:a48  prefixlen 64  scopeid 0x20
        ether 00:0c:29:57:8e:4a  txqueuelen 1000  (Ethernet)
        RX packets 15338  bytes 16557222 (15.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6379  bytes 743528 (726.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163  mtu 1500
        inet 192.168.188.150  netmask 255.255.255.0  broadcast 192.168.188.255
        inet6 fe80::e9ef:a358:6b52:97ef  prefixlen 64  scopeid 0x20
        ether 00:0c:29:57:8e:54  txqueuelen 1000  (Ethernet)
        RX packets 49  bytes 6023 (5.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 32  bytes 5550 (5.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 2  bytes 140 (140.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2  bytes 140 (140.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:ae:26:d2  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@centos7-v1 abc]#ifconfig  eth1
eth1: flags=4163  mtu 1500
        inet 192.168.188.150  netmask 255.255.255.0  broadcast 192.168.188.255
        inet6 fe80::e9ef:a358:6b52:97ef  prefixlen 64  scopeid 0x20
        ether 00:0c:29:57:8e:54  txqueuelen 1000  (Ethernet)
        RX packets 49  bytes 6023 (5.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 32  bytes 5550 (5.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

5)export

可以设置变量,也可以持久保存变量

#临时变量
[root@centos7-v1 abc]#export ip=192.168.188.10
[root@centos7-v1 abc]#echo $ip
192.168.188.10

#永久保存变量写在环境变量中,类似下面这个
[root@centos7-v1 abc]#cat /root/.bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
export HISTTIMEFORMAT="%F %T "

6.描述Linux发行版的系统目录名称命名规则以及用途

centos7有如下系统目录结构及其用途

[root@centos7-v1 ]#ls /
apps  boot  db1  etc   lib    log    misc  mysql  opt   root  sbin  sys  usr
bin   data  dev  home  lib64  media  mnt   net    proc  run   srv   tmp  var

/boot:引导文件存放目录,内核文件(vmlinuz)、引导加载器(bootloader, grub)都存放于此目录
/bin:所有用户使用的基本命令;不能关联至独立分区,OS启动即会用到的程序
/sbin:管理类的基本命令;不能关联至独立分区,OS启动即会用到的程序
/lib:启动时程序依赖的基本共享库文件以及内核模块文件(/lib/modules)
/lib64:专用于x86_64系统上的辅助共享库文件存放位置
/etc:配置文件目录
/home/USERNAME:普通用户家目录
/root:管理员的家目录
/media:便携式移动设备挂载点
/mnt:临时文件系统挂载点
/dev:设备文件及特殊文件存储位置
 b: block device,随机访问
 c: character device,线性访问
/opt:第三方应用程序的安装位置
/srv:系统上运行的服务用到的数据
/tmp:临时文件存储位置
/usr: universal shared, read-only data
 bin: 保证系统拥有完整功能而提供的应用程序
 sbin:
 lib:32位使用
 lib64:只存在64位系统
 include: C程序的头文件(header files)
 share:结构化独立的数据,例如doc, man等
       local:第三方应用程序的安装位置
   bin, sbin, lib, lib64, etc, share
/var: variable data files
 cache: 应用程序缓存数据目录
 lib: 应用程序状态信息数据
 local:专用于为/usr/local下的应用程序存储可变数据
 lock: 锁文件
 log: 日志目录及文件
 opt: 专用于为/opt下的应用程序存储可变数据
 run: 运行中的进程相关数据,通常用于存储进程pid文件
 spool: 应用程序数据池
 tmp: 保存系统两次重启之间产生的临时数据
/proc: 用于输出内核与进程信息相关的虚拟文件系统
/sys:用于输出当前系统上硬件设备相关信息虚拟文件系统
/selinux: security enhanced Linux,selinux相关的安全策略等信息的存储位置