#date 080706052019.10
练习二
1、在本机字符终端登录时,除显示原有信息外,再显示当前登录终端号,主机名和当前时间
vim /etc/issue
\b : Insert the baudrate of the current line.
\d : Insert the current date.
\s : Insert the system name, the name of the operating system.
\l : Insert the name of the current tty line.
\m : Insert the architecture identifier of the machine, eg. i486
\n : Insert the nodename of the machine, also known as the hostname.
\o : Insert the domainname of the machine.
\r : Insert the release number of the OS, eg. 1.1.9.
\t : Insert the current time.
\u : Insert the number of current users logged in.
\U : Insert the string "1 user" or " users" where is the number of current users logged in.
\v : Insert the version of the OS, eg. the build-date etc.
2、今天18:30自动关机,并提示用户
shutdown [OPTION]... TIME [MESSAGE]
#shutdown 18:30 please logoff before that time.
#shutdown -h 18:30 "dao dian guan ji,18:30"
(1) 如何创建?
/data/dir1/x,
/data/dir1/y,
/data/dir1/x/a,
/data/dir1/x/b,
/data/dir1/y/a,
/data/dir1/y/b
#mkdir /data/dir1/{x,y}/{a,b} -pv
#rm -rf dir1/
[root@centos7 data]#tree /data/
/data/
-- dir1|-- x| |-- a|-- b
-- y|-- a-- b
7 directories, 0 files
(2) 如何创建?
/data/dir2/x,
/data/dir2/y,
/data/dir2/x/a,
/data/dir2/x/b
n1=`head -10 /etc/passwd| tail -1 |cut -d: -f3`
n2=`head -20 /etc/passwd| tail -1 |cut -d: -f3`
echo "The 10th user id is $n1."
echo "The 20th user id is $n2."
let total=n1+n2
echo "The 10th user id and the 20th user is $total."
2、编写脚本/root/bin/sumspace.sh,传递两个文件路径作为参数给脚本,计算这两个文件中所有空白行之和
#!/bin/bash
n1=`grep "^$" $1 |wc -l`
n2=`grep "^$" $2 |wc -l`
echo "The first file with total blank line is $n1."
echo "The second file with total blank line is $n2."
let total=n1+n2
echo "$1 and $2 has total blank lines are $total."
3、编写脚本/root/bin/sumfile.sh,统计/etc, /var, /usr目录中共有多少个一级子目录和文件
#!/bin/bash
d1=`ls -l -d /etc/* |grep "^d" |wc -l`
d2=`ls -l -d /var/* |grep "^d" |wc -l`
d3=`ls -l -d /usr/* |grep "^d" |wc -l`
echo "/etc has dir $d1."
echo "/var has dir $d2."
echo "/usr has dir $d3."
let dtotal=d1+d2+d3
echo "Total dir is $dtotal."
f1=`ls -l -d /etc/* |grep "-" |wc -l`
f2=`ls -l -d /var/* |grep "-" |wc -l`
f3=`ls -l -d /usr/* |grep "-" |wc -l`
echo "/etc has file $f1."
echo "/var has file $f2."
echo "/usr has file $f3."
let ftotal=f1+f2+f3
echo "Total file is $ftotal."