shell collection exercises

1. Obtain ip or MAC address (not the only method)

[root@cicd ~]# ip a| grep 'inet' | awk -F " +" '{print $3}'| awk -F "/" '{print $1}'
127.0.0.1
::1
192.168.42.30
172.18.0.1
fe80::42:48ff:fef9:c58e
172.17.0.1
fe80::30c5:f7ff:fe76:9ef7
fe80::10ae:aaff:fef9:171e
fe80::4084:8cff:fe08:d03
fe80::a8e2:2bff:fe20:29a

 2. Be sure to copy the contents to a file below, and complete the following requirements:

  (1) count the number of times each URL that appears

  (2) (ascending order) according to the number of occurrences

  (3) removal of the top two ranked number appears URL

[root@cicd ~]# cat test
http://www.baidu.com
http://www.baidu.com
http://www.sina.com
http://www.sina.com
http://www.sina.com
http://www.sina.com
http://www.sina.com
http://www.sina.com
http://www.sina.com
http://www.sina.com
http://www.sina.com
http://www.sina.com
http://www.sina.com
http://www.sina.com
http://www.baidu.com
http://www.baidu.com
http://www.baidu.com
http://www.qq.com
http://www.qq.com
http://www.qq.com
http://www.qq.com
http://www.qq.com
http://www.qq.com
http://www.qq.com
http://www.baidu.com
http://www.baidu.com
http://www.baidu.com
http://www.baidu.com
http://www.baidu.com
http://www.baidu.com
http://www.taobao.com
http://www.taobao.com
http://www.taobao.com
http://www.taobao.com
http://www.taobao.com
http://www.taobao.com
http://www.taobao.com
http://www.taobao.com
http://www.taobao.com
http://www.taobao.com
http://www.baidu.com
http://www.baidu.com
http://www.baidu.com
http://www.baidu.com
http://www.baidu.com
http://www.baidu.com
http://www.baidu.com
test
( 1 ) count the number of times each URL appears 
[CICD the root @ ~] Test CAT # | Cut -d ' / ' - f3 | Sort | the uniq - C
      18 is www.baidu.com
       . 7 www.qq.com
      12 is www.sina .com
      10 www.taobao.com 

( 2 ) is ordered by number appears 
[CICD the root @ ~] Test CAT # | Cut -d ' / ' - f3 | Sort | the uniq -C | Sort - n-
       . 7 www.qq.com
      10 www.taobao.com
      12 is www.sina.com
      18 is www.baidu.com 

( . 3 ) of the top two times URL appears taken 
[CICD the root @~]# cat test | cut -d '/' -f3 | sort |uniq -c | sort -r  -n |head -2
     18 www.baidu.com
     12 www.sina.com
answer

3. Create a root user account and execute test2.sh, to achieve create a shell the Test user and its home directory new file try.html.

#!/bin/bash
useradd shelltest
su - shelltest
cd /home && touch try.html
View Code

4. The current system statistics total number of users

#!/bin/bash
who | wc -l
View Code

5. count the number of software currently installed

#!/bin/bash
rpm -qa | wc -l
View Code

 

Guess you like

Origin www.cnblogs.com/daisyyang/p/11068990.html