root用户: 一个特殊的管理账户,也被成为超级用户,root已接近完整的系统控制,对系统损害几乎有无线能力,除非必要,不要登录为root
普通(非特权用户): 权限有限,造成损害的能力比较有限
MBR、GPT磁盘分区表
主引导记录(Master Boot Rccord MBR) :可以安装启动引导程序的地方
分区表(partition):记录整块硬盘的分区状态
[root@192 ~]# w
10:38:53 up 18:48, 2 users, load average: 0.00, 0.11, 0.39
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 - Tue05 39:06 7.79s 7.79s -bash
root pts/0 192.168.1.5 10:02 5.00s 0.01s 0.00s w
[root@192 ~]# who
root tty1 2022-03-22 05:26
root pts/0 2022-03-25 10:02 (192.168.1.5)
[root@192 ~]# pwd
/root
[root@192 ~]# who am i
root pts/0 2022-03-25 10:02 (192.168.1.5)
[root@192 ~]#
[root@192 ~]# uname -a
Linux 4.18.0-147.el8.x86_64 #主版本.次版本.发布版本-修改版本
[root@192 testing]# uname -r
4.18.0-147.el8.x86_64
[root@192 testing]# uname -m
x86_64
[root@lxfcentos8 ~]# date +$Y/%m/%d
/03/25
[root@lxfcentos8 ~]# date +%Y/%m/%d
2022/03/25
[root@lxfcentos8 ~]# date +%H:%M
14:19
[root@lxfcentos8 ~]# date +%s
1648189242
[root@lxfcentos8 ~]# date --help #查看帮助
[root@lxfcentos8 ~]# cal
March 2022
Su Mo Tu We Th Fr Sa
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@lxfcentos8 ~]# cal 2022
2022
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 1 2 3 4 5 1 2 3 4 5
2 3 4 5 6 7 8 6 7 8 9 10 11 12 6 7 8 9 10 11 12
9 10 11 12 13 14 15 13 14 15 16 17 18 19 13 14 15 16 17 18 19
16 17 18 19 20 21 22 20 21 22 23 24 25 26 20 21 22 23 24 25 26
23 24 25 26 27 28 29 27 28 27 28 29 30 31
30 31
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 1 2 3 4 5 6 7 1 2 3 4
3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11
10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18
17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25
24 25 26 27 28 29 30 29 30 31 26 27 28 29 30
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 1 2 3 4 5 6 1 2 3
3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10
10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17
17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24
24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30
31
October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 1 2 3 4 5 1 2 3
2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
30 31
[root@lxfcentos8 ~]# cal 5 2011
May 2011
Su Mo Tu We Th Fr Sa
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@192 ~]# ls -al
total 32
dr-xr-xr-x. 17 root root 224 Mar 22 05:10 ..
文件类型 权限 拥有者 所在组 文件大小 修改时间
chgrp:修改文件所属用户组
chown:修改文件拥有者
chmod:修改文件的权限,SUID、SGID、SBIT等的特性
[root@192 ~]# ls -lcd /
-rw-r--r--. 1 root root 0 Mar 25 23:44 test
[root@192 ~]# chgrp centos8_user test
[root@192 ~]# ls -l
-rw-r--r--. 1 root centos8_user 0 Mar 25 23:44 test
[root@192 ~]# chgrp root test
[root@192 ~]# ls -l
-rw-r--r--. 1 root root 0 Mar 25 23:44 test
[root@192 ~]# chown centos8_user test
[root@192 ~]# ls -l
-rw-r--r--. 1 centos8_user root 0 Mar 25 23:44 test
[root@192 ~]# chown root test
[root@192 ~]# chmod 666 test
[root@192 ~]# ls -l
-rw-rw-rw-. 1 root root 0 Mar 25 23:44 test
chmod u\g\o\a|+\-\=|r\w\x file_name
[root@192 ~]# chmod a+x test
[root@192 ~]# ls -l test
-rwxrwxrwx. 1 root root 0 Mar 25 23:44 test
ll --time=atime /root/anaconda-ks.cfg ;输出access时间
ll --time=ctime /root/anaconda-ks.cfg ;输出权限属性变更时间
ll /root/anaconda-ks.cfg ; 输出文件内容变更的时间
|
命令
|
功能
|
参数
|
| cd | 切换目录 | |
| pwd | 显示当前目录 | -P 显示实际目录 |
| mkdir | 创建目录 | |
| rmdir | 删除目录 | -p 连同上层的空目录一起删除 |
| ls | 查看目录 | -a 全部文件 -d 仅显示目录 -l 详细信息 -R显示子目录 |
| cp | 复制文件 | -i 若目标文件存在询问 -p 连同文件的属性一并复制 -r递归复制 |
| rm | 删除文件 | -f 强制 -r递归删除 |
| mv | 移动文件 | |
| dirname |
[root@192 tmp]# basename /tmp/testing/ testing |
|
| basename |
[root@192 tmp]# dirname /tmp/testing/ /tmp |
|
符号
|
说明
|
| . | 当前目录 |
| .. | 上一级目录 |
| - | 前一个工作目录 |
| ~[账号] | 当前使用者的home目录或指定用户的家目录 |
|
命令
|
功能
|
说明
|
| cat | 从头看 | -n 打印行号 -A显示特殊字符 |
| tac | 从尾看 | |
| nl | 显示行号 | |
| less | 翻页看 | Enter下一行 空格键下一页 n|N 向前向后查找取决于{/|?} |
| tail | 只看最后几行 | tail -n 10 anaconda-ks.cfg 查看最后10行 |
| od | 以二进制方式读取文件 | |
| head | 查看前几行 | head -n 10 anaconda-ks.cfg 查看前10行 |
[root@192 ~]# cat -n anaconda-ks.cfg | head -n 20 | tail -n 10
11 keyboard --vckeymap=us --xlayouts='us'
12 # System language
13 lang en_US.UTF-8
14
15 # Network information
16 network --bootproto=dhcp --device=ens33 --onboot=off --ipv6=auto --no-activate
17 network --hostname=localhost.localdomain
18 repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream
19 # Root password
20 rootpw --iscrypted $6$pu3H2LauUZyuWUto$0xWrLZgEbT2zegn0zGINhmqdJfyawY.Ta0D8TpxRh5LCMeXJVlNEnei2eJWw4KZnDMfx3z9/ItDcOMP9QL9Em/
touch [option] file_name
-a 仅自定义access time
[root@192 ~]# touch test1
[root@192 ~]# ls -l
total 8
-rw-------. 1 root root 1377 Mar 22 05:13 anaconda-ks.cfg
-rw-r--r--. 1 root root 266 Mar 26 01:17 test
-rw-r--r--. 1 root root 0 Mar 26 02:22 test1
umask
[root@192 ~]# umask
0022
[root@192 ~]# chattr +i test #i 不可删除
[root@192 ~]# lsattr test
----i-------------- test
[root@192 ~]# chattr
Usage: chattr [-pRVf] [-+=aAcCdDeijPsStTu] [-v version] files...
The letters 'aAcCdDeijPsStTu' select the new attributes for the files:
append only (a), no atime updates (A), compressed (c), no copy on write (C), no dump (d), synchronous directory updates (D), extent format (e), immutable (i), data journalling (j), project hierarchy (P), secure deletion (s), synchronous updates (S), no tail-merging (t), top of directory hierarchy (T), and undeletable (u).
[root@192 /]# ls -ld /tmp/;ls -ld /usr/bin/passwd
drwxrwxrwt. 13 root root 4096 Mar 26 02:42 /tmp/
-rwsr-xr-x. 1 root root 34928 May 11 2019 /usr/bin/passwd
[root@192 ~]# file test
test: ASCII text
[root@192 ~]# file /etc/passwd
/etc/passwd: ASCII text
[root@192 ~]# file /usr/bin/passwd
/usr/bin/passwd: setuid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=4ba7de752293f0c8e4a3547285ea1952492eb9e4, stripped
#which [-a] command
[root@192 bin]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
[root@192 bin]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz
[root@192 ~]# find / -name "*testin*"
/etc/pki/rpm-gpg/RPM-GPG-KEY-centostesting
/usr/lib64/rsyslog/omtesting.so
/usr/share/doc/xkeyboard-config/HOWTO.testing
/tmp/testing
/tmp/testing/testing
[root@192 ~]#
#查看磁盘使用情况
[root@192 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 886M 0 886M 0% /dev
tmpfs tmpfs 904M 0 904M 0% /dev/shm
tmpfs tmpfs 904M 8.7M 895M 1% /run
tmpfs tmpfs 904M 0 904M 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 26G 1.5G 25G 6% /
/dev/sda1 ext4 976M 136M 774M 15% /boot
tmpfs tmpfs 181M 0 181M 0% /run/user/0
tmpfs tmpfs 181M 0 181M 0% /run/user/1000
[root@192 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 907128 0 907128 0% /dev
tmpfs 924780 0 924780 0% /dev/shm
tmpfs 924780 8856 915924 1% /run
tmpfs 924780 0 924780 0% /sys/fs/cgroup
/dev/mapper/cl-root 27245572 1547844 25697728 6% /
/dev/sda1 999320 138464 792044 15% /boot
tmpfs 184956 0 184956 0% /run/user/0
tmpfs 184956 0 184956 0% /run/user/1000
[root@192 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 886M 0 886M 0% /dev
tmpfs 904M 0 904M 0% /dev/shm
tmpfs 904M 8.7M 895M 1% /run
tmpfs 904M 0 904M 0% /sys/fs/cgroup
/dev/mapper/cl-root 26G 1.5G 25G 6% /
/dev/sda1 976M 136M 774M 15% /boot
tmpfs 181M 0 181M 0% /run/user/0
tmpfs 181M 0 181M 0% /run/user/1000
[root@192 ~]#
#查看文件占用情况
[root@192 ~]# du -h
44K .
[root@192 ~]# du -ah
4.0K ./.bash_logout
4.0K ./.bash_profile
4.0K ./.bashrc
4.0K ./.cshrc
4.0K ./.tcshrc
4.0K ./anaconda-ks.cfg
4.0K ./.bash_history
4.0K ./.lesshst
4.0K ./test
4.0K ./ll
4.0K ./test1
44K .
[root@192 ~]#
#不加参数创建硬链接、-s 创建软连接
[root@192 ~]# ll
total 16
-rw-------. 1 root root 1377 Mar 22 05:13 anaconda-ks.cfg
-rw-r--r--. 1 root root 611 Mar 26 03:19 ll
-rw-r--r--. 1 root root 266 Mar 26 01:17 test
-rw-r--r--. 1 root root 81 Mar 26 03:36 test1
drwxr-xr-x. 2 root root 6 Mar 26 03:43 testdir
lrwxrwxrwx. 1 root root 7 Mar 26 03:47 testdirln -> testdir
lrwxrwxrwx. 1 root root 4 Mar 26 03:44 testln -> test
[root@192 ~]# ll -i
total 16
34072132 -rw-------. 1 root root 1377 Mar 22 05:13 anaconda-ks.cfg
34072184 -rw-r--r--. 1 root root 611 Mar 26 03:19 ll
34072183 -rw-r--r--. 1 root root 266 Mar 26 01:17 test
34072186 -rw-r--r--. 1 root root 81 Mar 26 03:36 test1
16808713 drwxr-xr-x. 2 root root 6 Mar 26 03:43 testdir
34072185 lrwxrwxrwx. 1 root root 7 Mar 26 03:47 testdirln -> testdir
34072182 lrwxrwxrwx. 1 root root 4 Mar 26 03:44 testln -> test
[root@192 ~]# ln test1 testln1
[root@192 ~]# ll -i
total 20
34072132 -rw-------. 1 root root 1377 Mar 22 05:13 anaconda-ks.cfg
34072184 -rw-r--r--. 1 root root 611 Mar 26 03:19 ll
34072183 -rw-r--r--. 1 root root 266 Mar 26 01:17 test
34072186 -rw-r--r--. 2 root root 81 Mar 26 03:36 test1
16808713 drwxr-xr-x. 2 root root 6 Mar 26 03:43 testdir
34072185 lrwxrwxrwx. 1 root root 7 Mar 26 03:47 testdirln -> testdir
34072182 lrwxrwxrwx. 1 root root 4 Mar 26 03:44 testln -> test
34072186 -rw-r--r--. 2 root root 81 Mar 26 03:36 testln1
[root@192 ~]#
[root@192 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 886M 0 886M 0% /dev
tmpfs 904M 0 904M 0% /dev/shm
tmpfs 904M 8.7M 895M 1% /run
tmpfs 904M 0 904M 0% /sys/fs/cgroup
/dev/mapper/cl-root 26G 1.5G 25G 6% /
/dev/sda1 976M 136M 774M 15% /boot
tmpfs 181M 0 181M 0% /run/user/0
[root@192 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 29G 0 part
├─cl-root 253:0 0 26G 0 lvm /
└─cl-swap 253:1 0 3G 0 lvm [SWAP]
sr0 11:0 1 7G 0 rom
[root@192 ~]#
[root@192 ~]# parted /dev/sda print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary ext4 boot
2 1075MB 32.2GB 31.1GB primary lvm
[root@192 ~]# blkid
/dev/sda1: UUID="64ec4d3a-d3ea-4aa6-931e-1fe06bc6a11c" TYPE="ext4" PARTUUID="5d0c8e2f-01"
/dev/sda2: UUID="y4NDvp-3WGy-oAPF-ceTb-OP7n-BeiW-RxcP3F" TYPE="LVM2_member" PARTUUID="5d0c8e2f-02"
/dev/sr0: UUID="2020-01-03-21-42-40-00" LABEL="CentOS-8-1-1911-x86_64-dvd" TYPE="iso9660" PTUUID="087a73cc" PTTYPE="dos"
/dev/mapper/cl-root: UUID="489bc07d-91d5-4c42-bea8-7ed0f59c9cf7" TYPE="xfs"
/dev/mapper/cl-swap: UUID="5c75ef5e-64d4-4eeb-b152-4fad4e711f73" TYPE="swap"
[root@192 ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): m
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition #删除一个分区
F list free unpartitioned space
l list known partition types
n add a new partition #新增一个分区
p print the partition table #在屏幕上显示分区表
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit #保存
q quit without saving changes #不保存推退出
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
Command (m for help):
[root@192 ~]# grep 'processor' /proc/cpuinfo
processor : 0
processor : 1
[root@192 ~]# mkfs.xfs -f -d agcount=2 /dev/sda3
meta-data=/dev/sda3 isize=512 agcount=2, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@192 ~]#
[root@192 ~]# mkfs.ext4 /dev/sda3
mke2fs 1.44.6 (5-Mar-2019)
/dev/sda3 contains a ext4 file system
created on Sat Mar 26 18:26:53 2022
Proceed anyway? (y,N) y
Creating filesystem with 1310720 4k blocks and 327680 inodes
Filesystem UUID: d418717d-a381-405d-a996-8d0a8efb39ef
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@192 ~]#
#xfs文件系统
[root@192 ~]# xfs_repair /dev/sda3
Phase 1 - find and verify superblock...
Phase 2 - using internal log
- zero log...
- scan filesystem freespace and inode maps...
- found root inode chunk
Phase 3 - for each AG...
- scan and clear agi unlinked lists...
- process known inodes and perform inode discovery...
- agno = 0
- agno = 1
- process newly discovered inodes...
Phase 4 - check for duplicate blocks...
- setting up duplicate extent list...
- check for inodes claiming duplicate blocks...
- agno = 0
- agno = 1
Phase 5 - rebuild AG headers and trees...
- reset superblock...
Phase 6 - check inode connectivity...
- resetting contents of realtime bitmap and summary inodes
- traversing filesystem ...
- traversal finished ...
- moving disconnected inodes to lost+found ...
Phase 7 - verify and correct link counts...
done
[root@192 ~]#
#ext4文件系统检测#
[root@192 ~]# fsck.ext4 /dev/sda3
e2fsck 1.44.6 (5-Mar-2019)
/dev/sda3: clean, 11/327680 files, 42078/1310720 blocks
[root@192 ~]# fsck.ext4 -f /dev/sda3
e2fsck 1.44.6 (5-Mar-2019)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sda3: 11/327680 files (0.0% non-contiguous), 42078/1310720 blocks
[root@192 ~]#
[root@192 ~]# mount UUID="aabdb654-abcc-460f-bd36-42d4122db3e1" /root/mounttest/
[root@192 ~]# mkdir mounttest
[root@192 ~]# ls
anaconda-ks.cfg ll mounttest test test1 testdir testdirln testln testln1
[root@192 ~]# blkid
/dev/sr0: UUID="2020-01-03-21-42-40-00" LABEL="CentOS-8-1-1911-x86_64-dvd" TYPE="iso9660" PTUUID="087a73cc" PTTYPE="dos"
/dev/sda1: UUID="64ec4d3a-d3ea-4aa6-931e-1fe06bc6a11c" TYPE="ext4" PARTUUID="5d0c8e2f-01"
/dev/sda2: UUID="y4NDvp-3WGy-oAPF-ceTb-OP7n-BeiW-RxcP3F" TYPE="LVM2_member" PARTUUID="5d0c8e2f-02"
/dev/sda3: UUID="aabdb654-abcc-460f-bd36-42d4122db3e1" TYPE="xfs" PARTUUID="5d0c8e2f-03"
/dev/mapper/cl-root: UUID="489bc07d-91d5-4c42-bea8-7ed0f59c9cf7" TYPE="xfs"
/dev/mapper/cl-swap: UUID="5c75ef5e-64d4-4eeb-b152-4fad4e711f73" TYPE="swap"
[root@192 ~]# mount UUID="aabdb654-abcc-460f-bd36-42d4122db3e1" /root/mounttest/
[root@192 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 35G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 29G 0 part
│ ├─cl-root 253:0 0 26G 0 lvm /
│ └─cl-swap 253:1 0 3G 0 lvm [SWAP]
└─sda3 8:3 0 5G 0 part /root/mounttest
sr0 11:0 1 7G 0 rom
[root@192 ~]# cd mounttest/
[root@192 mounttest]# touch test
[root@192 mounttest]# ll
total 0
-rw-r--r--. 1 root root 0 Mar 26 18:44 test
[root@192 mounttest]#
#卸载目录
[root@192 mounttest]# umount /root/mounttest/
umount: /root/mounttest/: target is busy. #在这个目录位置无法卸载
[root@192 mounttest]# cd ../
[root@192 ~]# umount /root/mounttest/
设置开机自动挂载/dev/sda3挂载到 /root/mounttest
[root@192 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 35G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 29G 0 part
│ ├─cl-root 253:0 0 26G 0 lvm /
│ └─cl-swap 253:1 0 3G 0 lvm [SWAP]
└─sda3 8:3 0 5G 0 part /root/mounttest
sr0 11:0 1 7G 0 rom
[root@192 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Mar 22 05:09:47 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cl-root / xfs defaults 0 0
UUID=64ec4d3a-d3ea-4aa6-931e-1fe06bc6a11c /boot ext4 defaults 1 2
/dev/mapper/cl-swap swap swap defaults 0 0
/dev/sda3 /root/mounttest xfs defaults 0 0
[root@192 ~]#
#单一文件
[root@192 ~]# gzip fiel.txt #压缩
[root@192 ~]# ll
total 12
-rw-------. 1 root root 1377 Mar 22 05:13 anaconda-ks.cfg
-rw-r--r--. 1 root root 35 Mar 26 19:45 fiel.txt.gz
drwxr-xr-x. 2 root root 18 Mar 26 18:44 mounttest
-rw-r--r--. 1 root root 266 Mar 26 01:17 test
[root@192 ~]# zcat fiel.txt.gz #查看压缩文件内容
sdasdasdas
[root@192 ~]# gzip -d fiel.txt #解压缩
[root@192 ~]# ll
total 12
-rw-------. 1 root root 1377 Mar 22 05:13 anaconda-ks.cfg
-rw-r--r--. 1 root root 11 Mar 26 19:45 fiel.txt
drwxr-xr-x. 2 root root 18 Mar 26 18:44 mounttest
-rw-r--r--. 1 root root 266 Mar 26 01:17 test
[root@192 ~]#
#多个文件
tar {A|c|d|r|t|u|x}[GnSkUWOmpsMBiajJzZhPlRvwo] [ARG...]
-c 打包文件- t 查看包文件 -x 解包 -j bz2文件后缀 -J xz文件后缀 -z gz文件后缀
[root@192 ~]# tar -zcv -f testfile3.tar.gz testfile3
testfile3
[root@192 ~]# ll
total 20
-rw-r--r--. 1 root root 0 Mar 26 19:51 testfile3
-rw-r--r--. 1 root root 115 Mar 26 20:11 testfile3.tar.gz
[root@192 ~]# tar -ztv -f testfile3.tar.gz testfile3
-rw-r--r-- root/root 0 2022-03-26 19:51 testfile3
[root@192 ~]# rm testfile3
rm: remove regular empty file 'testfile3'? yes
[root@192 ~]# ll
total 20
-rw-r--r--. 1 root root 115 Mar 26 20:11 testfile3.tar.gz
[root@192 ~]# tar -zxv -f testfile3.tar.gz
testfile3
[root@192 ~]# ll
total 20
-rw-r--r--. 1 root root 0 Mar 26 19:51 testfile3
-rw-r--r--. 1 root root 115 Mar 26 20:11 testfile3.tar.gz
[root@192 ~]#
XFS文件备份还原 xfsdump 备份 xfsrestor 还原
|
命令
|
说明
|
| 0 | 一行最前面 |
| $ | 一行最后面 |
| H、M、L | 屏幕第一个字符、中间、对后一个 |
| G | 文章最后一行 |
| :set nu / nonu | = 设置行号/ 取消行号 |
| gg | 文章第一行 |
| 1 | :::: |
| /word | 查找字符 |
| n/N | 向下朝朝/向上查找 |
| x/X | 后删除/前删除 |
| dd | 删除行 |
| yy | 复制 |
| p | 粘贴 |
| J | 光标所在行和下一行结合成1行 |
| o/O | 在光标所在前插入一行输入数据/在光标所在后插入一行输入数据 |
| i/i | 光标前后输入数据 |
| w、q 、! | 保存、退出、强制 |
| r file_name | 在光标后插入另一个文件内容 |
| n1:n2 w file_name | 将n1到n2行的内容保存到另一个文件 |
| Ctrl V | 区块选择 |
| sp file_name | |
| ctrl w +j | 切换窗口 |
shell
[root@192 ~]# echo $SHELL
/bin/bash
变量名称只能是数字字母,不能以数字开头
用 ”=“ 连接
[root@192 ~]# myname=lxf
[root@192 ~]# echo ${myname}
lxf
[root@192 ~]# myinfo="myname is $myname"
[root@192 ~]# echo ${myinfo}
myname is lxf
#命令作为变量名称
[root@192 ~]# version=$(uname -r)
[root@192 ~]# echo $version
4.18.0-147.el8.x86_64
#追加变量内容
[root@192 ~]# myname=${myname}:jzj
[root@192 ~]# echo $myname
lxf:jzj
[root@192 ~]# myname=${myname}jzj
[root@192 ~]# echo $myname
lxf:jzjjzj
#取消变量
[root@192 ~]# unset myname
[root@192 ~]# env
SSH_CONNECTION=192.168.1.2 54800 192.168.1.8 22
LANG=en_US.UTF-8
HISTCONTROL=ignoredups
HOSTNAME=192.168.1.8
OLDPWD=/root/root
XDG_SESSION_ID=1
USER=root
SELINUX_ROLE_REQUESTED=
PWD=/root
HOME=/root
SSH_CLIENT=192.168.1.2 54800 22
SELINUX_LEVEL_REQUESTED=
SSH_TTY=/dev/pts/0
MAIL=/var/spool/mail/root
TERM=xterm
SHELL=/bin/bash
SELINUX_USE_CURRENT_RANGE=
SHLVL=1
LOGNAME=root
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/0/bus
XDG_RUNTIME_DIR=/run/user/0
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
HISTSIZE=1000
LESSOPEN=||/usr/bin/lesspipe.sh %s
_=/usr/bin/env
[root@192 ~]#
read 从键盘输入
[root@192 / 22:08]#read myname
lxf
[root@192 / 22:10]#echo $myname
lxf
#数组
[root@192 / 22:12]#arr[2]="2"
[root@192 / 22:12]#arr[1]="1"
[root@192 / 22:12]#echo $arr[2]
[2]
[root@192 / 22:12]#echo "${arr[1]},${arr[2]}"
1,2
[root@192 / 22:13]#
root@192 / 22:19]#echo $path
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@192 / 22:19]#echo ${path#/*usr/local/sbin:}
/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@192 / 22:20]#echo ${path##/*:}
/root/bin
[root@192 / 22:21]#
[root@192 ~ 22:28]#alias vim=/bin/vi #设置别名
[root@192 ~ 22:28]#alias #查看别名
alias rm='rm -i'
alias vim='/bin/vi'
alias which='(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-
[root@192 ~ 22:28]#unalias vim #取消别名
[root@192 ~ 22:28]#alias
alias rm='rm -i'
alias which='(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-
[root@192 ~ 22:28]#
#history 相关操作
886 ll
887 history
[root@192 ~ 22:32]#!886
ll
total 20
-rw-------. 1 root root 1377 Mar 22 05:13 anaconda-ks.cfg
-rw-------. 1 root root 1377 Mar 26 20:38 anaconda-ks.cfg.bk
drwxr-xr-x. 2 root root 18 Mar 26 19:47 mounttest
-rw-r--r--. 1 root root 135 Mar 26 21:18 test.test
-rw-r--r--. 1 root root 135 Mar 26 21:23 test1.test
-rw-r--r--. 1 root root 135 Mar 26 21:23 test2.test
[root@192 ~ 22:32]#!! #执行上一条命令
ll
total 20
-rw-------. 1 root root 1377 Mar 22 05:13 anaconda-ks.cfg
-rw-------. 1 root root 1377 Mar 26 20:38 anaconda-ks.cfg.bk
drwxr-xr-x. 2 root root 18 Mar 26 19:47 mounttest
-rw-r--r--. 1 root root 135 Mar 26 21:18 test.test
cmd1 || cmd2 或 cmd1 && cmd2 且
[root@192 ~]# ll /root/dir || touch dir.txt
ls: cannot access '/root/dir': No such file or directory
[root@192 ~]# ll
-rw-r--r--. 1 root root 0 Mar 26 23:47 dir.txt
[root@192 ~]# ll /root/dir && touch dir1.txt
ls: cannot access '/root/dir': No such file or directory
[root@192 ~]# ll
total 24
-rw-r--r--. 1 root root 0 Mar 26 23:47 dir.txt
[root@192 ~]# ll /root/mounttest && touch /root/mounttest/dir1.txt
total 0
-rw-r--r--. 1 root root 0 Mar 26 18:44 test
[root@192 ~]#
[root@192 ~]# cd mounttest/
[root@192 mounttest]# ll
total 0
-rw-r--r--. 1 root root 0 Mar 26 23:48 dir1.txt
[root@192 mounttest]#
标准输入:< 、<<
标准输出:>、>>
标准错误输出:2>、2>>
标准输出和标准错误输出一起输出:&>等价 2>&1
[root@192 ~]# ll /root/ls &> ll.log
[root@192 ~]# cat ll.log
ls: cannot access '/root/ls': No such file or directory
[root@192 ~]# ll /root &> ll.log
[root@192 ~]# cat ll.log
total 8
-rw-------. 1 root root 1377 Mar 22 05:13 anaconda-ks.cfg
-rw-------. 1 root root 1377 Mar 26 20:38 anaconda-ks.cfg.bk
-rw-r--r--. 1 root root 0 Mar 26 23:55 ll.log
drwxr-xr-x. 2 root root 34 Mar 26 23:48 mounttest
[root@192 ~]#
管道符后第一个数据必定是命令 ,且这个命令能够接受标准输入的数据。
例如:less、more、head、tail等都是管道符命令
例如:ls、cp、mv等就不是
#cut 分割数据
[root@192 ~]# cat ll.log
total 8
-rw-------. 1 root root 1377 Mar 22 05:13 anaconda-ks.cfg
-rw-------. 1 root root 1377 Mar 26 20:38 anaconda-ks.cfg.bk
-rw-r--r--. 1 root root 0 Mar 27 00:20 ll.log
drwxr-xr-x. 2 root root 50 Mar 27 00:18 mounttest
[root@192 ~]# cat ll.log | cut -d ' ' -f 1,2,3,4
total 8
-rw-------. 1 root root
-rw-------. 1 root root
-rw-r--r--. 1 root root
drwxr-xr-x. 2 root root
#grep 支持正则表达式
[root@192 ~]# cat ll.log | grep root
-rw-------. 1 root root 1377 Mar 22 05:13 anaconda-ks.cfg
-rw-------. 1 root root 1377 Mar 26 20:38 anaconda-ks.cfg.bk
-rw-r--r--. 1 root root 0 Mar 27 00:20 ll.log
drwxr-xr-x. 2 root root 50 Mar 27 00:18 mounttest
[root@192 ~]#
#sort 排序的使用
[root@192 ~]# cat ll.log | cut -d ' ' -f 2 | sort -n
1
1
1
2
8
[root@192 ~]# cat ll.log | sort -t ' ' -n -k 2
-rw-------. 1 root root 1377 Mar 22 05:13 anaconda-ks.cfg
-rw-------. 1 root root 1377 Mar 26 20:38 anaconda-ks.cfg.bk
-rw-r--r--. 1 root root 0 Mar 27 00:20 ll.log
drwxr-xr-x. 2 root root 50 Mar 27 00:18 mounttest
total 8
#列出重复的数据此时
[root@192 ~]# cat ll.log | cut -d ' ' -f 2 | uniq -c
1 8
3 1
1 2
#统计多少行
[root@192 ~]# cat ll.log | cut -d ' ' -f 2 | wc
5 5 10
[root@192 ~]# cat ll.log | cut -d ' ' -f 2 | wc -l #行数
5
[root@192 ~]# cat ll.log | cut -d ' ' -f 2 | wc -w #多少字
5
[root@192 ~]# cat ll.log | cut -d ' ' -f 2 | wc -m #多少字符
10
#tee 输入到文件同时输出到屏幕
[root@192 ~]# ping 192.168.1.1 | tee ping.log
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=1.54 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=2.08 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=1.95 ms
^C
[root@192 ~]# ll
total 16
-rw-------. 1 root root 1377 Mar 22 05:13 anaconda-ks.cfg
-rw-------. 1 root root 1377 Mar 26 20:38 anaconda-ks.cfg.bk
-rw-r--r--. 1 root root 228 Mar 27 00:20 ll.log
drwxr-xr-x. 2 root root 50 Mar 27 00:18 mounttest
-rw-r--r--. 1 root root 227 Mar 27 00:35 ping.log
[root@192 ~]#
#tr
[root@192 ~]# cat ping.log
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=1.75 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.86 ms
64 bytes from 192.168.1.1: icmp_seq=206 ttl=64 time=1.52 ms
#删除指定字符串
[root@192 ~]# cat ping.log | tr -d from
64 bytes 192.168.1.1: icp_seq=1 ttl=64 tie=1.75 s
64 bytes 192.168.1.1: icp_seq=2 ttl=64 tie=1.86 s
64 bytes 192.168.1.1: icp_seq=206 ttl=64 tie=1.52 s
#将小写换成大写
[root@192 ~]# cat ping.log | tr '[a-z]' '[A-Z]'
64 BYTES FROM 192.168.1.1: ICMP_SEQ=1 TTL=64 TIME=1.75 MS
64 BYTES FROM 192.168.1.1: ICMP_SEQ=2 TTL=64 TIME=1.86 MS
64 BYTES FROM 192.168.1.1: ICMP_SEQ=206 TTL=64 TIME=1.52 MS
[root@192 ~]#
#join 两个文件要用共同点
[root@192 ~]# head -n 3 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@192 ~]# head -n 3 /etc/shadow
root:$6$pu3H2LauUZyuWUto$0xWrLZgEbT2zegn0zGINhmqdJfyawY.Ta0D8TpxRh5LCMeXJVlNEnei2eJWw4KZnDMfx3z9/ItDcOMP9QL9Em/::0:99999:7:::
bin:*:18078:0:99999:7:::
daemon:*:18078:0:99999:7:::
[root@192 ~]# join -t ':' /etc/passwd /etc/shadow | head -n 3
root:x:0:0:root:/root:/bin/bash:$6$pu3H2LauUZyuWUto$0xWrLZgEbT2zegn0zGINhmqdJfyawY.Ta0D8TpxRh5LCMeXJVlNEnei2eJWw4KZnDMfx3z9/ItDcOMP9QL9Em/::0:99999:7:::
bin:x:1:1:bin:/bin:/sbin/nologin:*:18078:0:99999:7:::
daemon:x:2:2:daemon:/sbin:/sbin/nologin:*:18078:0:99999:7:::
[root@192 ~]# join -t ':' -1 4 /etc/passwd -2 4 /etc/shadow | head -n 3
0:root:x:0:root:/root:/bin/bash:root:$6$pu3H2LauUZyuWUto$0xWrLZgEbT2zegn0zGINhmqdJfyawY.Ta0D8TpxRh5LCMeXJVlNEnei2eJWw4KZnDMfx3z9/ItDcOMP9QL9Em/::99999:7:::
join: 0:root:x:0:root:/root:/bin/bash:bin:*:18078:99999:7:::
0:root:x:0:root:/root:/bin/bash:daemon:*:18078:99999:7:::
/etc/passwd:6: is not sorted: sync:x:5:0:sync:/sbin:/bin/sync
[root@192 ~]#
#paste 将第二个文件内容与第一个文件内容 tab 键隔开
[root@192 ~]# paste anaconda-ks.cfg anaconda-ks.cfg
#expand 将tab 转换成空格
expand -t 5 file_name #默认tab 是8个空格 可以用 -t 修改
[root@192 ~]# split -b 300b anaconda-ks.cfg.bk anac
[root@192 ~]# ll
total 24
-rw-r--r--. 1 root root 1377 Mar 27 00:58 anacaa
-rw-------. 1 root root 1377 Mar 26 20:38 anaconda-ks.cfg.bk
[root@192 ~]# ll
[root@192 ~]# grep -n '20' ping.log #指定字符所在行
3:64 bytes from 192.168.1.1: icmp_seq=206 ttl=64 time=1.52 ms
[root@192 ~]# grep -vn '20' ping.log #不含指定字符的行
1:64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=1.75 ms
2:64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.86 ms
[root@192 ~]# grep -in 'a' ping.log #不区分大小写
2:64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.86 ms A
3:64 bytes from 192.168.1.1: icmp_seq=206 ttl=64 time=1.52 ms a
[root@192 ~]# grep -n 'f[sb]om' ping.log #[]或的关系s或b 不能是sb
1:64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=1.75 ms fbom
2:64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.86 ms fsom
|
RE字符
|
说明
|
| ^word | 查找特定字符开头的行:grep -n '^#' anaconda-ks.cfg |
| word$ | 查找特定字符结尾的行:grep -n 'end$' anaconda-ks.cfg |
| . | 通配符 1个任意字符 |
| \ | 转义符 grep -n \" anaconda-ks.cfg |
| * | 重复前一个字符 grep -n 'add*' anaconda-ks.cfg #d*代表0或多个 |
| [list] | #[]或的关系s或b 不能是sb grep -n 'f[sb]om' ping.log |
| [n1-n2] | 两个字符之间的连续字符 [a-z] 、[A-Z]、[1-9] |
| [^list] | 非指定字符 [^A-Z] |
| \{n,m\} | 连续n到m个字符 grep -n 'ab\{2,\3}' anaconda-ks.cfg #abb、abbb 为结果 |
| + | 前一个字符1个或1个以上 |
| ? | 前一个字符0个或1个 |
| | | 或 |
| () | 找出群组字符串 god gld = g(o|l)d |
| ()+ | 多个重复的字符串 AasdasdasdQ =A(asd)+Q |
sed -option [操作]
sed [OPTION]... {script-only-if-no-other-script} [input-file]...
|
option
|
说明
|
| -n | sed操作过的行才会显示 |
| -e | 直接在命令行模式进行sed编辑 |
| -i | 直接修改读取文件内容 |
| n1,n2 | 在指定n1,n2 行直接操作 |
|
操作
|
说明
|
| a | 在下一行新增 |
| c | 替换cword |
| d | 删除 |
| i | 在前一行新增 |
| p | 打印 |
| s | 替换 正则表达式 |
#显示2、3行
[root@192 ~]# nl ping.log | sed -n '2,3p'
2 64 bytes fsbom 192.168.1.1: icmp_seq=2 ttl=64 time=1.86 ms fsom
3 64 bytes from 192.168.1.1: icmp_seq=206 ttl=64 time=1.52 ms a
#删除2-22行
[root@192 /]# nl /etc/passwd | sed '2,21d'
1 root:x:0:0:root:/root:/bin/bash
22 centos8_user:x:1000:1000:centos8_user:/home/centos8_user:/bin/bash
#在第2行前后(i\a)插入指定字符
[root@192 ~]# nl ping.log | sed '2a drink tea'
1 64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=1.75 ms fbom
2 64 bytes fsbom 192.168.1.1: icmp_seq=2 ttl=64 time=1.86 ms fsom
drink tea
[root@192 ~]# nl ping.log | sed '2i drink tea'
1 64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=1.75 ms fbom
drink tea
2 64 bytes fsbom 192.168.1.1: icmp_seq=2 ttl=64 time=1.86 ms fsom
#\n换行 插入2行
[root@192 ~]# nl ping.log | sed '2i drink tea \n aaaaaa'
1 64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=1.75 ms fbom
drink tea
aaaaaa
2 64 bytes fsbom 192.168.1.1: icmp_seq=2 ttl=64 time=1.86 ms fsom
#c替换 将第二行替换成aaaaaaaaa
[root@192 ~]# nl ping.log | sed '2c aaaaaaaa '
1 64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=1.75 ms fbom
aaaaaaaa
3 64 bytes from 192.168.1.1: icmp_seq=206 ttl=64 time=1.52 ms a
#提取IP地址
[root@192 ~]# cat ping.log | grep -n fsbom | sed 's/^.*fsbom //g' | sed 's/:.*$//g'
192.168.1.1
[root@192 ~]# tail -n 1 /etc/passwd
centos8_user: x :1000:1000:centos8_user:/home/centos8_user:/bin/bash
用户名 密码 UiD GID 说明信息 家目录 shell 目录
[root@192 ~]# tail -n 1 /etc/shadow
centos8_user:$6$63uOYua64……: 19077 : 0 : 99999
账号 密码 最近修改密码的时间 密码不可修改的天数 密码需要修改的天数
: 7 : : :
密码需要修改前警告天数 密码过期后宽限时间 密码失效日(与密码无关) 保留
[root@192 ~]# head -n 1 /etc/group
root: x : 0 :
组名 用户组密码 GID 此用户组支持的账号名称
[root@192 ~]# head -n 1 /etc/gshadow
root : : :
组名 密码 用户组管理账号 有加入该用户组支持的所属的账号
#将用户加入组
[root@192 ~]#usermod -d -G users centos8_user
[centos8_user@192 ~]$ groups
centos8_user users
#删除用户
[root@192 ~]# userdel testuser
[root@192 ~]# useradd testuser
[root@192 ~]# ll -d /home/testuser/
drwx------. 2 testuser testuser 62 Mar 27 06:18 /home/testuser/
[root@192 ~]# grep testuser /etc/passwd /etc/shadow /etc/group
/etc/passwd:testuser:x:1001:1001::/home/testuser:/bin/bash
/etc/shadow:testuser:!!:19077:0:99999:7:::
/etc/group:testuser:x:1001:
[root@192 ~]# useradd -u 1500 -g users testuser1
[root@192 ~]# grep testuser1 /etc/passwd /etc/shadow /etc/group
/etc/passwd:testuser1:x:1500:100::/home/testuser1:/bin/bash
/etc/shadow:testuser1:!!:19077:0:99999:7:::
[root@192 ~]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
[root@192 ~]#
[root@192 ~]# passwd testuser
Changing password for user testuser.
New password:
BAD PASSWORD: The password fails the dictionary check - it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.
[root@192 ~]# cat /etc/pam.d/password-auth
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authselect is run.
auth required pam_env.so
auth sufficient pam_unix.so try_first_pass nullok
auth required pam_deny.so
account required pam_unix.so
password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password sufficient pam_unix.so try_first_pass use_authtok nullok sha512 shadow
password required pam_deny.so
session optional pam_keyinit.so revoke
session required pam_limits.so
-session optional pam_systemd.so
session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session required pam_unix.so
[root@192 ~]# cat /etc/pam.d/passwd
#%PAM-1.0
# This tool only uses the password stack.
password substack system-auth
-password optional pam_gnome_keyring.so use_authtok
password substack postlogin
[root@192 ~]#
[root@192 ~]# cat /etc/login.defs | grep '^[^#]'
MAIL_DIR /var/spool/mail
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_MIN_LEN 5
PASS_WARN_AGE 7
UID_MIN 1000
UID_MAX 60000
SYS_UID_MIN 201
SYS_UID_MAX 999
GID_MIN 1000
GID_MAX 60000
SYS_GID_MIN 201
SYS_GID_MAX 999
CREATE_HOME yes
UMASK 077
USERGROUPS_ENAB yes
ENCRYPT_METHOD SHA512
[root@192 ~]#
[root@192 ~]# passwd -l testuser
Locking password for user testuser.
passwd: Success
[root@192 ~]# passwd -S testuser
testuser LK 2022-03-26 0 99999 7 -1 (Password locked.)
[root@192 ~]# passwd -u testuser
Unlocking password for user testuser.
passwd: Success
[root@192 ~]#
[root@192 ~]# chage -l testuser
Last password change : Mar 26, 2022
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
-d Last password change : Mar 26, 2022
-E Account expires : never
-I Password expires : never
-m
-M Number of days of warning before password expires : 7
-W Number of days of warning before password expires : 7
[root@192 ~]# id
uid=0(root) gid=0(root) groups=0(root)
[root@192 ~]# groupadd testgroup
[root@192 ~]# groupdel testgroup
[root@192 ~]# groupadd testgroup
[root@192 ~]# gpasswd testgroup
Changing the password for group testgroup
New Password:
Re-enter new password:
[root@192 ~]# gpasswd -A centos8_user testgroup
[root@192 ~]# grep testgroup /etc/gshadow /etc/group
/etc/gshadow:testgroup:$6$dg9Bv/80GNb/fc.P$9m.rNQImNxyVEFZ3HWmwcsZUkUtmM8SICgNw.6W6P22tOxwa6WEmhCmMcM8ZsVz1bYIA.ENJdhHkIzaJCTj/r/:centos8_user:
/etc/group:testgroup:
|
账号名称
|
账号全名
|
支持次要用户组
|
是否登录主机
|
密码
|
|
myuser1
|
1st user
|
mygroup1
|
Y
|
password
|
|
myuser2
|
2nd user
|
mygroup1
|
Y
|
password
|
|
myuser3
|
3rd user
|
无额外支持
|
N
|
password
|
[root@192 ~]# groupadd mygroup1
[root@192 ~]# useradd -G mygroup1 -c "1st user" mysuer1
[root@192 ~]# useradd -G mygroup1 -c "2nd user" mysuer2
[root@192 ~]# useradd -G mygroup1 -c "3rd user" -s /sbin/nologin mysuer3
[root@192 ~]# echo "password" | passwd --stdin mysuer1
Changing password for user mysuer1.
passwd: all authentication tokens updated successfully.
[root@192 ~]# echo "password" | passwd --stdin mysuer2
Changing password for user mysuer2.
passwd: all authentication tokens updated successfully.
[root@192 ~]# echo "password" | passwd --stdin mysuer3
Changing password for user mysuer3.
passwd: all authentication tokens updated successfully.
|
账号名称
|
支持次要用户组
|
密码
|
|
pro1
|
projecta
|
password
|
|
pro2
|
projecta
|
password
|
|
pro3
|
projecta
|
password
|
[root@192 ~]# groupadd projecta
[root@192 ~]# useradd -G projecta -c "projecta" pro1
[root@192 ~]# useradd -G projecta -c "projecta" pro2
[root@192 ~]# useradd -G projecta -c "projecta" pro3
[root@192 ~]# echo "password" | passwd --stdin pro1
Changing password for user mysuer1.
passwd: all authentication tokens updated successfully.
[root@192 ~]# echo "password" | passwd --stdin pro2
Changing password for user mysuer2.
passwd: all authentication tokens updated successfully.
[root@192 ~]# echo "password" | passwd --stdin pro3
Changing password for user mysuer3.
passwd: all authentication tokens updated successfully.
[root@192 ~]# mkdir /srv/projecta
[root@192 ~]# chgrp projecta /srv/projecta/
[root@192 ~]# chmod 2775 /srv/projecta/
[root@192 ~]# ll -d /srv/projecta/
drwxrwsr-x. 2 root projecta 6 Mar 27 07:08 /srv/projecta/
[root@192 ~]#gpasswd -A centos8_user projecta
[root@192 ~]# crontab -l
0 11 * * * wall "test jihuarenwu"
#分 时 日 月 周 命令
# -e 编辑 -l 查看 -r 删除
[root@192 ~]#
[root@192 ~]#
[root@192 ~]# date
Sun Mar 27 10:59:56 CST 2022
Broadcast message from root@192.168.1.8 (somewhere) (Sun Mar 27 11:00:01 2022):
test jihuarenwu
|
特殊字符
|
说明
|
| * | 匹配所有 |
| , | 3,6 3和6 |
| - | 20 7-10 7点到10点 每20分钟 |
| /n | n代表数字 每隔n单位时间 */5 每隔5分钟 |
[root@192 ~]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
[root@192 ~]# cat /etc/anacrontab
# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
#period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
anacron [-s] [-f] [-n] [-d] [-q] [-t anacrontab] [-S spooldir] [job]
anacron [-S spooldir] -u [-t anacrontab] [job]
anacron [-V|-h]
anacron -T [-t anacrontab]
|
option
|
说明
|
| -s | 开始连续执行任务 |
| -f | 强制执行 |
| -n | 立刻执行未执行任务 |
| -u | 更新记录文件时间戳不执行任务 |
| job | /etc/anacrontab定义的任务 |
#查看当前进程
[root@192 ~]# ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 0 7645 7631 0 80 0 - 6370 - pts/0 00:00:00 bash
0 R 0 7758 7645 0 80 0 - 11191 - pts/0 00:00:00 ps
4 T 0 7760 7645 0 80 0 - 8097 - pts/0 00:00:00 ping
[root@192 ~]#
[root@192 ~]# jobs -l
[2] 7816 Running ping 192.168.1.1 > ping.log &
[3]- 7819 Stopped find / -print
[4]+ 7820 Stopped find / -print
[root@192 ~]# jobs -r
[2] Running ping 192.168.1.1 > ping.log &
[root@192 ~]# jobs -s
[3]- Stopped find / -print
[4]+ Stopped find / -print
[root@192 ~]#
[root@192 ~]# ping 192.168.1.1 > ping.log &
[1] 7828
[root@192 ~]# jobs
[1]+ Running ping 192.168.1.1 > ping.log &
[root@192 ~]# fg
ping 192.168.1.1 > ping.log
^C[root@192 ~]# jobs
[root@192 ~]#
#fg n 将后台任务n显示
[root@192 ~]# kill -l
1) SIGHUP#启动进程 2) SIGINT#终端进程 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL#结束进程 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM#以正常方式结束进程
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP#暂停进程 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
[root@192 ~]# kill -9 %1 ; jobs
[1]+ Running ping 192.168.1.1 > ping.log &
[root@192 ~]# kill -9 %1 ; jobs
-bash: kill: (7830) - No such process
[1]+ Killed ping 192.168.1.1 > ping.log
[root@192 ~]# ps aux | grep "rsys.*"
root 1374 0.0 0.4 208748 9008 ? Ssl Mar26 0:01 /usr/sbin/rsyslogd -n
[root@192 ~]# ps aux | grep "rsys.*" | grep -v 'grep'
root 1374 0.0 0.4 208748 9008 ? Ssl Mar26 0:01 /usr/sbin/rsyslogd -n
[root@192 ~]# ps aux | grep "rsys.*" | grep -v 'grep' | awk '{print $2}'
1374
[root@192 ~]# kill -1 $(ps aux | grep "rsys.*" | grep -v 'grep' | awk '{print $2}')
killall -i 进程名称
ps [options]
|
option
|
说明
|
| -A | 所有进程与-e一样效果 |
| -a | 不显示与终端有关的进程 |
| -u | 有效使用者的相关进程 |
| x | 列出比较完整的信息 |
| l | pid 信息详细列出来 |
| j | 任务的格式 |
| -f | 做一个完整的输出 |
[root@192 ~]# ps aux | head -n 5
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.7 178652 13204 ? Ss Mar26 0:01 /usr/lib
root 2 0.0 0.0 0 0 ? S Mar26 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? I< Mar26 0:00 [rcu_gp]
root 4 0.0 0.0 0 0 ? I< Mar26 0:00 [rcu_par_gp]
#查看自己的进程
[root@192 ~]# ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 0 7645 7631 0 80 0 - 6403 - pts/0 00:00:00 bash
4 S 0 7859 7645 0 80 0 - 31037 - pts/0 00:00:00 su
4 S 0 7860 7859 0 80 0 - 6344 - pts/0 00:00:00 bash
#F 4代表root S代表状态:R表示运行、S代表休眠、D代表不可唤醒状态、T停止的状态、Z:僵尸状态
#
#查看所有树状 进程ID
[root@192 ~]# ps axjf | head -n 10
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
0 2 0 0 ? -1 S 0 0:00 [kthreadd]
2 3 0 0 ? -1 I< 0 0:00 \_ [rcu_gp]
2 4 0 0 ? -1 I< 0 0:00 \_ [rcu_par_gp]
2 6 0 0 ? -1 I< 0 0:00 \_ [kworker/0:0H]
2 8 0 0 ? -1 I< 0 0:00 \_ [mm_percpu_wq]
2 9 0 0 ? -1 S 0 0:00 \_ [ksoftirqd/0]
2 10 0 0 ? -1 I 0 0:06 \_ [rcu_sched]
2 11 0 0 ? -1 S 0 0:00 \_ [migration/0]
2 12 0 0 ? -1 S 0 0:00 \_ [watchdog/0]
[root@192 ~]#
top -hv|-bcEHiOSs1 -d secs -n max -u|U user -p pid -o fld -w [cols]
|
选项
|
说明
|
| -d | 刷新时间单位秒 |
| -b | 以批量方式执行top |
| -n | 与-b一起使用,需要执行几次top的输出结果 |
| -p | 指定PID信息 |
| P | 以cpu 排序 |
| M | 以内存排序 |
| N | 以pid排序 |
| T | 由该进程使用的cpu时间累积排序 |
| r | 给予pid一个nice值 |
| k | 给予pid一个信号 |
[root@192 ~]# top | head -n 10
top - 12:31:31 up 14:48, 3 users, load average: 0.00, 0.00, 0.00
Tasks: 153 total, 1 running, 152 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 2.9 sy, 0.0 ni, 97.1 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 1806.2 total, 1179.4 free, 261.1 used, 365.7 buff/cache
MiB Swap: 3072.0 total, 3072.0 free, 0.0 used. 1363.5 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 178652 13204 8364 S 0.0 0.7 0:01.75 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd
3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp
#在top 命令中 输入 相关参数排序
[root@192 ~]# free -m -t -s 2
# 单位 总量 刷新时间2s
total used free shared buff/cache available
Mem: 1806 260 1179 8 365 1363
Swap: 3071 0 3071
Total: 4878 260 4251
total used free shared buff/cache available
Mem: 1806 260 1179 8 365 1363
Swap: 3071 0 3071
Total: 4878 260 4251
total used free shared buff/cache available
Mem: 1806 260 1179 8 365 1363
Swap: 3071 0 3071
Total: 4878 260 4251
total used free shared buff/cache available
Mem: 1806 260 1179 8 365 1363
Swap: 3071 0 3071
Total: 4878 260 4251
[root@192 ~]# uptime
12:57:29 up 15:14, 3 users, load average: 0.00, 0.00, 0.00
#查看系统运行时间 以及最近1、5、15分钟负载情况
root@192 ~]# getenforce
Enforcing
[root@192 ~]# setenforce disabled
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@192 ~]# setenforce 0
[root@192 ~]# getenforce 0
Permissive
[root@192 ~]# cat /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.target
Wants=sshd-keygen.target
[Service]
Type=notify
EnvironmentFile=-/etc/crypto-policies/back-ends/opensshserver.config
EnvironmentFile=-/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS $CRYPTO_POLICY
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
[root@192 ~]#
systemctl [OPTIONS...] COMMAND [UNIT...]
#start 、stop 、restart、reload、enable、disable、status、
[root@192 ~]# systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-03-26 18:57:32 CST; 18h ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 975 (sshd)
Tasks: 1 (limit: 11338)
Memory: 13.6M
CGroup: /system.slice/sshd.service
└─975 /usr/sbin/sshd -D -oCiphers=aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes256-cbc,aes128-gcm@openssh.com,aes128-ctr,aes128-cbc -oMACs=hmac-sha2-256-etm@openssh.com,hmac>
Mar 27 12:03:26 192.168.1.8 sshd[7773]: Accepted password for centos8_user from 192.168.1.5 port 53268 ssh2
Mar 27 12:03:26 192.168.1.8 sshd[7773]: pam_unix(sshd:session): session opened for user centos8_user by (uid=0)
lines 1-21/21 (END)
#查看服务与端口对应
[root@192 ~]# cat -n /etc/services | less
##