1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
[root@centos8 data]# grep -v "/sbin/nologin" /etc/passwd |echo "`wc -l`个用户,如下:" && grep -v "/sbin/nologin" /etc/passwd | cut -d: -f1
8个用户,如下:
root
sync
shutdown
halt
thomas
user1
user2
user3
[root@centos8 data]#
2、查出用户UID最大值的用户名、UID及shell类型
[root@centos8 data]# grep `grep -oE "[0-9]+:[0-9]+" /etc/passwd |cut -d: -f1 | sort -nr | head -1` /etc/passwd | cut -d: -f1,3,7
nobody:65534:/sbin/nologin
[root@centos8 data]#
方法一 grep `grep -oE "[0-9]+:[0-9]+" /etc/passwd |cut -d: -f1 | sort -nr | head -1` /etc/passwd
该步骤可能会筛出gid最大的值,得不到想要的结果。仅留做借鉴,建议使用方法2提取 max uid信息即可。
[root@centos8 data]# cut -d: -f1,3,7 /etc/passwd | sort -t: -k2 -nr | head -1
nobody:65534:/sbin/nologin
[root@centos8 data]#
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[root@centos8 data]# ss -ant -H | grep -oE "([0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]*[[:space:]]*$" | cut -d: -f1 | sort -nr|uniq -c
4 10.0.0.1
1 8.43.85.14
[root@centos8 data]#
4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
#disk.sh
#!/bin/bash
#********************************************************************
#Author: xxxxxxxxxxxxx
#Date: 2021-12-03 01:17
#FileName: disk.sh
#Description:Shell Script
#********************************************************************
red="\e[1;31m"
green="echo -e \e[1;32m"
end="\e[0m"
disk_max_use=`df -h| grep -vi filesystem| tr -s ' ' '%'| cut -d'%' -f5| sort -nr |head -1`
disk_name=`df -h |grep $disk_max_use |cut -d' ' -f1`
$green----MAX DISK INFO----------$end
echo -e "$red DISK-NAME: $disk_name $end"
echo -e "$red MAX-USAGE: $disk_max_use% $end"
$green---------------------------$end
运行结果:
[root@centos8 shell-excercise]# bash disk.sh
----MAX DISK INFO----------
DISK-NAME: /dev/sda5
MAX-USAGE: 21%
---------------------------
[root@centos8 shell-excercise]#
5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
#systeminfo.sh
#!/bin/bash
#********************************************************************
#Author: xxxxxxxxxxxxxx
#Date: 2021-12-03 00:12
#FileName: systeminfo.sh
#Description:Shell Script
#********************************************************************
red="\e[1;31m"
green="echo -e \e[1;32m"
end="\e[0m"
sys_hostname=`hostnamectl |grep hostname | cut -d: -f2`
sys_ipaddr=`ip addr show ens33 |grep -oE "([0-9]{1,3}\.){3}[0-9]{1,3}" |head -1`
os_ver=`cat /etc/os-release |grep -i "pretty_name" |cut -d= -f2`
kernel_ver=`uname -r`
cpu_ver=`cat /proc/cpuinfo |grep -i "model name" | cut -d: -f2 |uniq`
ram_size=`cat /proc/meminfo |grep -i "memtotal" |cut -d: -f2 |tr -s ' '`
disk_size=`lsblk |grep "^sd" |tr -s ' ' |cut -d' ' -f4`
$green-----------------------SystemInfo--------------------------------$end
echo -e "$red HOSTNAME: $sys_hostname $end"
echo -e "$red IPADDR: $sys_ipaddr $end"
echo -e "$red OS_VERSION: $os_ver $end"
echo -e "$red KERNEL: $kernel_ver $end"
echo -e "$red CPU: $cpu_ver $end"
echo -e "$red RAM SIZE: $ram_size $end"
echo -e "$red DISK SIZE: $disk_size $end"
$green-----------------------SystemInfo--------------------------------$end
运行结果:
[root@centos8 shell-excercise]# bash systeminfo.sh
-----------------------SystemInfo--------------------------------
HOSTNAME: centos8.magedu.org
IPADDR: 10.0.0.151
OS_VERSION: "CentOS Linux 8"
KERNEL: 4.18.0-305.3.1.el8.x86_64
CPU: Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz
RAM SIZE: 1997772 kB
DISK SIZE: 200G
-----------------------SystemInfo--------------------------------
[root@centos8 shell-excercise]#
6、20分钟内通关vimtutor(可参考https://yyqing.me/post/2017/2017-02-22-vimtutor-chinese-summary)
vimtutor:
Lesson 1 summary
Lesson 1.1: Moving the cursor 移动
h:⬅ j:⬇ k:⬆ l:➡
Lesson 1.2: EXITING VIM 退出
1. Press the <ESC> key (make sure in normal mode)
2. Type: :q!<ENTER> (discarding any changes you have mode)
Lesson 1.3: TEXT EDITING - DELETION 删除
** Press x to delete the character under the cursor.**
Lesson 1.4: TEXT EDITING - INSERTION 插入
** Press i to insert text.**
Lesson 1.5: TEXT EDITING - APPENDING 添加
** Press A to append text.**
Lesson 1.6: EDITING A FILE 使用 :wq 命令保存并退出
** Use :wq to save file and exit. **
Lesson 2 Summary
1. To delete from the cursor up to the next word type: dw
** dw 从光标处开始删除直至遇到下一个单词 **
2. To delete from the cursor up to the end of a line type: d$
** d$ 从光标处开始删除至行末 **
3. To delete a whole line type: dd
** dd 删除光标所在整行 **
4. To repeat a motion prepend it with a number: 2w
** 在动作前面加数字来实现重复操作 **
5. The format for a change command is:
operator [number] motion
where:
operator - is what to do, such as d for delete
[number] - is an optional count to repeat the motion
motion - moves over the text to operate on, such as w (word),
$ (to the end of line), etc.
6. To move to the start of the line use a zero: 0
** Normal模式下数字0可以将光标移至行首 **
7. To undo previous actions, type: u (lowercase u)
To undo all the changes on a line, type: U (capital U)
To undo the undo's, type: CTRL-R
** 小字母u可以撤销上一步操作,大写字母U可以撤销整行的修改,ctrl+r可以恢复刚刚被u撤销的修改**
Lesson 3 Summary
1. To put back text that has just been deleted, type p . This puts the
deleted text AFTER the cursor (if a line was deleted it will go on the
line below the cursor).
** Normal模式下,字母p可以将删除的文本粘贴到光标所在位置的后面,如果删除的是一行,则粘贴在光标所在行的下一行位置**
2. To replace the character under the cursor, type r and then the
character you want to have there.
** Normal模式下,将光标移动至要替换的字母上,键入r,然后再键入想要替换成的字母即可 **
3. The change operator allows you to change from the cursor to where the motion takes you. eg. Type ce to change from the cursor to the end of the word, c$ to change to the end of a line.
** Normal模式下,键入ce/c$ 将删除从光标处开始至单词末/行末,并进入Insert模式,输入修改后的内容 **
4. The format for change is:
c [number] motion
Lesson 4 Summary
1. CTRL-G displays your location in the file and the file status.
G moves to the end of the file.
number G moves to that line number.
gg moves to the first line.
**Normal模式下,G定位到文件末行,数字+G定位到指定数字行,gg定位到文件首行。**
2. Typing / followed by a phrase searches FORWARD for the phrase.
Typing ? followed by a phrase searches BACKWARD for the phrase.
After a search type n to find the next occurrence in the same direction
or N to search in the opposite direction.
CTRL-O takes you back to older positions, CTRL-I to newer positions.
**Normal模式下,键入 /string 或 ?string 来实现字符串向下/向上匹配搜索,n为当前搜索模式下顺序搜索下一个结果,N为反向搜索下一个结果。ctrl+o 定位到光标上一次位置,ctrl-i 定位到光标较目前的下一个位置(如有)。**
3. Typing % while the cursor is on a (,),[,],{, or } goes to its match.
**Normal模式下,当光标在括号等字符上时键入%来定位匹配的字符对。**
4. To substitute new for the first old in a line type :s/old/new
To substitute new for all 'old's on a line type :s/old/new/g
To substitute phrases between two line #'s type :#,#s/old/new/g
To substitute all occurrences in the file type :%s/old/new/g
To ask for confirmation each time add 'c' :%s/old/new/gc
**Normal模式下,键入:s/old/new实现对光标所在行的匹配的第一个字符串进行替换,:s/old/new/g实现对光标所在行的匹配的全部字符串进行替换。:#,#s/old/new/g实现对指定的#-#行之间的匹配的全部字符串进行替换。:%s/old/new/g实现对全文匹配的全部字符串进行替换,gc则是增加每个字符串替换前确认提示。**
Lesson 5 Summary
1. :!command executes an external command.
Some useful examples are:
(MS-DOS) (Unix)
:!dir :!ls - shows a directory listing.
:!del FILENAME :!rm FILENAME - removes file FILENAME.
**Normal模式下,通过键入 :!command 来执行外部的shell命令**
2. :w FILENAME writes the current Vim file to disk with name FILENAME.
**Normal模式下,键入 :w filename 来将当前内容另存为当前目录的 filename 文件中。**
3. v motion :w FILENAME saves the Visually selected lines in file
FILENAME.
**normal模式下通过键入v进入visual模式,在visual模式下选取部分内容后,键入 :w filename 将选取的内容另存为当前目录下的 filename 文件。**
4. :r FILENAME retrieves disk file FILENAME and puts it below the
cursor position.
**normal模式下,键入 :r filename 来提取当前目录下filename文件内容至光标下位置。**
5. :r !dir reads the output of the dir command and puts it below the
cursor position.
*Normal模式下,键入 :r !command 将命令command的执行结果提取到光标下位置。**
Lesson 6 Summary
1. Type o to open a line BELOW the cursor and start Insert mode.
Type O to open a line ABOVE the cursor.
**Normal模式下,键入小写o来在光标下新开一行并进入Insert模式,大写O则是在上一行。**
2. Type a to insert text AFTER the cursor.
Type A to insert text after the end of the line.
**Normal模式下,键入小写a在光标后进入Insert模式,大写A则是定位到行末并进入Insert模式。**
3. The e command moves to the end of a word.
**Normal模式下,键入e将光标移动至单词末尾处。**
4. The y operator yanks (copies) text, p puts (pastes) it.
**Normal模式下,y表示复制,p表示粘贴**
5. Typing a capital R enters Replace mode until <ESC> is pressed.
**Normal模式下,键入大写R进入字符连续替换模式直至键入<ESC>返回Normal模式。**
6. Typing ":set xxx" sets the option "xxx". Some options are:
'ic' 'ignorecase' ignore upper/lower case when searching
'is' 'incsearch' show partial matches for a search phrase
'hls' 'hlsearch' highlight all matching phrases
You can either use the long or the short option name.
7. Prepend "no" to switch an option off: :set noic
**Normal模式下,键入 :set xxx 来开启 xxx对应的功能,:set noxxx 来关闭。**
Lesson 7 Summary
1. Type :help or press <F1> or <Help> to open a help window.
**Normal模式下,键入 :help启动帮助文档窗口。**
2. Type :help cmd to find help on cmd .
**Normal 或帮助文档窗口中,键入 :help cmd 来查找命令 cmd 的帮助信息。**
3. Type CTRL-W CTRL-W to jump to another window
**vim多窗口模式下通过 ctrl+w 来切换窗口。**
4. Type :q to close the help window
**键入 :q 来退出帮助窗口。**
5. Create a vimrc startup script to keep your preferred settings.
**可以参考 :r $VIMRUNTIME/vimrc_example.vim 来创建自己的vim环境。保存在 ~/.vimrc文件。**
6. When typing a : command, press CTRL-D to see possible completions.
Press <TAB> to use one completion.
**键入冒号 : 后,可通过ctrl+d 来显示命令选项,通过tab按键来实现命令补齐或切换提示**
vim提高资料参考链接:http://iccf-holland.org/click5.html