M20 – 1- 第二周(2):课堂练习与作业

课堂练习:

1、显示/var目录下所有以l开头,以一个小写字母结尾,且中间出现至少一位数字的文件和目录

[root@centos6 ~]# ls /var/l*[[:digit:]]*[[:lower:]]
ls: cannot access /var/l*[[:digit:]]*[[:lower:]]: No such file or directory
[root@centos6 ~]# touch /var/l5x
[root@centos6 ~]# ls /var/l*[[:digit:]]*[[:lower:]]
/var/l5x

2、显示/etc目录下以任意一位数字开头,且以非数字结尾的文件或目录

[root@centos6 ~]# ls /etc/[[:digit:]]*[^[:digit:]]
ls: cannot access /etc/[[:digit:]]*[^[:digit:]]: No such file or directory
[root@centos6 ~]# touch /etc/7abc
[root@centos6 ~]# ls /etc/[[:digit:]]*[^[:digit:]]
/etc/7abc

3、显示/etc目录下以非字母开头,后面跟了一个字母及其它任意长度任意字符的文件和目录

[root@centos6 ~]# ls -d /etc/[^[:alpha:]][[:alpha:]]*
/etc/7abc

4、显示/etc目录下所有以m开头以非数字结尾的文件或目录

[root@centos6 ~]# ls -d /etc/m*[^0-9]
/etc/magic    /etc/mail.rc    /etc/man.config  /etc/mime.types   /etc/modprobe.d  /etc/mtab         /etc/my.cnf
/etc/mailcap  /etc/makedev.d  /etc/maven       /etc/mke2fs.conf  /etc/motd        /etc/mtools.conf

5、显示/etc目录下,所有以.d结尾的文件或目录

[root@centos6 ~]# ls -d /etc/*.d
/etc/bash_completion.d  /etc/init.d         /etc/modprobe.d      /etc/rc0.d  /etc/rc6.d          /etc/setuptool.d
/etc/chkconfig.d        /etc/latrace.d      /etc/oddjobd.conf.d  /etc/rc1.d  /etc/rc.d           /etc/statetab.d
/etc/cron.d             /etc/ld.so.conf.d   /etc/pam.d           /etc/rc2.d  /etc/request-key.d  /etc/sudoers.d
/etc/depmod.d           /etc/logrotate.d    /etc/popt.d          /etc/rc3.d  /etc/rsyslog.d      /etc/sysctl.d
/etc/dnsmasq.d          /etc/lsb-release.d  /etc/prelink.conf.d  /etc/rc4.d  /etc/rwtab.d        /etc/xinetd.d
/etc/dracut.conf.d      /etc/makedev.d      /etc/profile.d       /etc/rc5.d  /etc/sane.d         /etc/yum.repos.d

6、显示/etc目录下,所有以.conf结尾,且以m,n,r,p开头的文件或目录

[root@centos6 ~]# ls -d /etc/[mnrp]*.conf
/etc/mke2fs.conf    /etc/nsswitch.conf  /etc/pm-utils-hd-apm-restore.conf  /etc/readahead.conf    /etc/rsyslog.conf
/etc/mtools.conf    /etc/ntp.conf       /etc/pnm2ppa.conf                  /etc/request-key.conf
/etc/nfsmount.conf  /etc/pbm2ppa.conf   /etc/prelink.conf                  /etc/resolv.conf

作业:

1、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中

[root@centos6 ~]# cat /etc/issue | tr 'a-z' 'A-Z' > /tmp/issue.out
[root@centos6 ~]# cat !$
cat /tmp/issue.out
CENTOS RELEASE 6.8 (FINAL)
KERNEL \R ON AN \M
TTY IS \L
DATE IS \D
HOSTNAME IS \N

2、将当前系统登录用户的信息转换为大写后保存至/tmp/who.out文件中

[root@centos6 ~]# who | tr 'a-z' 'A-Z' > /tmp/who.out
[root@centos6 ~]# cat !$
cat /tmp/who.out
ROOT     PTS/0        2016-07-30 19:26 (172.18.19.236)

3、一个linux用户给root发邮件,要求邮件标题为“help”,邮件正文如下:

Hello,I am 用户名,the system version is here,pleasehelp me to check it,thanks!

[root@centos6 ~]# mail -s help wang
Hello, I am wang, the system version is here, pleasehelp me to check it, thanks!
.
EOT
[root@centos6 ~]# su - wang
[wang@centos6 ~]$ mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/wang": 2 messages 2 new
>N  1 root                  Sat Jul 30 20:59  18/662   "help"
 N  2 root                  Sat Jul 30 20:59  18/662   "help"
& 1
Message  1:
From root@centos6.localdomain  Sat Jul 30 20:59:41 2016
Return-Path: <root@centos6.localdomain>
X-Original-To: wang
Delivered-To: wang@centos6.localdomain
Date: Sat, 30 Jul 2016 20:59:41 +0800
To: wang@centos6.localdomain
Subject: help
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: root@centos6.localdomain (root)
Status: R

Hello, I am wang, the system version is here, pleasehelp me to check it, thanks!

&

4、将/root/下文件列表,显示成一行,并以文件名之间用空格隔开

[root@centos6 ~]# ls -a | tr '\n' ' '
. .. .abrt anaconda-ks.cfg .bash_history .bash_logout .bash_profile .bashrc bc .cache .config .cshrc .dbus dead.letter 
Desktop Documents Downloads edrawmax-cn.exe .esd_auth file1 .gconf .gconfd .gnome2 .gnote .gnupg .gtk-bookmarks .gvfs .ICEauthority .imsettings.log install.log install.log.syslog .local Music .nautilus Pictures Public .pulse .pulse-cookie root.out .ssh .tcshrc Templates tr Videos .viminfo [root@centos6 ~]#

5、file文件的内容为:“1 2 3 4 5 6 7 8 9 10” 计算出所有数字的总和

[root@centos6 ~]# cat file1 
1 2 3 4 5 6 7 8 9 10
[root@centos6 ~]# cat file1 |xargs|sed 's/ /+/g'|bc
55
[root@centos6 ~]# cat file1
1 2 3 4 5 6 7 8 9 10
[root@centos6 ~]# cat file1|tr ' ' '+' |bc
55

6、删除Windows文本文件中的"^M"字符

[root@centos6 ~]# cat -A file4.txt 
a^M$
b^M$
c^M$
d^M$
f^M$
g[root@centos6 ~]# tr -d '\r' <  file4.txt > file5.txt
[root@centos6 ~]# cat -A file5.txt 
a$
b$
c$
d$
f$
g[root@centos6 ~]#

7、处理字符串“xt.,1 1 jr#!$mn2 c*/fe3 uz4 ”,只保留其中的数字和空格

[root@centos6 ~]# echo "xt.,1 1 jr#bcmn2 c*/fe3 uz4" | tr -d '[[:alpha:]][[:punct:]]'
1 1 2 3 4

8、将PATH变量每个目录显示在独立的一行

[root@centos6 ~]# echo $PATH |tr ':' '\012'
/usr/lib64/qt-3.3/bin
/usr/local/sbin
/usr/local/bin
/sbin
/bin
/usr/sbin
/usr/bin
/root/bin

9、删除指定文件的空行

[root@centos6 ~]# cat file2
a

b

c
         
[root@centos6 ~]# sed -i '/^$/d' file2
[root@centos6 ~]# cat file2
a
b
c

10、将文件中每个单词(字母)显示在独立的一行,并无空行

[root@centos6 ~]# cat file6
how are you! how old are you!
[root@centos6 ~]# cat file6 |tr ' ' '\n'
how
are
you!
how
old
are
you!

原创文章,作者:Aleen,如若转载,请注明出处:http://www.178linux.com/26882

(0)
上一篇 2016-08-02 10:58
下一篇 2016-08-02 10:58

相关推荐

  • LVS_DR配置

    DR : 192.168.29.150 VIP:192.168.29.100 RS1: 192.168.29.110 VIP:192.168.29.100 RS2:192.168.29.120 VIP:192.168.29.100 RS 配置 1 配置VIP [root@local ~]# ifconfig lo:0 192.168.29.100 netma…

    2017-06-30
  • N26第二周博客作业

    1、  Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。 常见的文件查看命令有:cat,tac,head,tail,more,less,stat,touch 常见的文件管理命令有:cp,mv,rm 常见的目录管理命令:mkdir,rmdir 以下进行详细介绍: 1.1  文件查看命令 l  ca…

    Linux干货 2017-02-03
  • 重定向、管道——Linux基本命令(9)

    1.     输出重定向 Linux默认输入是键盘,输出是显示器。可以用重定向来改变这些设置。比如用wc命令的时候本来是要手动输入一篇文字来计算字符数的,可以直接把一个已经写好的文件用‘<’指向这条命令,就直接可以统计这个文件的字符数等了。   STDOUT(标准输出)和STDERR(标准错误)可以被重…

    2017-07-20
  • 第一周作业

    一、计算机的组成及其功能。 计算机是由运算器、控制器、存储器、输入设备、输出设备五大部件组成,每一个部分分别按照要求执行特定的基本功能。 运算器:运算器的主要功能是对数据进行各种运算。 控制器:控制器是整个计算机系统的控制中心,它指挥计算机各部分协调地工作,保证计算机按照预先规定的目标和步骤有条不紊的进行操作及处理。 存储器:存储器的主要功能是存储程序和各种…

    Linux干货 2017-01-18
  • 逻辑卷管理器LVM

    一、LVM逻辑卷管理     lvm(Logical Volume Manage,逻辑卷管理)的重点在于可以弹性的调整filesystem的容量,而并非在于数据的存储效率及安全上面。需要文件的读写效能或者是数据的可靠性是RAID所考虑的问题。LVM可以整合多个实体partition在一起,让这些partitions看起…

    Linux干货 2016-09-02
  • LVS NAT模型演示

    LVS NAT模型演示 这里我们刻意将两个RS的web页面文件,提供为不同的内容(实际应用中,每个RS页面的内容要完全相同) 基本配置 [root@web1 ~]# route add default gw 192.168.110.130  –> web1服务器…

    2016-10-29