1:如何获取主机IP?
方法一:awk:
[root@server ~]# ifconfig eth0 | grep "inet " | awk '{print $2}'
172.25.254.100
方法二:cut
[root@server ~]# ifconfig eth0 | grep "inet " | cut -d " " -f 10
172.25.254.100
2:检测网络
[root@server ~]# vim ping.sh
ping -c1 -w1 172.25.254.$1 &> /dev/null && echo 172.25.254.$1 is up || echo 172.25.254.$1 is down
[root@server ~]# sh ping.sh 100
172.25.254.100 is up
3:找出/mnt目录中的文件大小最大的:
[root@server mnt]# ll /mnt
total 4
drwx------. 2 root root 23 Dec 22 06:42 ssh-o63BsvHdpEJR
drwx------. 3 root root 16 Dec 22 06:40 systemd-private-Bsnm8D
drwx------. 3 root root 16 Dec 9 07:54 systemd-private-knpjXn
drwx------. 3 root root 16 Dec 9 07:52 systemd-private-LpoUQZ
drwx------. 3 root root 16 Dec 22 06:42 systemd-private-OmwKO5
drwx------. 3 root root 16 Dec 22 06:40 systemd-private-OWrNwD
drwx------. 3 root root 16 Dec 9 07:52 systemd-private-xoctWX
-rw-------. 1 root root 563 Dec 22 06:42 systemd-private-aksNwoX
第一种:
[root@server mnt]# ll /tmp | sort -nk 5 | cut -d " " -f 9 | tail -n 1
systemd-private-aksNwoX
第二种:
[root@server mnt]# ls -Sl /tmp/ | head -2 | cut -d " " -f 9
systemd-private-aksNwoX
4:判断输入的数字是否在10以内
1:输入是否为空
2:是否在10以内
3:0<
a
<
10
−
−
>
y
e
s
4
:
a<10 --> yes 4:
a<10−−>yes4:a<1 $a>10 --> no
#!/bin/bash
[ -z "$1" ] && {
echo "please input a number!"
exit 1
}
[ "$1" -gt "0" -a "$1" -lt "10" ] && {
echo "YES"
}||{
echo "NO"
}
5:判断文件类型
#!/bin/bash
[ -z "$1" ] && {
echo "please enter the file name!"
exit 1
}
[ -e "$1" ] || {
echo "This file does not exist!"
exit 1
}
[ -f "$1" ] && {
echo "The file is a normal file."
}
[ -S "$1" ] && {
echo "The file is a socket."
}
[ -c "$1" ] && {
echo "The file is a character device.0"
}
[ -L "$1" ] && {
echo "The file is a soft link"
}