730作業

1、將/etc/issue文件中的內容轉換為大寫后保存至/tmp/issue.out文件中

[root@local ~]# cat /etc/issue |tr "[[:lower:]]" "[[:upper:]]" > /tmp/issue.out
[root@local ~]# cat /tmp/issue.out 
CENTOS RELEASE 6.8 (FINAL)
KERNEL \R ON AN \M

2、將當前系統登錄用戶的信息轉換為大寫后保存至/tmp/who.out文件中

[root@local ~]# finger $(whoami) | tr "[[:lower:]]" "[[:upper:]]" > /tmp/who.out
[root@local ~]# cat /tmp/who.out 
LOGIN: ROOT                     NAME: ROOT
DIRECTORY: /ROOT                        SHELL: /BIN/BASH
ON SINCE FRI JUL 29 23:41 (EDT) ON TTY1    6 HOURS 55 MINUTES IDLE
ON SINCE SAT JUL 30 05:55 (EDT) ON PTS/1 FROM 10.1.24.1
NO MAIL.
NO PLAN.

3、一個linux用戶給root發郵件,要求郵件標題為”help”,郵件正文如下: Hello, I am 用戶名,the system version is here,pleasehelp me to check it ,thanks! 操作系統版本信息

[root@local ~]# echo "Hello, I am $(whoami),the system version is here,pleasehelp me to check it ,thanks   $(cat /etc/issue)"  |mail -s "help"  gentoo
[root@local ~]# su - gentoo
[gentoo@local ~]$ mail 
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/gentoo": 2 messages 1 new
    1 root                  Sat Jul 30 05:58  20/670   "help"
>N  2 root                  Sat Jul 30 06:43  19/659   "help"
& 2  
Message  2:
From root@local.linux  Sat Jul 30 06:43:54 2016
Return-Path: <root@local.linux>
X-Original-To: gentoo
Delivered-To: gentoo@local.linux
Date: Sat, 30 Jul 2016 06:43:53 -0400
To: gentoo@local.linux
Subject: help
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: root@local.linux (root)
Status: R

Hello, I am root,the system version is here,pleasehelp me to check it ,thanks   CentOS release 6.8 (Final)
Kernel \r on an \m

4、將/root/下文件列表,顯示成一行,并文件名之間用空格隔開

[root@local ~]# ls / >1.txt
[root@local ~]# tr '\n' ' ' <1.txt 
bin boot dev etc home lib lib64 lost+found media mnt opt proc root sbin selinux srv sys test.txt test.txt~ tmp usr var

5、file1文件的內容為:”1 2 3 4 5 6 7 8 9 10” 計算出所有數字的總和

[root@local ~]# echo "1 2 3 4 5 6 7 8 9 10"  | xargs | sed -r "s# #+#g" | bc
55


[root@local ~]# echo "1 2 3 4 5 6 7 8 9 10" > 1.txt
[root@local ~]# tr " " "+" <  1.txt |bc
55

6、刪除Windows文本文件中的'^M'字符 
首先在windows操作系統下任意創建一個txt文本文件,在里面任意輸入一些字符 
然后通過xftp 將txt文本文件導入Linux系統。

    [root@local ~]# cat -A test.txt 
    123123dsa ^M$
    dasd^M$
    d^M$
    asd^M$
    as sa^M$
     ^M$
    dasdasda
    [root@local ~]# tr -d "^M" <test.txt 
    123123dsa 
    dasd
    d
    asd
    as sa

    dasdasda

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

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

8、將PATH變量每個目錄顯示在獨立的一行

    [root@local ~]# echo $PATH
    /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
    [root@local ~]# echo $PATH | tr ":" "\n"
    /usr/local/sbin
    /usr/local/bin
    /sbin
    /bin
    /usr/sbin
    /usr/bin
    /root/bin

9、刪除指定文件的空行

[root@local ~]# cat > 123.txt << END
> 1231231
> 
> 
> dasd
> dsadx
> dcxc
> 
> 
> dsa
> x
> dsa
> 
> 
> 
> ..
> !@#!
> 
> 
> 12312
> END
[root@local ~]# cat -A 1
123.txt  1.txt    
[root@local ~]# cat -A 123.txt 
1231231$
$
$
dasd$
dsadx$
dcxc$
$
$
dsa$
x$
dsa$
$
$
$
..$
!@#!$
$
$
12312$
[root@local ~]# tr -d "\n" < 123.txt 
1231231
dasd
dsadx
dcxc
dsa
x
dsa
..
!@#!
1231

10、將文件中每個單詞(字母)顯示在獨立的一行,并無空行

    [root@local ~]# cat /etc/issue | tr ' ' '\n' | tr -s '\n'
    CentOS
    release
    6.8
    (Final)
    Kernel
    \r
    on
    an
    \m

原創文章,作者:fighter,如若轉載,請注明出處:http://www.www58058.com/27001

(0)
fighterfighter
上一篇 2016-08-02
下一篇 2016-08-02

相關推薦

  • Sqlserver2012(主從復制)共享同步日志備份恢復

    SQL Server 2012相對于SQL Server 2008來說,無論是性能還是功能都有一個相當大的提高,甚至可以用“革命”來形容這一次升級。SQL Server 2012使 SQL Server 躋身于企業級數據庫行列。在數據高可用性方面,SQL Se…

    Linux干貨 2015-10-31
  • M20-1 8月5日 文本查看工具以及文本處理工

    一、文本查看工具:  cat,tac,rev cat用法:cat [option]..[FILE]..   cat選項:    -E:顯示行結束符$    -n:對顯示出的每一行進行編號    -A:顯示所有控制符    -b:非空行編號   &nb…

    Linux干貨 2016-08-08
  • 馬哥教育網絡班21期-第六周課程練習

    請詳細總結vim編輯器的使用并完成以下練習題 1、復制/etc/rc.d/rc.sysinit文件至/tmp目錄,將/tmp/rc.sysinit文件中的以至少一個空白字符開頭的行的行首加#; 2、復制/boot/grub/grub.conf至/tmp目錄中,刪除/tmp/grub.conf文件中的行首的空白字符; 3、刪除/tmp/rc.sysinit文件…

    Linux干貨 2016-08-05
  • find可以這么用

    在工作中不可或缺的工具find:查找系統中的各種文件,對查找的文件進行操作,這就是find的作用。進入正題: 1、查找下系統中有一下系統中有幾個文件叫issue的     [root@localhost private]#find / -name issue      …

    Linux干貨 2017-03-05
  • select與case組合循環

    select與case: 格式: select variable in list do 循環體命令 done 例1:     #!/bin/bash PS3="what do you want: " select i in a b c d         #在例2中省略…

    Linux干貨 2016-08-22
  • 馬哥教育21期網絡班—第12周課程+練習—-LAMP練習中

    為第4題中的第2個虛擬主機提供https服務,使得用戶可以通過https安全的訪問此web站點; (1)要求使用證書認證,證書中要求使用的國家(CN)、州(HA)、城市(ZZ)和組織(MageEdu); (2)設置部門為Ops,主機名為www2.stuX.com,郵件為admin@stuX.com; [ root@centos CA]# …

    Linux干貨 2016-09-26
欧美性久久久久