一、按系列羅列 Linux 的發行版,並描述不一樣發行版之間的聯繫與區別。shell
slackware:SUSE Linux Enterprise Server,OpenSuse
debian:ubuntu,deepin,mint
redhat:RHEL,CentOS,Fedora
本次學習用到的:
CentOS is a Linux distribution that provides a free, community-supported computing platform functionally compatible with its upstream source, Red Hat Enterprise Linux.
Ubuntu is a Linux distribution based on Debian mostly composed of free and open-source software. Ubuntu is officially released in three editions: Desktop, Server, and Core for Internet of things devices and robots.
學習使用版本:
CentOS-8.1.1911-x86_64-dvd1.iso
CentOS-7-x86_64-Everything-1908.iso
CentOS-6.10-x86_64-bin-DVD1.iso
ubuntu-18.04.5-server-amd64.isoubuntu
二、安裝 Centos七、6 操做系統,建立一個本身名字的用戶名,並能夠正常登陸,將主要步驟截圖。windows
[root@centos7 ~]# useradd zhl
[root@centos7 ~]# cat /etc/passwd | grep zhl
zhl:x:1001:1001::/home/zhl:/bin/bash
[root@centos7 ~]# passwd zhl
Changing password for user zhl.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@centos7 ~]# su - zhl
Last login: Sun Oct 4 16:03:41 CST 2020 on pts/0
[zhl@centos7 ~]$ id
uid=1001(zhl) gid=1001(zhl) groups=1001(zhl) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023centos
[root@centos6 ~]# useradd zhl
[root@centos6 ~]# cat /etc/passwd | grep zhl
zhl:x:501:501::/home/zhl:/bin/bash
[root@centos6 ~]# su zhl
[zhl@centos6 root]$ id
uid=501(zhl) gid=501(zhl) groups=501(zhl) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023緩存
三、配置環境變量,實現執行 history 的時候能夠看到執行命令的時間。bash
[root@centos7 ~]# HISTTIMEFORMAT="%F %T "
[root@centos7 ~]# history
28 2020-10-04 16:16:16 HISTTIMEFORMAT="%F %T "
29 2020-10-04 16:16:21 historysession
四、總結 Linux 哲學思想。app
一切都是一個文件(包括硬件)
小型,單一用途的程序
連接程序,共同完成複雜的任務
避免使人困惑的用戶界面
配置數據存儲在文本中less
五、總結 Linux 經常使用命令使用格式,並用實例說明。例如 echo、screen、date、ifconfig、export 等命令tcp
echo
[root@centos8 ~]# help echo
echo: echo [-neE] [arg ...]
Write arguments to the standard output.
Display the ARGs, separated by a single space character and followed by a newline, on the standard output. Options: -n do not append a newline -e enable interpretation of the following backslash escapes -E explicitly suppress interpretation of backslash escapes
[root@centos8 ~]# echo -e 'a\x0Ab'
a
b
screen
[root@centos7 ~]# screen --help
Use: screen [-opts] [cmd [args]]
or: screen -r [host.tty]
Options:
-4 Resolve hostnames only to IPv4 addresses.
-6 Resolve hostnames only to IPv6 addresses.
-a Force all capabilities into each window's termcap.
-A -[r|R] Adapt all windows to the new display width & height.
-c file Read configuration file instead of '.screenrc'.
-d (-r) Detach the elsewhere running screen (and reattach here).
-dmS name Start as daemon: Screen session in detached mode.
-D (-r) Detach and logout remote (and reattach here).
-D -RR Do whatever is needed to get a screen session.
-e xy Change command characters.
-f Flow control on, -fn = off, -fa = auto.
-h lines Set the size of the scrollback history buffer.
-i Interrupt output sooner when flow control is on.
-l Login mode on (update /var/run/utmp), -ln = off.
-ls [match] or
-list Do nothing, just list our SockDir [on possible matches].
-L Turn on output logging.
-m ignore $STY variable, do create a new screen session.
-O Choose optimal output rather than exact vt100 emulation.
-p window Preselect the named window if it exists.
-q Quiet startup. Exits with non-zero return code if unsuccessful.
-Q Commands will send the response to the stdout of the querying process.
-r [session] Reattach to a detached screen process.
-R Reattach if possible, otherwise start a new session.
-s shell Shell to execute rather than $SHELL.
-S sockname Name this session <pid>.sockname instead of <pid>.<tty>.<host>.
-t title Set title. (window's name).
-T term Use term as $TERM for windows, rather than "screen".
-U Tell screen to use UTF-8 encoding.
-v Print "Screen version 4.01.00devel (GNU) 2-May-06".
-wipe [match] Do nothing, just clean up SockDir [on possible matches].
-x Attach to a not detached screen. (Multi display mode).
-X Execute <cmd> as a screen command in the specified session.
[root@centos7 ~]# screen -ls
There is a screen on:
71922.pts-0.centos7 (Attached)
1 Socket in /var/run/screen/S-root.
date
[root@centos8 ~]# 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.
Mandatory arguments to long options are mandatory for short options too.
-d, --date=STRING display time described by STRING, not 'now'
--debug annotate the parsed date,
and warn about questionable usage to stderr
-f, --file=DATEFILE like --date; once for each line of DATEFILE
-I[FMT], --iso-8601[=FMT] output date/time in ISO 8601 format.
FMT='date' for date only (the default),
'hours', 'minutes', 'seconds', or 'ns'
for date and time to the indicated precision.
Example: 2006-08-14T02:34:56-06:00
-R, --rfc-email output date and time in RFC 5322 format.
Example: Mon, 14 Aug 2006 02:34:56 -0600
--rfc-3339=FMT output date/time in RFC 3339 format.
FMT='date', 'seconds', or 'ns'
for date and time to the indicated precision.
Example: 2006-08-14 02:34:56-06:00
-r, --reference=FILE display the last modification time of FILE
-s, --set=STRING set time described by STRING
-u, --utc, --universal print or set Coordinated Universal Time (UTC)
--help display this help and exit
--version output version information and exit
[root@centos8 ~]# date -d @date +%s
Sun Oct 4 21:10:46 CST 2020
ifconfig
[root@centos8 ~]# ifconfig --help
Usage:
ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
[add <address>[/<prefixlen>]]
[del <address>[/<prefixlen>]]
[[-]broadcast [<address>]] [[-]pointopoint [<address>]]
[netmask <address>] [dstaddr <address>] [tunnel <address>]
[outfill <NN>] [keepalive <NN>]
[hw <HW> <address>] [mtu <NN>]
[[-]trailers] [[-]arp] [[-]allmulti]
[multicast] [[-]promisc]
[mem_start <NN>] [io_addr <NN>] [irq <NN>] [media <type>]
[txqueuelen <NN>]
[[-]dynamic]
[up|down] ...
[root@centos8 ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.201 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::b42f:c7f4:8d16:bc0e prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:2e:10:39 txqueuelen 1000 (Ethernet)
RX packets 26252 bytes 10782373 (10.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9679 bytes 1273609 (1.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
export
[root@centos8 ~]# help export
export: export [-fn] [name[=value] ...] or export -p
Set export attribute for shell variables.
Marks each NAME for automatic export to the environment of subsequently executed commands. If VALUE is supplied, assign VALUE before exporting. Options: -f refer to shell functions -n remove the export property from each NAME -p display a list of all exported variables and functions An argument of `--' disables further option processing. Exit Status: Returns success unless an invalid option is given or NAME is invalid.
[root@centos8 ~]# export HISTTIMEFORMAT="%F %T "
[root@centos8 ~]# echo $HISTTIMEFORMAT
%F %T
tips:
[root@centos8 ~]# hostname -I
10.0.0.201 192.168.122.1
[root@centos6 ~]# cat /etc/inittab | grep -v "#"
id:3:initdefault:
[root@centos8 ~]# systemctl get-default
multi-user.target
[root@centos8 ~]# systemctl set-default multi-user.target
[root@centos8 ~]# runlevel
N 3
Linux 基礎入門
內容概述
1 Linux 基礎
1.1 用戶類型
1.2 終端 terminal
1.2.1 終端類型
1.2.2 查看當前的終端設備
[root@centos8 ~]# tty
/dev/pts/0
etc至關於Windows註冊表
登陸前的提示
[root@centos8 ~]# cat /etc/issue
登陸後的提示
[root@centos8 ~]# cat /etc/motd
[root@centos8 ~]# ps aux | grep bash
root 858 0.0 0.1 25380 2464 ? S 15:55 0:00 /bin/bash /usr/sbin/ksmtuned
root 1616 0.0 0.2 26560 5084 tty1 Ss+ 15:56 0:00 -bash
root 1936 0.0 0.2 26824 5548 pts/0 Ss 16:05 0:00 -bash
root 4321 0.0 0.0 12108 964 pts/0 R+ 20:09 0:00 grep --color=auto bash
1.3 交互式接口
1.3.1 交互式接口類型
1.3.2 什麼是 shell
shell是命令解釋器,也是一種高級程序設計語言
1.3.3 各類 shell
1.3.4 bash shell
[root@centos8 ~]# echo $SHELL
/bin/bash
顯示當前系統使用的全部shell
[root@centos8 ~]# cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
1.4 設置主機名
[root@centos8 ~]# hostname
centos8.magedu.org
wang@ubuntu1804:~$ cat /etc/hostname
ubuntu1804
root@ubuntu1804:~# hostname ubuntu1804.magedu.org
root@ubuntu1804:~# hostname
ubuntu1804.magedu.org
root@ubuntu1804:~# hostnamectl set-hostname ubuntu1804.magedu.org
root@ubuntu1804:~# cat /etc/hostname
ubuntu1804.magedu.org
注意:主機名不要使用下劃線
1.5 命令提示符
[root@centos8 ~]# echo $PS1
[\u@\h \W]\$
我的設置
[root@centos8 ~]# cat /etc/profile.d/env.sh
1.6 執行命令
1.6.1 執行命令過程
1.6.2 shell 中可執行的兩類命令
特殊外部命令,別名(磁盤上的文件,不屬於bash內部)
[root@centos8 ~]# ls /bin/bash
/bin/bash
[root@centos8 ~]# ll /bin/bash
-rwxr-xr-x. 1 root root 1219248 Nov 9 2019 /bin/bash
[root@centos8 bin]# ls /bin/ls
/bin/ls
[root@centos8 bin]# ll /bin/ls
-rwxr-xr-x. 1 root root 166448 May 12 2019 /bin/ls
[root@centos8 bin]# type hostname
hostname is hashed (/usr/bin/hostname)(第一次執行在磁盤中找,第二次執行時文件路徑已存在hash內存中)
[root@centos8 bin]# type echo
echo is a shell builtin
[root@centos8 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@centos8 ~]# hash
hits command
2 /usr/bin/hostname
4 /usr/bin/ls(執行了四次了)
[root@centos8 ~]# type type
type is a shell builtin
shell不一樣,內部命令不一樣,因此會有同名的內部、外部命令
[root@centos8 ~]# type -a echo
echo is a shell builtin
echo is /usr/bin/echo
1.6.2.1 內部命令相關
enable . 對等 enable source
修改完配置文件後,不用重啓、退出重登,應用下
#. /etc/profile.d/env.sh
#source /etc/profile.d/env.sh
yum install nano
dnf install nano(centos8)
[root@centos8 ~]# help
[root@centos8 ~]# enable
enable能夠禁用內部命令 -n(好比禁用內部echo)
enable輸出中就沒了被禁用命令,help會標記被禁用
此時外部echo還能用
enable -n enable,因爲沒保存文件,exit,再登陸,就正常了
1.6.2.2 執行外部命令
退出後,hash緩存會清除
hash -r清除hash緩存
避免命令被移走,而以前hash存放以前的路徑緩存,執行時報沒有命令
hash -d hostanme清理單條hash緩存
[root@centos8 ~]# type -a echo
echo is a shell builtin
echo is /usr/bin/echo
[root@centos8 ~]# which enable
/usr/bin/which: no enable in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@centos8 ~]# which reboot
/usr/sbin/reboot
[root@centos8 ~]# which echo
/usr/bin/echo
[root@centos8 ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz(多顯示了幫助)
1.6.3 命令別名
每一個用戶都有.bashrc,在這裏加別名
[root@centos8 ~]# cat .bashrc | grep alias
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
[root@centos8 ~]#
修改完
#. .bashrc
#source .bashrc
unalias
[root@centos8 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 4G 0 part [SWAP]
sr0 11:0 1 7G 0 rom(光盤)
添加硬盤
不用重啓,掃盤
[root@centos8 ~]# type ls
ls is aliased to `ls --color=auto'
[root@centos8 ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
[root@centos8 ~]# ls
[root@centos8 ~]# type cdnetwork(判斷是否已有命令名)
-bash: type: cdnetwork: not found
[root@centos8 ~]# alias cdnetwork="cd /etc/sysconfig/network-scripts/"
[root@centos8 ~]# type cdnetwork(此時能夠看出已是別名)
exit,別名消失
非要把別名設置成已有命令
別名優先級高
別名>內部命令>外部命令(hash)>無此命令
hash緩存的外部命令
找外部命令,先hash,後路徑
1.6.4 命令格式
[root@centos8 ~]# free -h
total used free shared buff/cache available
Mem: 1.9Gi 298Mi 1.3Gi 9.0Mi 326Mi 1.5Gi
Swap: 4.0Gi 0B 4.0Gi
[root@centos8 ~]# free --human
total used free shared buff/cache available
Mem: 1.9Gi 298Mi 1.3Gi 9.0Mi 326Mi 1.5Gi
Swap: 4.0Gi 0B 4.0Gi
[root@centos8 ~]# ls -a
. .bash_logout .config Documents initial-setup-ks.cfg .pki Videos
.. .bash_profile .cshrc Downloads .local Public .Xauthority
anaconda-ks.cfg .bashrc .dbus .esd_auth Music .tcshrc
.bash_history .cache Desktop .ICEauthority Pictures Templates
[root@centos8 ~]# ls --all
. .bash_logout .config Documents initial-setup-ks.cfg .pki Videos
.. .bash_profile .cshrc Downloads .local Public .Xauthority
anaconda-ks.cfg .bashrc .dbus .esd_auth Music .tcshrc
.bash_history .cache Desktop .ICEauthority Pictures Templates
[root@centos8 ~]# ps
PID TTY TIME CMD
6567 pts/1 00:00:00 bash
7889 pts/1 00:00:00 ps
[root@centos8 ~]# ps a
PID TTY STAT TIME COMMAND
1616 tty1 Ss+ 0:00 -bash
6567 pts/1 Ss 0:00 -bash
7890 pts/1 R+ 0:00 ps a
[root@centos8 ~]# ps au
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1616 0.0 0.2 26560 5084 tty1 Ss+ 00:45 0:00 -bash
root 6567 0.0 0.2 26692 5464 pts/1 Ss 08:52 0:00 -bash
root 7891 0.0 0.1 57184 3800 pts/1 R+ 11:00 0:00 ps au
[root@centos8 ~]# iptables -vnL
Chain INPUT (policy ACCEPT 5932 packets, 8898K bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT udp -- virbr0 0.0.0.0/0 0.0.0.0/0 udp dpt:53
0 0 ACCEPT tcp -- virbr0 0.0.0.0/0 0.0.0.0/0 tcp dpt:53
0 0 ACCEPT udp -- virbr0 0.0.0.0/0 0.0.0.0/0 udp dpt:67
0 0 ACCEPT tcp -- virbr0 0.0.0.0/0 0.0.0.0/0 tcp dpt:67
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT all -- virbr0 0.0.0.0/0 192.168.122.0/24 ctstate RELATED,ESTABLISHED
0 0 ACCEPT all -- virbr0 192.168.122.0/24 0.0.0.0/0
0 0 ACCEPT all -- virbr0 virbr0 0.0.0.0/0 0.0.0.0/0
0 0 REJECT all -- virbr0 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
0 0 REJECT all -- virbr0 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
Chain OUTPUT (policy ACCEPT 3290 packets, 343K bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT udp -- * virbr0 0.0.0.0/0 0.0.0.0/0 udp dpt:68
[root@centos8 ~]# iptables -Lnv
iptables: No chain/target/match by that name.
^C強行退出
^D正常退出
1.7 常見命令
1.7.1 查看硬件信息
1.7.1.1 查看 CPU
[root@centos8 ~]# lscpu
[root@centos8 ~]# cat /proc/cpuinfo
1.7.1.2 查看內存大小
[root@centos8 ~]# free
total used free shared buff/cache available
Mem: 2012252 306036 1371512 9368 334704 1540244
Swap: 4194300 0 4194300
[root@centos8 ~]# cat /proc/meminfo
proc顯示的是內存中的文件
[root@centos8 ~]# ll /proc/meminfo
-r--r--r--. 1 root root 0 Oct 2 15:54 /proc/meminfo(大小爲0)
1.7.1.3 查看硬盤和分區狀況
[root@centos8 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 4G 0 part [SWAP]
sr0 11:0 1 7G 0 rom
[root@centos8 ~]# cat /proc/partitions
major minor #blocks name
11 0 7377920 sr0
8 0 209715200 sda
8 1 1048576 sda1
8 2 104857600 sda2
8 3 52428800 sda3
8 4 1 sda4
8 5 4194304 sda5
1.7.2 查看系統版本信息
1.7.2.1 查看內核版本
[root@centos8 ~]# uname -r
4.18.0-147.el8.x86_64
1.7.2.2 查看操做系統發行版本
[root@centos8 ~]# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)
[root@centos8 ~]# cat /etc/os-release
1.7.3 日期和時間
[root@centos8 ~]# date(修改時間,也是保存在內存中,重啓時間又恢復)
硬件時間,主板時間
[root@centos8 ~]# clock
2020-10-03 11:54:04.446048+08:00
[root@centos8 ~]# clock -s(以硬件時間矯正系統時間)
[root@centos8 ~]# ll /etc/localtime
lrwxrwxrwx. 1 root root 35 Oct 1 19:46 /etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai
[root@centos8 ~]# timedatectl set-timezone Asia/Shanghai
Ubuntu
# cat /etc/timezone
1.7.4 關機和重啓
root@ubuntu1804:~# reboot
root@ubuntu1804:~# init 6
root@ubuntu1804:~# init 0
1.7.5 用戶登陸信息查看命令
[root@centos8 ~]# w
13:55:51 up 13:11, 2 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 - Fri15 21:59m 0.23s 0.23s -bash
root pts/1 10.0.0.1 08:52 0.00s 0.21s 0.01s w
1.7.6 文本編輯
1.7.7 會話管理
關閉窗口,會話結束,會話內部的進程也會隨之終止,無論有沒有運行完
1.7.7.1 screen
1.7.7.2 tmux
1.7.8 輸出信息 echo
echo 輸出的字符串間以空白字符隔開,並在最後加上換行號
-n 不自動換行
[root@centos8 ~]# echo -e 'a\x0Ab'
a
b
1.8 字符集和編碼
字符集(字是如何寫)
字符與二進制對應關係
ASCII碼
編碼(在磁盤上的保存形式)
字體,表現形式
1.8.1 ASCII 碼
1.8.2 Unicode
[root@centos8 ~]# echo $LANG
en_US.UTF-8
[root@centos8 ~]# cat /tmp/test.txt
abc
[root@centos8 ~]# hexdump -C /tmp/test.txt
00000000 61 62 63 20 0a |abc .|
00000005
[root@centos8 ~]# ll /tmp/test.txt
-rw-r--r--. 1 root root 5 Oct 3 16:01 /tmp/test.txt
[root@centos8 ~]# man ascii
1.9 命令行擴展和被括起來的集合
1.9.1 命令行擴展:`` 和 $ ()
[root@centos8 ~]# touch date +%F
.txt
[root@centos8 ~]# touch $(date +%F).txt
[root@centos8 ~]# ls $(echo $(date +F%).txt)
[root@centos8 ~]# ls echo $(date +F%).txt
[root@centos8 ~]# ls $(echo date +F%
.txt)
單引號:六親不認
反向單引號:變量和命令都識別
雙引號:不能識別命令
1.9.2 括號擴展:{}
[root@centos8 ~]# echo {1,3,5}
1 3 5
[root@centos8 ~]# echo 1 3 5
1 3 5
[root@centos8 ~]# echo user{1,3,5}
user1 user3 user5
[root@centos8 ~]# echo file{1,3,5}.txt
file1.txt file3.txt file5.txt
[root@centos8 ~]# echo {1..10}
1 2 3 4 5 6 7 8 9 10
[root@centos8 ~]# echo {20..10}
20 19 18 17 16 15 14 13 12 11 10
[root@centos8 ~]# echo {20..10..2}
20 18 16 14 12 10
[root@centos8 ~]# echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
[root@centos8 ~]# echo {a..z..2}
a c e g i k m o q s u w y
[root@centos8 ~]# echo {000..20..2}
000 002 004 006 008 010 012 014 016 018 020
[root@centos8 ~]# echo {a..Z}
a _ ^ ] [ Z<br/>[root@centos8 ~]# man ascii<br/>[root@centos8 ~]# echo {A..z}<br/>A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ ] ^ _
a b c d e f g h i j k l m n o p q r s t u v w x y z
[root@centos8 ~]# echo file{1..10}.{txt,log}
file1.txt file1.log file2.txt file2.log file3.txt file3.log file4.txt file4.log file5.txt file5.log file6.txt file6.log file7.txt file7.log file8.txt file8.log file9.txt file9.log file10.txt file10.log
1.10 tab 鍵補全
1.10.1 命令補全
命令嵌套子命令(tab子命令補全)
[root@centos8 ~]# nmcli connection
add delete edit help load monitor show
clone down export import modify reload up
須要包
[root@centos8 ~]# rpm -qa bash*
bash-completion-2.7-5.el8.noarch
1.10.2 路徑補全
1.10.3 雙擊 Tab 鍵
1.11 命令行歷史
正常退出,歷史命令會追加到文件中。登陸,會導入內存
[root@centos8 ~]# cat ~/.bash_history
[root@centos8 ~]# echo $HISTSIZE
1000
[root@centos8 ~]# cat /etc/profile | grep HISTSIZ
HISTSIZE=1000
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
改完後
[root@centos8 ~]# source /etc/profile
[root@centos8 ~]# history -s rm -rf /
[root@centos8 ~]# history
149 echo $HISTSIZE
150 cat /etc/profile | grep HISTSIZ
151 history -s
152 history
153 rm -rf /
154 history
[root@centos8 ~]# cat .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
1.12 調用命令行歷史
1.13 bash 的快捷鍵
2 得到幫助
2.1 whatis
[root@centos8 ~]# whatis hostname
hostname: nothing appropriate.
[root@centos8 ~]# mandb
[root@centos8 ~]# whatis hostname
hostname (7) - hostname resolution description
hostname (1) - show or set the system's host name
hostname (5) - Local hostname configuration file
[root@centos8 ~]# man -f hostname
hostname (7) - hostname resolution description
hostname (1) - show or set the system's host name
hostname (5) - Local hostname configuration file
2.2 查看命令的幫助
內部命令(type)
help
man
2.3 --help 或 -h 選項
外部命令
cmd --help
[root@centos8 ~]# date +"%F %T"
2020-10-04 09:58:46
[root@centos8 ~]# touch date +%F_%H-%M-%S
.log
[root@centos8 ~]# mv app.log appdate -d '-1 day' +%F
.log
2.4 man 命令
[root@centos8 ~]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
[root@centos8 ~]# whatis passwd
openssl-passwd (1ssl) - compute password hashes
passwd (1) - update user's authentication tokens
passwd (5) - password file
[root@centos8 ~]# man 5 passwd
[root@centos8 ~]# man -k password
[root@centos8 ~]# man 7 utf8
[root@centos8 ~]# man -w ls
/usr/share/man/man1/ls.1.gz
2.5 info
[root@centos8 ~]# info ls
2.6 Linux 安裝提供的本地文檔獲取幫助
2.7 命令自身提供的官方使用指南
[root@centos8 doc]# pwd
/usr/share/doc
2.8 系統及第三方應用官方文檔
2.8.1 經過在線文檔獲取幫助
2.8.2 Linux 官方在線文檔和知識庫
2.8.3 紅帽全球技術支持服務
2.9 網站和搜索
已學:aliasbccalcat /ect/motd /etc/issuecdclearclockdatednfecho $PS1 $SHELLenableexitfilefreegedit 圖形化halthashhelphexdumphostname hostnamectlinit 0 3 5 6logoutlsblklscpumanmvnano /etc/motdpoweroffps auxrebootrunlevelshutdownsleepsreensudo -itmuxttytypeunaliasuptimewhereiswhichwhoamiwho who am iyum