码迷,mamicode.com
首页 > 系统相关 > 详细

Linux 基础入门(完成优先于完美)

时间:2020-10-05 22:01:53      阅读:34      评论:0      收藏:0      [点我收藏+]

标签:lsblk   drop   不用   ora   creat   关机   ini   UNC   auto   

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

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.iso

2、安装 Centos7、6 操作系统,创建一个自己名字的用户名,并可以正常登录,将主要步骤截图。

[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.c1023

[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

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

[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 history

4、总结 Linux 哲学思想。

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

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

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 网站和搜索

已学:
alias
bc
cal
cat /ect/motd /etc/issue
cd
clear
clock
date
dnf
echo $PS1 $SHELL
enable
exit
file
free
gedit 图形化
halt
hash
help
hexdump
hostname hostnamectl
init 0 3 5 6
logout
lsblk
lscpu
man
mv
nano /etc/motd
poweroff
ps aux
reboot
runlevel
shutdown
sleep
sreen
sudo -i
tmux
tty
type
unalias
uptime
whereis
which
whoami
who who am i
yum

Linux 基础入门(完成优先于完美)

标签:lsblk   drop   不用   ora   creat   关机   ini   UNC   auto   

原文地址:https://blog.51cto.com/12079667/2539990

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!