Linux 第四天: (07月28日) 练习和作业

Linux 第四天: (07月28日) 练习和作业

 

 

 

 

定义别名命令baketc, 每天将/etc/目录下所有文件, 备份到/testdir独立的子目录下, 并要求子目录格式为backupYYYY-mm-dd, 备份过程可见

alias baketc='cp -a /etc/ /testdir/backup~date +%F~'

 

 

2 创建/testdir/rootdir目录并复制/root所有文件到该目录, 要求保留原有权限

cp -R –preserv=mod /root testdir/rootdir

 

如何创建/testdir/dir1/x,/testdir/dir1/y,
/testdir/dir1/x/a,/testdir/dir1/x/b,
/testdir/dir1/y/a,/testdir/dir1/y/b,

mkdir -p /testdir/dir1/{x,y}/{a,b}

 

如何创建/testdir/dir2/x, /testdir/dir2/y,
/testdir/dir2/x/a,/testdir/dir2/x/b,

mkdir -p /testdir/dir2/{x/{a,b},y}

 

如何创建/testdir/dir3, testdir/dir4, /testdir/dir5,
/testdir/dir5/dir6,/testdir/dir5/dir7,

mkdir -p dir{3,4,5/dir{6,7}}

 

 

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

cat /etc/issue | tr 'a-z' 'A-Z' > /tmp/issue.out

 

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

who | tr [:lower:] [:upper:] > /tmp/who.out

 

3 一个linux用户给root发邮件,标题"help",正文如下:
Hello, I am 用户名, the system version is here, please help me to check it, thanks!
操作系统版本信息
第一种 echo "hello, i am `whoami` or $USER, the system, thanks! \n`lsb_release`" | mail -s "help" root

第二种 mail -s "help" root <<eof
>hello, i am ~whoami~, the system, thanks!
>`lsb_release`
>eof

 

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

第一种 echo $(ls /root -a) > file1

第二种 ls /root -a | tr '\n' ' '

 

5 file文件内容"1 2 3 4 5 6 7 8 9 10" 计算所有数字总和

第一种 echo "1 2 3 4 5 6 7 8 9 10" | tr ' ' '+' |bc

第二种 echo &[echo "1 2 3 4 5 6 7 8 9 10"|tr ' ' '+']

 

6 删除windows文本文件中的'^M'字符

cat a.txt |tr -d '\015'

 

7 处理字符串 "xt.,| 1 jr#!$mn 2c*/fe34z4", 只保留数字和空格

excho 'xt.,| 1 jr#!$mn 2c*/fe34z4' |tr -cd '[:digit:] \n'

 

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

echo $PATH | tr ":" "\n"

 

9 删除文件的空行

cat a.txt | tr -s '\n'

 

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

cat /etc/init.d/dunctions |tr -cs '[:alpha:]' '\n'

 

 

 

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

(0)
上一篇 2016-08-08 09:22
下一篇 2016-08-08 09:22

相关推荐

  • N28-第二周作业

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。 命令:cp、mv、rm 1.1 cp命令 用法: cp [OPTIONS]…[-T] SOURCE DEST cp SRC DEST而言,SRC是文件时 如果目标不存在: 新建DEST,并将SRC中内容填充至DEST中 如果目标存在: 如果DEST是文件:将SRC中的内容覆盖至DE…

    Linux干货 2017-12-15
  • 不重启添加硬盘

    添加硬盘后 ls /dev/sd* 不重启添加硬盘 [root@localhost ~]# cd /sys/class/scsi_host/ [root@localhost scsi_host]# ls host0  host1  host2 [root@localhost scsi_host]# echo “- – -”…

    Linux干货 2017-10-21
  • LAMP及nfs、samba的综合练习

    练习一: 配置第一台主机:服务端共享目录: [root@localhost /]# yum install nfs-utils [root@localhost /]# systemctl start rpcbind [root@localhost /]# sy…

    Linux干货 2016-10-24
  • 第二十一周作业

    1、回顾并详细总结MySQL的存储引擎、索引; 常用存储引擎的对比: 特点 MyISAM InnoDB MEMORY MERGE NDB 存储限制 有 64TB 有 没有 有 事务安全 支持 锁机制 表锁 行锁 表锁 表锁 行锁 B树索引 支持 支持 支持 支持 支持 哈希索引 支持 全文索引 支持 集群索引 支持 数据缓存 支持 支持 支持 索引缓存 支持…

    2017-07-29
  • N22-第十三周作业

    1、建立samba共享,共享目录为/data,要求:(描述完整的过程)  1)共享名为shared,工作组为magedu;  2)添加组develop,添加用户gentoo,centos和ubuntu,其中gentoo和centos以develop为附加组,ubuntu不属于develop组;密码均为用户名;  3)添加samb…

    Linux干货 2016-11-14
  • N21 第二周练习

    ####1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。复制:cp   移动:mv    删除:rm   cp:copy,复制文件或目录</br>  cp [OPTION]… SOURCE… DIRECTORY…

    Linux干货 2016-07-22