linux learning first week

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

1, according to the release series displays linux, and describes the differences between the various links in this issue

Linux distributions:
Slackware: SUSE, Linux Enterprise Server (SLES) OpenSuse Desktop
Debian: Ubuntu, deepin (depth), Mint
Redhat: RedHat Enterprise Linux, CentOS, Fedora
Archlinux: Lightweight simple, follow KLSS principle, (keep IT simple and Stupid)
Gentoo: extreme performance, does not provide a traditional installer, download the source code to compile and install the software on the machine
LFS: linux From sxrath homemade Linux
Android: Kernel busybox + (tool set) + Java virtual machine
linux learning first week

不同发行版本之间的联系:完整的Linux系统都是由Linux内核加上各种应用程序组成

the difference:

Red Hat, is redhat own release of Enterprise Edition, is an important node of redhat.
Fedore is a linux-based operating system, and software is a set of computers to maintain the normal operation of the collection. Sponsored by Red Hat.
suse linux, for individual users.
Red flag linux distributions, including desktop, workstation, Datacenter Server Edition, HA Cluster Edition and the red flag embedded linux and other products,
is China's larger, more mature one linux distribution.
Debian, the three major releases only operate in the form of community, the company is not working on a commercial basis. We are committed to creating a free operating system
Cooperation Organization. And most of the basic tools in the operating system debian developers created from the GNU project.
Ubuntu, it is a desktop application to linux-based operating system. Ubuntu aims to provide an up to date, as well as the general user
operating system is quite stable and the main building by the Free Software made.
Centos, is based on a redhat linux can provide enterprise linux release the source code freely available. Currently Centos has been acquired,
it becomes a redhat's organization.

2, the installation centos7.6 operating system, create a user name his name, and normal landing, the main steps screenshots

[root@localhost ~]# useradd tk
[root@localhost ~]# passwd tk
Changing password for user tk.
New password: 
BAD PASSWORD: The password fails the dictionary check - it is too simplistic/systematic
Retype new password: 
passwd: all authentication tokens updated successfully.
linux learning first week
linux learning first week

3, when the configuration environment variable to achieve the implementation of history can see the time of execution of the command

HISTSIZE found in / etc / profile and add the following HISTTIMEFORMT = "% F% T" 
or HISTTIMEFORMT = "% y-% m-% d% H:% M:% S", note that S preferably have the format behind% such a display format when the space
looking to, the following:
[the root TK @ ~] # Vim / etc / Profile
linux learning first week
[the root TK @ ~] # Source / etc / Profile
[the root TK @ ~] # History
linux learning first week

4, summary linux philosophy

a. Everything is a file (including hardware)
B. small, single-use procedure
c. linker, complex tasks common
d. Reduce confusing user interface
e. Configure data stored in the text

5 summarizes linux common command format, and illustrated by an example, columns such as echo, screen, date, ifconfig, export commands

Screen:

screen用于命令行终端切换
用户可以通过该软件同时连接多个本地或远程的命令行会话,并在其间自由切换。GNU Screen可以看作
是窗口管理器的命令行界面版本。它提供了统一的管理多个会话的界面和相应的功能。
会话恢复:只要Screen本身没有终止,在其内部运行的会话都可以恢复。这一点对于远程登录的用户特别
有用——即使网络连接中断,用户也不会失去对已经打开的命令 行会话的控制。只要再次登录到主机上
执行screen  -r就可以恢复会话的运行。同样在暂时离开的时候,也可以执行分离命令detach,在保证里
面的程序正常运行的情况下让Screen挂起(切换到后 台)

语法:
screen [-AmRvx -ls -wipe][-d <作业名称>][-h <行数>][-r <作业名称>][-s ][-S <作业名称>]
选项:

-A  将所有的视窗都调整为目前终端机的大小。
-d <作业名称>  将指定的screen作业离线。
-h <行数>  指定视窗的缓冲区行数。
-m  即使目前已在作业中的screen作业,仍强制建立新的screen作业。
-r <作业名称>  恢复离线的screen作业。
-R  先试图恢复离线的作业。若找不到离线的作业,即建立新的screen作业。
-s  指定建立新视窗时,所要执行的shell。
-S <作业名称>  指定screen作业的名称。
-v  显示版本信息。
-x  恢复之前离线的screen作业。
-ls或--list  显示目前所有的screen作业。
-wipe  检查目前所有的screen作业,并删除已经无法使用的screen作业。

常用screen参数:

screen -S yourname -> 新建一个叫yourname的session
screen -ls -> 列出当前所有的session
screen -r yourname -> 回到yourname这个session
screen -d yourname -> 远程detach某个session
screen -d -r yourname -> 结束当前session并回到yourname这个session
在每个screen session 下,所有命令都以 ctrl+a(C-a) 开始。
C-a ? -> 显示所有键绑定信息
C-a c -> 创建一个新的运行shell的窗口并切换到该窗口
C-a n -> Next,切换到下一个 window
C-a p -> Previous,切换到前一个 window
C-a 0..9 -> 切换到第 0..9 个 window
Ctrl+a [Space] -> 由视窗0循序切换到视窗9
C-a C-a -> 在两个最近使用的 window 间切换
C-a x -> 锁住当前的 window,需用用户密码解锁
C-a d -> detach,暂时离开当前session,将目前的 screen session (可能含有多个 windows)
丢到后台执行,并会回到还没进 screen 时的状态,此时在 screen session 里,每个 window 内运行的 process
(无论是前台/后台)都在继续执行,即使 logout 也不影响。
C-a z -> 把当前session放到后台执行,用 shell 的 fg 命令则可回去。
C-a w -> 显示所有窗口列表
C-a t -> time,显示当前时间,和系统的 load
C-a k -> kill window,强行关闭当前的 window
C-a [ -> 进入 copy mode,在 copy mode 下可以回滚、搜索、复制就像用使用 vi 一样
C-b Backward,PageUp
C-f Forward,PageDown
H(大写) High,将光标移至左上角
L Low,将光标移至左下角
0 移到行首
$ 行末
w forward one word,以字为单位往前移
b backward one word,以字为单位往后移
Space 第一次按为标记区起点,第二次按为终点
Esc 结束 copy mode
C-a ] -> paste,把刚刚在 copy mode 选定的内容贴上
安装screen
流行的Linux发行版(例如Red Hat Enterprise Linux)通常会自带screen实用程序,如果没有的话,可以从
GNU screen的官方网站下载。
[root@localhost ~]# yum -y install screen

实例:

创建 screen 终端
#screen //创建 screen 终端 
创建 screen 终端 并执行任务
#screen vi ~/main.c //创建 screen 终端 ,并执行 vi命令
使用描述性名称启动屏幕会话是一个很好的做法,这样你可以轻松地记住会话中正在运行的进程。要使用
会话名称创建新会话,请运行以下命令:
screen -S name #将 “name” 替换为对你会话有意义的名字。
从 screen 会话中分离
要从当前的 screen 会话中分离,你可以按下Ctrl-A 和 d。所有的 screen 会话仍将是活跃的,你之后可以
随时重新连接。
重新连接到 screen 会话
如果你从一个会话分离,或者由于某些原因你的连接被中断了,你可以使用下面的命令重新连接:
screen -r
如果你有多个 screen 会话,你可以用 ls 参数列出它们。
screen -ls
There are screens on:
7880.session    (Detached)
7934.session2   (Detached)
7907.session1   (Detached)
3 Sockets in /var/run/screen/S-root.
在我们的例子中,我们有三个活跃的 screen 会话。因此,如果你想要还原 “session2” 会话,你可以执行:
screen -r 7934
或者使用 screen 名称。
screen -r -S session2
中止 screen 会话
有几种方法来中止 screen 会话。你可以按下 Ctrl+d ,或者在命令行中使用 exit 命令。
要查看screen命令所有有用的功能,你可以查看 screen 的 man 手册。man screen

echo:

字符串输出
命令格式:
echo string

实例:

普通字符串输出

[root@localhost ~]# echo IM taokui
IM taokui
[root@localhost ~]# echo "IM taokui"
IM taokui
[root@localhost ~]# echo 'IM taokui'
IM taokui

显示转义字符

[root@localhost ~]# echo \"IM taokui\"
"IM taokui"
[root@localhost ~]# echo ""\"IM taokui\"
"IM taokui"

显示变量

read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量
[root@localhost ~]# vim test.sh
#!/bin/sh
read name
echo "$name IM taokui"
[root@localhost ~]# sh test.sh 
wo
wo IM taokui

显示换行

[root@localhost ~]# echo -e "tk \n" #-e开启转义,\n表示换行,以下是换行和不换行的效果
tk 
[root@localhost ~]# echo IM tk
IM tk

显示不换行

[root@localhost ~]# vim test.sh
#!/bin/sh
echo -e “tk \c” #-e开启转义 \c不换行
echo "IM taokui"
[root@localhost ~]# sh test.sh 
tk IM taokui

显示结果指定向文件

[root@localhost ~]# echo IM taokui >a.txt
[root@localhost ~]# cat a.txt 
IM taokui

原样输出字符串,不进行转义或取变量(用单引号)

[root@localhost ~]# echo '$name\'
$name\
[root@localhost ~]# echo "$name\" #如果用双引号会是不能原样输出的

显示命令执行结果

[root@localhost ~]# echo date #这里用的是反引号(`)而不是单引号(’),如果用单引号或者双引号
都只会原样输出
Sun Dec 1 19:16:05 CST 2019

export:

命令用于设置或显示环境变量,可新增,修改或删除环境变量,供后续执行的程序使用,xeport的效力仅限于该次登录操作

语法:

export [-fnp][变量名]=[变量设置值]
-f 代表[变量名称]中为函数名称
-n 删除指定的变量,变量时间上并未删除,只是不会输出到后续指令的执行环境中
-p 列出所有的shell赋予程序的环境变量

列出当前所有的环境变量

[root@localhost ~]# export -p #列出当前所有环境变量 ,由于篇幅原因这里我只复制前半部分
declare -x HISTCONTROL="ignoredups"
declare -x HISTSIZE="1000"
declare -x HOME="/root"
declare -x HOSTNAME="localhost"
declare -x LANG="en_US.UTF-8"
declare -x LESSOPEN="||/usr/bin/lesspipe.sh %s"
declare -x LOGNAME="root"

定义环境变量赋值

[root@localhost ~]# export tk=love
[root@localhost ~]# export -p #会看到刚刚定义的变量
declare -x USER="root"
declare -x XDG_RUNTIME_DIR="/run/user/0"
declare -x XDG_SESSION_ID="4"
declare -x tk="love"

定义环境变量

[root@localhost ~]# export TK #定义变量的时候需要大写
[root@localhost ~]# export -p
declare -x SSH_TTY="/dev/pts/0"
declare -x TERM="xterm"
declare -x TK

date:

用来显示或者设定系统的时间和日期
若是不以加号作为开头,则表示要设定时间,而时间格式为 MMDDhhmm[[CC]YY][.ss],其中 MM 为月份,DD 为日,hh 为小时,mm 为分钟,CC 为年份前两位数字,YY 为年份后两位数字,ss 为秒数。

语法:

date [-u] [-d datestr] [-s datestr] [--utc] [--universal] [--date=datestr] [--set=datestr] [--help] [--version] [+FORMAT] [MMDDhhmm[[CC]YY][.ss]]

参数说明:

-d datestr : 显示 datestr 中所设定的时间 (非系统时间)
--help : 显示辅助讯息
-s datestr : 将系统时间设为 datestr 中所设定的时间
-u : 显示目前的格林威治时间
--version : 显示版本编号

date命令的用法 :

date +%Y-%m-%d, date +%y-%m-%d 年月日 
date +%H:%M:%S = date +%T 时间 
date +%s 时间戳 
date -d @1504620492 时间戳换算
date -d “+1day” 一天后 
date -d “-1 day” 一天前 
date -d “-1 month” 一月前 
date -d “-1 min” 一分钟前 
date +%w, date +%W 星期

查看当前时间

[root@tk ~]# date
2019年 12月 04日 星期三 02:18:19 CST

查看系统日期

[root@tk ~]# cal
十二月 2019 
日 一 二 三 四 五 六
1 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

查看当前年份(四位显示)

[root@dl-001 shell]# date +%Y 
2019

查看当前年份(简化显示)

[root@tkl~]# date +%y 
19

查看当前 年 月 日 时 分 秒 星期

[root@tk ~]# date "+%Y-%m-%d %H:%M:%S %w" 
2019-12-04 02:24:44 3

查看当前时间是一年的第几周

[root@tk ~]# date +%W 
48

查看时间戳(显示从1970年1月1日00:00:00到目前经历的秒数)

[root@tk ~]# date +%s
1575397686

时间戳的换算

[root@tk ~]# date -d @1575397686
2019年 12月 04日 星期三 02:28:06 CST

打印指定日期和时间

[root@tk ~]# date -d "-2 day" +%d
02
[root@tk ~]# date -d "-1 year -3 month -1 day" +%Y-%m-%d
2018-09-03

手动设置当前时间

[root@tk ~]# date -s "2019-12-4 02:37:40"
2019年 12月 04日 星期三 02:37:40 CST
[root@tk ~]# date
2019年 12月 04日 星期三 02:37:44 CST

同步网络时间

[root@tk~]# yum install -y ntp
[root@tk ~]# ntpdate ntp.ubuntu.com
4 Dec 02:38:48 ntpdate[19778]: the NTP socket is in use, exiting
[root@tk ~]# date
2019年 12月 04日 星期三 02:38:53 CST

Ifconfig:

用于显示或者设置网络

语法:

ifconfig [网络设备][down up -allmulti -arp -promisc][add<地址>][del<地址>][<hw<网络设备类型><硬件地址>][io_addr<I/O地址>][irq<IRQ地址>][media<网络媒介类型>][mem_start<内存地址>][metric<数目>][mtu<字节>][netmask<子网掩码>][tunnel<地址>][-broadcast<地址>][-pointopoint<地址>][IP地址]

参数说明:

add<地址> 设置网络设备IPv6的IP地址。
del<地址> 删除网络设备IPv6的IP地址。
down 关闭指定的网络设备。
<hw<网络设备类型><硬件地址> 设置网络设备的类型与硬件地址。
io_addr<I/O地址> 设置网络设备的I/O地址。
irq<IRQ地址> 设置网络设备的IRQ。
media<网络媒介类型> 设置网络设备的媒介类型。
mem_start<内存地址> 设置网络设备在主内存所占用的起始地址。
metric<数目> 指定在计算数据包的转送次数时,所要加上的数目。
mtu<字节> 设置网络设备的MTU。
netmask<子网掩码> 设置网络设备的子网掩码。
tunnel<地址> 建立IPv4与IPv6之间的隧道通信地址。
up 启动指定的网络设备。
-broadcast<地址> 将要送往指定地址的数据包当成广播数据包来处理。
-pointopoint<地址> 与指定地址的网络设备建立直接连线,此模式具有保密功能。
-promisc 关闭或启动指定网络设备的promiscuous模式。
[IP地址] 指定网络设备的IP地址。
[网络设备] 指定网络设备的名称。

实例:

启动关闭指定网卡

#ifconfig eth0 down# ifconfig eth0 up

为网卡配置和删除IPv6地址

ifconfig eth0 add 33ffe: 3240: 800 : 1005 :: 2/64 // IPv6 address of the network card eh
#ifconfig eth0 del 33ffe: 3240: 800 : 1005 :: 2/64 // remove the IPv6 address for the network card

 modify the MAC address with ifconfig

#ifconfig eth0 down // Close the card # ifconfig eth0 hw ether 00: AA: BB: CC: DD: EE // modify the MAC address # ifconfig eth0 up // start card # ifconfig eth1 hw ether 00: 1D: 1C: 1D: 1E // close the card and change the MAC address # ifconfig eth1 up // start card

 configure the IP address

#ifconfig eth0 192.168.1.56 // assign an IP address to the network card eth0 # ifconfig eth0 192.168.1.56 netmask 255.255.255.0 // eth0 network card to configure the IP address, subnet mask and add # ifconfig eth0 192.168.1.56 netmask 255.255.255.0 broadcast 192.168.1.255// eth0 network card to configure the IP address, subnet mask plus, plus a broadcast address

 enable and disable the ARP protocol

ifconfig eth0 arp // open # ifconfig eth0 -arp // Close

The maximum transmission unit setting 

#ifconfig eth0 mtu 1500 // set by the maximum packet size of 1500 bytes

Guess you like

Origin www.cnblogs.com/aiaitie/p/11980788.html