linux foundation regular expression, shell base, and compression file search
1.shell program displays basic information about your computer, the primary basis for the script. Only for version 6.7.
COLOR="\033[1;36m"
COLOREND="\033[0m"
echo -e "CPU type is $COLOR `lscpu |grep 'Model name'|tr -s ' '|cut -d: -f2`$COLOREND"
echo -e "Disk space is $COLOR `lsblk |grep 'disk' |tr -s ' '|cut -d' ' -f4|head -n 1` $COLOREND"
echo -e "Memory size is $COLOR `free -h |grep 'Mem'|tr -s ' '|cut -d' ' -f2` $COLOREND"
echo -e "OS Verion is $COLOR `cat /etc/redhat-release` $COLOREND"
echo -e "kernel version is $COLOR `uname -r` $COLOREND"
echo -e "IPaddr is $COLOR ` ifconfig ens33 |grep 'netmask'|tr -s ' '|cut -d' ' -f3`$COLOREND"
2. Find ifconfig "name card" command IPv4 address of the machine results
[root@centos7 scripts38]#ifconfig ens33 |grep netmask|tr -s ' '|cut -d' ' -f3
192.168.11.131
[root@centos7 ~]#ifconfig ens33 |grep ask | grep -o "\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}"|head -1
192.168.6.136
3. To find out the maximum percentage of the value of partition space usage
[root@centos7 scripts38]#df|grep '/dev/sd'|tr -s ' '|cut -d' ' -f5|tr -d %|sort -nr|head -n 1
17
4. The isolated UID of the maximum user name, UID and shell type
[root@centos7 scripts38]#cat /etc/passwd |cut -d: -f1,3,7 |sort -t: -k2 -nr|head -n 1
nfsnobody:65534:/sbin/nologin
The isolated for / tmp permissions, shown numerically
[root@centos7 ~]#stat /tmp |grep 'drwx'|cut -d' ' -f2|tr -dc [0-9]
1777
6. statistics for each connection currently connected remote host IP of the machine, press descending order
netstat -tun|grep ESTAB|tr -s " " : |cut -d: -f6|sort -nr|uniq -c
1 192.168.6.1
The display / proc / meminfo file to the beginning of the line size s (requirement: two methods)
[root@centos7 ~]#grep ^[sS] /proc/meminfo
SwapCached: 2288 kB
SwapTotal: 2097148 kB
SwapFree: 2058044 kB
Shmem: 16796 kB
Slab: 88744 kB
SReclaimable: 39980 kB
SUnreclaim: 48764 kB
[root@centos7 ~]#grep '^s\|^S' /proc/meminfo
SwapCached: 2288 kB
SwapTotal: 2097148 kB
SwapFree: 2058044 kB
Shmem: 16796 kB
Slab: 88744 kB
SReclaimable: 39980 kB
SUnreclaim: 48764 kB
[root@centos7 ~]#grep ^[s\|S] /proc/meminfo
SwapCached: 2288 kB
SwapTotal: 2097148 kB
SwapFree: 2058044 kB
Shmem: 16796 kB
Slab: 88744 kB
SReclaimable: 39980 kB
SUnreclaim: 48764 kB
[root@centos7 ~]#grep -w \<'s\|S.*' /proc/meminfo
SwapCached: 2288 kB
SwapTotal: 2097148 kB
SwapFree: 2058044 kB
Shmem: 16796 kB
Slab: 88716 kB
SReclaimable: 39980 kB
SUnreclaim: 48736 kB
The display / etc / passwd file not to / bin / bash line end
[root@centos7 ~]#cat /etc/passwd |grep -v '/bin/bash$'
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
The display default shell user rpc program
[root@centos7 ~]#cat /etc/passwd |grep '\<rpc\>'|cut -d: -f7
/sbin/nologin
10. To find the / etc / passwd in two or three-digit
[root@centos7 ~]#cat /etc/passwd |grep "\<[0-9]\{2,3\}\>"
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
libstoragemgmt:x:998:995:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
colord:x:997:994:User for colord:/var/lib/colord:/sbin/nologin
The display /etc/grub2.cfg CentOS7 file, at least to begin with a blank behind the characters and the non-
blank character lines
[root@centos7 ~]#cat /etc/grub2.cfg |grep ^[[:space:]].*
load_env
set default="${next_entry}"
set next_entry=
save_env next_entry
set boot_once=true
set default="${saved_entry}"
menuentry_id_option="--id"
menuentry_id_option=""
set saved_entry="${prev_saved_entry}"
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
if [ -z "${boot_once}" ]; then
saved_entry="${chosen}"
save_env saved_entry
fi
if [ x$feature_all_video_module = xy ]; then
insmod all_video
else
insmod efi_gop
insmod efi_uga
insmod ieee1275_fb
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
fi
set timeout_style=menu
set timeout=5
set timeout=5
source ${prefix}/user.cfg
if [ -n "${GRUB2_PASSWORD}" ]; then
set superusers="root"
export superusers
password_pbkdf2 root ${GRUB2_PASSWORD}
fi
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' b6888a3b-3755-49af-b1db-5b412eda8657
else
search --no-floppy --fs-uuid --set=root b6888a3b-3755-49af-b1db-5b412eda8657
fi
linux16 /vmlinuz-3.10.0-957.el7.x86_64 root=UUID=05bdb265-31b6-4a0f-942b-f69d4b103e8d ro crashkernel=auto rhgb quiet LANG=en_US.UTF-8
initrd16 /initramfs-3.10.0-957.el7.x86_64.img
load_video
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' b6888a3b-3755-49af-b1db-5b412eda8657
else
search --no-floppy --fs-uuid --set=root b6888a3b-3755-49af-b1db-5b412eda8657
fi
linux16 /vmlinuz-0-rescue-55bf685d782642d9bcbb1eaf123db175 root=UUID=05bdb265-31b6-4a0f-942b-f69d4b103e8d ro crashkernel=auto rhgb quiet
initrd16 /initramfs-0-rescue-55bf685d782642d9bcbb1eaf123db175.img
source ${config_directory}/custom.cfg
source $prefix/custom.cfg;
12. identify the "netstat -tan" command followed by the results to the end of any number of white space characters LISTEN line
[root@centos7 ~]#netstat -tan|grep 'LISTEN[[:space:]]\+'
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:6000 0.0.0.0:* LISTEN
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp6 0 0 :::111 :::* LISTEN
tcp6 0 0 :::6000 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
The display name of the user UID within less than all of the 1000 and UID CentOS7
[root@centos7 ~]#cat /etc/passwd |cut -d':' -f1,3 |grep -v '\<[0-9]\{4\}\>'
root:0
bin:1
daemon:2
adm:3
lp:4
sync:5
shutdown:6
halt:7
mail:8
operator:11
games:12
ftp:14
nobody:99
systemd-network:192
dbus:81
polkitd:999
libstoragemgmt:998
colord:997
rpc:32
gluster:996
saslauth:995
abrt:173
rtkit:172
pulse:171
radvd:75
rpcuser:29
nfsnobody:65534
unbound:994
chrony:993
qemu:107
tss:59
usbmuxd:113
geoclue:992
ntp:38
sssd:991
setroubleshoot:990
saned:989
gdm:42
gnome-initial-setup:988
sshd:74
avahi:70
postfix:89
tcpdump:72
[root@centos7 ~]#cat /etc/passwd |cut -d':' -f1,3 |grep '\<[0-9]\{1,3\}\>'
root:0
bin:1
daemon:2
adm:3
lp:4
sync:5
shutdown:6
halt:7
mail:8
operator:11
games:12
ftp:14
nobody:99
systemd-network:192
dbus:81
polkitd:999
libstoragemgmt:998
colord:997
rpc:32
gluster:996
saslauth:995
abrt:173
rtkit:172
pulse:171
radvd:75
rpcuser:29
unbound:994
chrony:993
qemu:107
tss:59
usbmuxd:113
geoclue:992
ntp:38
sssd:991
setroubleshoot:990
saned:989
gdm:42
gnome-initial-setup:988
sshd:74
avahi:70
postfix:89
tcpdump:72
14. Add user bash, testbash, line basher, sh, nologin (which shell is / sbin / nologin), find the / etc / passwd shell of the same name and username
[root@centos7 ~]#grep '\(.*\+\):.*\<\1$' /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
nologin:x:1026:1032::/home/nologin:/sbin/nologin
[root@centos7 ~]#egrep "(.*+):.*\<\1$" /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
nologin:x:1026:1032::/home/nologin:/sbin/nologin
15. The use of df and grep, remove the disk usage of each partition, and descending order
[root@centos7 ~]#df |grep '/dev/sd'|tr -s ' '|cut -d' ' -f5 |sort -nr
17%
5%
1%
[root@centos7 ~]#df |grep '/dev/sd'|grep -o '[0-9]\{0,3\}%' |sort -nr
17%
5%
1%
16. View large version of Linux.
[root@centos7 data]#cat /etc/redhat-release |cut -d. -f1|grep -o '[[:digit:]]'
7
17 shows three users root, mage, wang UID and default shell
[root@centos7 scripts38]#cat /etc/passwd |grep -w '^root\|^wang\|^mage'|cut -d: -f1,3,7
root:0:/bin/bash
wang:1027:/bin/bash
mage:1028:/bin/bash
18. /etc/rc.d/init.d/functions lines in the file to find out first for a word (underscore) followed by a row of small parenthesis
[root@centos7 data]#cat /etc/rc.d/init.d/functions |grep '^[[:alpha:]].*(.*).*'
systemctl_redirect () {
checkpid() {
daemon() {
killproc() {
pidfileofproc() {
pidofproc() {
status() {
echo_success() {
echo_failure() {
echo_passed() {
echo_warning() {
update_boot_stage() {
success() {
failure() {
passed() {
warning() {
action() {
strstr() {
is_ignored_file() {
convert2sec() {
is_true() {
is_false() {
apply_sysctl() {
strstr "$(cat /proc/cmdline)" "rc.debug" && set -x
19. Use egrep removed /etc/rc.d/init.d/functions its name and group name of Contents
目录名
[root@centos7 data]#echo /etc/rc.d/init.d/functions |egrep -o "^[/].*/"
/etc/rc.d/init.d/
20. Statistics last command in each host root logins to log IP addresses
[root@centos7 data]#last |grep 'root' | egrep -o \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}|sort|uniq -c|sort -nr
70 192.168.6.1
1 172.18.37.37
21. The use of extended regular expressions represent 0-9,10-99,100-199,200-249,250-255
[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]
22. ifconfig command shows all IPv4 addresses results
[root@centos7 data]#ifconfig |egrep -o "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"
192.168.6.136
255.255.255.0
192.168.6.255
172.18.7.7
255.255.0.0
172.18.255.255
127.0.0.1
255.0.0.0
192.168.122.1
255.255.255.0
192.168.122.255
23. This string: welcome to magedu linux each character, and to re-sort, many repetitions discharged to the front
[root@centos7 data]#echo welcome to magedu linux |grep -o "."|sort|uniq -c|sort -nr
3 e
3
2 u
2 o
2 m
2 l
1 x
1 w
1 t
1 n
1 i
1 g
1 d
1 c
1 a
24. scripting backup.sh, can achieve the daily / etc / backup directory to / backup / etcYYYY? Mm-dd in
COLOR="\033[1;36m"
COLOREND="\033[0m"
echo -e "${COLOR}Starting backup ...$COLOREND"
cp -av /etc/ /data/etc_backup-`date +%F`
echo -e "${COLOR}Backup is finished$COLOREND"
25. scripting disk.sh, displays the current maximum value in the hard disk partition space utilization
COLOR="\033[1;36m"
COLOREND="\033[0m"
echo -e "${COLOR}Starting Hard Disk Inspection ...$COLOREND"
echo -e "${COLOR}`df|grep "/dev/sd" |tr -s " "|cut -d ' ' -f5|sort -nr|head -1`$COLOREND"
echo -e "${COLOR}Hard Disk Inspection is finished$COLOREND"
26. scripting links.sh, display IPv4 address and the number of connections is connecting each remote host this host and press connections descending order
COLOR="\033[1;36m"
COLOREND="\033[0m"
echo -e "${COLOR}Linsk ...$COLOREND"
echo -e "${COLOR}` netstat -tun|grep ESTAB|tr -s " " : |cut -d: -f6|sort -nr|uniq -c`$COLOREND"
echo -e "${COLOR}Linsk$COLOREND"
27. The generic version of information storage sites
[root@centos7 data]#cat /proc/partitions
硬盘大小存放位置
[root@centos7 data]#cat /proc/meminfo
内存大小存放位置
[root@centos7 data]#cat /proc/cpuinfo
CPU等存放位置
28. The remote execution of scripts.
先开启服务,6上面自带服务
[root@centos6 ~]#service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for centos6.10.localdomain
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
把脚本拷贝到6的主机上
[root@centos7 scripts38]#scp 2systeminfo.sh 192.168.6.129:/var/www/html/
The authenticity of host '192.168.6.129 (192.168.6.129)' can't be established.
RSA key fingerprint is SHA256:7SNWeID7Jr5cvOTZkLQWElsa/MbwymmEUZRhTd8qxJ4.
RSA key fingerprint is MD5:3e:fa:86:dd:c6:b8:41:34:a0:50:f3:f6:b3:17:82:9a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.6.129' (RSA) to the list of known hosts.
[email protected]'s password:
2systeminfo.sh 100% 964 581.7KB/s 00:00
查看是否拷贝到了6的主机上
[root@centos6 ~]#ls /var/www/html/
2systeminfo.sh
在其他主机上执行就可以实现了
[root@centos7 scripts38]#curl 192.168.6.129/2systeminfo.sh |bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 100 964 100 964 0 0 335k 0 --:--:-- --:--:-- --:--:-- 470k
29. The results identify the "ldd / usr / bin / cat" command in the file path
[root@centos7 data]#ldd /usr/bin/cat | grep -o '/[^[:space:]]\+'
/lib64/libc.so.6
/lib64/ld-linux-x86-64.so.2
30. Copy the / etc / profile ⾄ / tmp / of Contents, Using the Find and Replace command to remove white space characters ⾏ therefore especially the / tmp / profile files in
[root@centos7 data]#cp /etc/profile /tmp/
[root@centos7 data]#vim /tmp/profile
:%s/^[[:space:]]\+//g
31. Copy /etc/rc.d/init.d/functions file to the / tmp of Contents, Using the Find and Replace command / tmp / per ⾏ beginning functions as ⾏ perform while the white space character therefore especially Add an # sign
[root@centos7 data]#cp /etc/rc.d/init.d/functions /tmp/
[root@centos7 data]#vim /tmp/functions
:%s/^[[:space:]]/#/g
31. scripting sumid.sh, UID calculate the / etc / passwd file and the second user 10 and user 20
NUM1=` cat /etc/passwd |head -1 |cut -d: -f3`
NUM10=`cat /etc/passwd |head -10 |tail -1|cut -d: -f3`
SUM=$[NUM1+NUM10]
echo "num1 user UUID + num10 user UUID = $SUM"
32. scripting sumspace.sh, passing two file path as a parameter to the script, these two documents is calculated in the sum of all the blank lines
NUM1=` grep '^$' $1 |wc -l`
NUM2=` grep '^$' $2 |wc -l`
SUM=$[NUM1+NUM2]
echo "The sum of blank lines =$SUM"
Scripting sumfile.sh 33., statistics / etc, / var, a number of subdirectories and files in / usr directory Total
ETC=`ls -l /etc/ | wc -l`
VAR=`ls -l /var/ | wc -l`
USR=`ls -l /usr/ | wc -l`
SUM=$[ETC+VAR+USR]
echo "sum=$SUM"
34. scripting argsnum.sh, accepts a file path as a parameter; if the number of parameters is less than 1,
the user is prompted "should at least give a parameter", and exit immediately; if the number of parameters is not less than 1, the first display the number of blank lines in the file pointed to by the argument
[ $# -lt 1 ] && { echo "At least one parameter should be given"; exit 10; }
NUM1=` grep '^$' $1 |wc -l`
echo "The blank lines =$NUM1"
35. scripting hostping.sh, IPv4 address of a host of parameters as whether the test can even
pass. If the ping, the user is prompted to "The IP address to access"; if the ping is not, the user is prompted to "The IP address is inaccessible"
. /data/scripts38/color.sh
read -p "Please enter a correct IP:" IP
# [[ $# -lt 1 ]] && { echo "Please enter a IP"; exit 10; }
[[ "$IP" =~ ^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ ]] || { echo -e "${COLOR} Please enter a IP${COLOREND}" ; exit 20;}
ping -c1 -w2 $IP &> /dev/null && echo -e "${COLOR}该IP地址可访问${COLOREND}" ||echo -e "${COLOR}该IP地址不可访问${COLOREND}"
36. scripting checkdisk.sh, check disk partition space and inode usage, if more than 80%, to send a warning broadcast space will be filled
USE=` df|grep "/dev/sd" |tr -s " " %|cut -d "%" -f5|sort -nr|head -1`
INODE=`df -i|grep "/dev/sd" |tr -s " " %|cut -d "%" -f5|sort -nr|head -1`
test $USE -gt 80 && echo " disk will be full " &&echo disk will be full | mail -s warning root || echo "disk is normal"
[[ "$INODE" -gt 80 ]] && echo " inode will be full " &&echo inode will be full | mail -s warning root || echo "inode is normal"
unset USE INODE
37. scripting per.sh, to determine the current user to specify the parameters file, if unreadable and unwritable
. /data/scripts38/color.sh
#read -p "Please enter a file:" FILE
[[ $# -lt 1 ]] && { echo -e "${COLOR}No input file${COLOREND}" ; exit 10;}
[[ ! -e $@ ]] && { echo -e "${COLOR}file does not exist${COLOREND}" ; exit 20;}
[ ! -r $@ -a ! -w $@ ] && { echo -e "${COLOR}The file is unreadable and not writable${COLOREND}" ;}
[ -r $@ -a ! -w $@ ] && { echo -e "${COLOR}The file is readable and not writable${COLOREND}" ;}
[ -r $@ -a -w $@ ] && { echo -e "${COLOR}The file is readable and writable${COLOREND}" ;}
38. scripting excute.sh, to determine whether the file parameter file for ordinary sh suffix, and if so, add executable permissions to everyone, otherwise the user is prompted non-script file
. /data/scripts38/color.sh
[[ $# -lt 1 ]] && { echo -e "${COLOR}No input file${COLOREND}" ; exit 10;}
[[ ! -e $@ ]] && { echo -e "${COLOR}file does not exist${COLOREND}" ; exit 20;}
[ ! -f $@ ] && { echo -e "${COLOR}Not an ordinary document${COLOREND}" ; exit 30;}
[[ $@ =~ .sh$ ]] && (chmod a+x $@ ; echo -e "${COLOR}$@是一个脚本文件${COLOREND}" ) || { echo -e "${COLOR}User Non-script Files${COLOREND}" ; exit 40;}
39. scripting nologin.sh and login.sh, to achieve a ban and allow ordinary users to log system
. /data/scripts38/color.sh
[ -f /etc/nologin ] && echo -e "${COLOR}Normal users are prohibited from logging in${COLOREND}"|| (touch /etc/nologin ; echo -e "${COLOR}Normal users are prohibited from logging in${COLOREND}")
. /data/scripts38/color.sh
[ -f /etc/nologin ] && (rm -f /etc/nologin ; echo -e "${COLOR}Ordinary users can log in${COLOREND}")||echo -e "${COLOR}Ordinary users can log in${COLOREND}"
40. Age
read -p "Input your age: " AGE
if [[ ! "$AGE" =~ ^[0-9]+$ ]]; then
echo "Please input a digit age"
elif [ $AGE -lt 18 ];then
echo "GOOD good study"
elif [ $AGE -lt 80 ];then
echo "goot goot work"
elif [ $AGE -le 120 ];then
echo "enjoy life"
else
echo "Welcome to the earth"
fi
41. chickens and rabbits with cage, head 37, pin 94
read -p "please input the head number:" HEAD
read -p "please input the foot number:" FOOT
Rabbit=$[FOOT/2-HEAD]
Chook=$[HEAD-Rabbit]
echo "Number of rabbits:" $Rabbit
echo "Number of chook:" $Chook
The ens33 changed eth0
[root@centos7 ~]#sed -ri '/^[[:space:]]+linux16/s#(.*)#\1 net.ifnames=0#' /boot/grub2/grub.cfg
[root@centos7 ~]#sed -ir '/GRUB_CMDLINE_LINUX/s@"$@ net.ifnames=0"@' /etc/default/grub
Close selinux
[root@centos7 data]#sed -i 's/SELINUX=enforcing/SELINUX=disabled/ ' /etc/selinux/config
42.
cat <<EOF
1.不知道想干啥
2.干什么都不容易
3.干点什么不好
4.吃饭饭
5.睡觉觉
6.打豆豆
EOF
read -p "抽奖啦啦,输入一个数字(1-6)):" NUM
case $NUM in
1)
echo "干什么都不如睡觉"
;;
2)
echo "梦里啥都有,要什么自行车"
;;
3)
echo "吃饭,睡觉,打豆豆,一天又一天"
;;
4)
echo "少吃点,该减肥了"
;;
5)
echo "一睡就是一整天"
;;
6)
echo "打什么豆豆"
;;
*)
echo "欢迎来地球"
esac
43. scripting createuser.sh, achieve the following functions: Use one uses one user name as a parameter, if the Use user-specified parameters exists to monitor its presence, or add it; add the displayed user's id number Use and other information
if [ -z "$1" ];then
read -p "please input user:" USER
if
[ -z $USER ] ;then
echo "Password cannot be empty"
exit 10;
else
NAME=$USER
fi
else
NAME=$USER
fi
if id $NAME &> /dev/null ; then
echo "$NAME 账户已经存在"
exit 20
else
useradd $NAME && echo "密码创建成功"
echo magedu | passwd --stdin $NAME &> /dev/null && echo "初始密码为:magedu"
passwd -e $NAME &> /dev/null
echo "userinfo:`id $NAME`"
fi
44. scripting /root/bin/yesorno.sh, Tips Using user input START yes or no, and user input determines Use START is yes or no, or other information
read -p "Do you agree? (yes or no): " ANSWER
case $ANSWER in
[Yy]|[Yy][Ee][sS])
echo YES
;;
[Nn]|[Nn][Oo])
echo NO
;;
*)
echo input false
esac
45. scripting /root/bin/filetype.sh, the user determines Use Entering text path member, which is displayed on the file type (general, of Contents, links to other file type)
read -p "输入一个文件:" A
if [ -z $A ];then
echo "输入不能为空"
exit
elif [ ! -e $A ];then
echo "文件不存在"
exit
elif [ -d $A ];then
echo "这是一个目录"
exit
elif [ -L $A ];then
echo "这是一个链接文件"
exit
elif [ -f $A ];then
echo "这是一个普通文件"
exit
else
echo "other file"
exit
fi
46. scripting /root/bin/checkint.sh, Using the parameters to determine whether the user input START is a positive integer
. /data/scripts38/color.sh
read -t 30 -p "please input a number:" NUM
if [ -z $NUM ] ; then
echo -e "${COLOR}输入不能为空${COLOREND}"
exit 10
elif [[ "$NUM" =~ ^[0-9]+$ ]] ;then
echo "这是一个正整数"
exit 20
else
echo "这不是一个正整数"
exit 30
fi
47. Use for all users of the PATH environment variable values of extra ⼀ paths, for example: / usr / local / apache / bin
echo 'PATH=/usr/local/apache/bin:$PATH' >> /etc/profile.d/env.sh
source /etc/profile.d/env.sh
48. Using the user logged in as root, into a command identifier indicator in red, and automatically activated as Alias:
RM = 'RM -i'
cdnet = 'CD / etc / sysconfig / Network-scripts /'
editnet = ' Vim / etc / sysconfig / Network-scripts / the ifcfg-eth0 '
editnet =' Vim / etc / sysconfig / Network-scripts / or the ifcfg-eno16777736
ifcfg-ens33 '(if the system is CentOS7)
echo "PS1='\[\e[1;31m\][\u@\h \W]\$\[\e[0m\]'" >> /etc/profile.d/env.sh
source /etc/profile.d/env.sh
echo "alias rm='rm –i'" >> ~/.bashrc
echo "alias cdnet='cd /etc/sysconfig/network-scripts/'" >> ~/.bashrc
echo "alias editnet1='vim /etc/sysconfig/network-scripts/ifcfg-eth0'" >> ~/.bashrc
echo "alias editnet2='vim /etc/sysconfig/network-scripts/ifcfg-ens33'" >> ~/.bashrc
source .bashrc
49. Find / var of Contents subordinate to the main root, and all files belong to the group mail.
[root@centos7 data]#find /var/ -user root -group mail
/var/spool/mail
/var/spool/mail/root
50. Find / var of Contents under does not belong to root, lp, gdm of all files.
[root@centos7 data]#find /var/ -not \( -user root -o -user lp -o -user gdm \)
/var/tmp/abrt
/var/lib/colord
/var/lib/colord/icc
51. Find the file currently no owner, or belong to groups on the system, and the recent ⼀ two weeks had been visited.
[root@centos7 data]#find /var -atime -7 -nouser -o -nogroup
52. Find / var ⼀ weeks of Contents under its recently revised content, while the owner is not root, nor is the postfix files.
[root@centos7 data]#find /var -mtime -7 -not \( -user root -o -group postfix \)
/var/log/cups
/var/spool/mail/test
/var/spool/mail/bash
/var/spool/mail/testbash
/var/spool/mail/basher
/var/spool/mail/sh
/var/spool/mail/nologin
/var/spool/mail/wang
/var/spool/mail/mage
/var/spool/mail/lll
/var/spool/mail/aaa
/var/spool/mail/aaaaa
/var/spool/mail/jiaoyu
/var/spool/mail/chen
/var/spool/postfix/active
/var/spool/postfix/incoming
/var/spool/postfix/maildrop
/var/spool/postfix/private
/var/spool/postfix/public
53. Find the / etc of Contents 1M zoomed all files and files of the ordinary type.
[root@centos7 data]#find /etc/ -size +1M -type f
/etc/udev/hwdb.bin
/etc/selinux/targeted/active/policy.kern
/etc/selinux/targeted/contexts/files/file_contexts.bin
/etc/selinux/targeted/policy/policy.31
/etc/brltty/zh-tw.ctb
54. Find / etc of Contents Using all households do not have write access to the file.
[root@centos7 data]#find /etc/ -not -perm /222
/etc/pki/ca-trust/extracted/java/cacerts
/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem
/etc/udev/hwdb.bin
/etc/openldap/certs/password
/etc/gshadow
/etc/shadow
/etc/gshadow-
/etc/ld.so.conf.d/kernel-3.10.0-957.el7.x86_64.conf
/etc/lvm/profile/cache-mq.profile
/etc/lvm/profile/cache-smq.profile
/etc/lvm/profile/command_profile_template.profile
/etc/lvm/profile/lvmdbusd.profile
/etc/lvm/profile/metadata_profile_template.profile
/etc/lvm/profile/thin-generic.profile
/etc/lvm/profile/thin-performance.profile
/etc/dbus-1/system.d/cups.conf
/etc/pam.d/cups
/etc/shadow-
/etc/machine-id
/etc/sudoers
55. Find / etc of Contents under ⾄ rare ⼀ class Using the user does not Perform authority files.
[root@centos7 data]#find /etc/ -not -perm -111
56. Find /etc/init.d of Contents under Using all users have permission to YES, and the other user has write access to the file.
[root@centos7 data]#find /etc/init.d/ -perm -113