马哥教育网络班21期-第二周课程练习

1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。

mv    #移动或重命名文件
[root@server0 tmp]# mv 1.txt 2.txt    #重命名1.txt 为2.txt
[root@server0 tmp]# mv 1.txt /var/tmp/    #移动文件到/var/tmp/下
rm    #删除
[root@server0 tmp]# rm 2.txt 
rm: remove regular empty file ‘2.txt’? y
cp    #复制
[root@server0 tmp]# cp /var/tmp/1.txt .    #复制文件到当前目录

2、bash的工作特性之命令执行状态返回值和命令行展开所涉及的内容及其示例演示。

状态返回值
[root@server0 tmp]# echo hello
hello
[root@server0 tmp]# echo $?    #打印上一次命令执行状态返回值,0表示命令执行成功
0
命令行展开
[root@server0 tmp]# touch {1..3}.txt
[root@server0 tmp]# ls *.txt
1.txt  2.txt  3.txt

3、请使用命令行展开功能来完成以下练习:

   (1)、创建/tmp目录下的:a_c, a_d, b_c, b_d

[root@server0 tmp]# touch a_{c,d} b_{c,d}

   (2)、创建/tmp/mylinux目录下的:

mylinux/

    ├── bin

    ├── boot

    │   └── grub

    ├── dev

    ├── etc

    │   ├── rc.d

    │   │   └── init.d

    │   └── sysconfig

    │       └── network-scripts

    ├── lib

    │   └── modules

    ├── lib64

    ├── proc

    ├── sbin

    ├── sys

    ├── tmp

    ├── usr

    │   └── local

    │       ├── bin

    │       └── sbin

    └── var

        ├── lock

        ├── log

        └── run

[root@server0 tmp]# mkdir -p /tmp/mylinux/{bin,boot/grub,dev,etc/{rc.d/init.d,sysconfig/network-scripts},lib/modules,lib64,proc,sbin,sys,tmp,usr/local/{bin,sbin},var/{lock,log,run}}
[root@server0 tmp]# tree mylinux/
mylinux/
├── bin
├── boot
│   └── grub
├── dev
├── etc
│   ├── rc.d
│   │   └── init.d
│   └── sysconfig
│       └── network-scripts
├── lib
│   └── modules
├── lib64
├── proc
├── sbin
├── sys
├── tmp
├── usr
│   └── local
│       ├── bin
│       └── sbin
└── var
    ├── lock
    ├── log
    └── run

4、文件的元数据信息有哪些,分别表示什么含义,如何查看?如何修改文件的时间戳信息。

使用 stat 命令查看
[root@server0 tmp]# stat 1.txt 
  File: ‘1.txt’
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fd01h/64769d	Inode: 51938148    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2016-07-02 16:43:34.050729173 +0800
Modify: 2016-07-02 16:43:34.050729173 +0800
Change: 2016-07-02 16:43:34.050729173 +0800
 Birth: -
使用 touch 命令修改
[root@server0 tmp]# touch -a 1.txt 
[root@server0 tmp]# stat 1.txt 
  File: ‘1.txt’
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fd01h/64769d	Inode: 51938148    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2016-07-02 17:00:18.370666026 +0800
Modify: 2016-07-02 16:43:34.050729173 +0800
Change: 2016-07-02 17:00:18.370666026 +0800
 Birth: -

5、如何定义一个命令的别名,如何在命令中引用另一个命令的执行结果?

使用 alias 定义命令别名 
[root@server0 tmp]# alias a="ls *.txt"
[root@server0 tmp]# a
1.txt  2.txt  3.txt
使用反引号引用
[root@server0 tmp]# echo "welcome to `echo linux`"
welcome to linux

6、显示/var目录下所有以l开头,以一个小写字母结尾,且中间至少出现一位数字(可以有其它字符)的文件或目录。

[root@server0 var]# ls l*[[:digit:]]*[[:lower:]]

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

[root@server0 tmp]# ls /etc/[0-9]*[^0-9]

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

[root@server0 tmp]# ll /etc/[^[:alpha:]][[:alpha:]]*

9、在/tmp目录下创建以tfile开头,后跟当前日期和时间的文件,文件名形如:tfile-2016-05-27-09-32-22。

[root@server0 tmp]# touch tfile-`date +%F-%H-%M-%S`

10、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。

[root@server0 tmp]# cp /etc/p*[^[:digit:]] /tmp/mytest1

11、复制/etc目录下所有以.d结尾的文件或目录至/tmp/mytest2目录中。

[root@server0 tmp]# cp /etc/*.d /tmp/mytest2/

12、复制/etc/目录下所有以l或m或n开头,以.conf结尾的文件至/tmp/mytest3目录中。

[root@server0 tmp]# cp /etc/{l,m,n}*.conf /tmp/mytest3/

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

(0)
Net21_木头Net21_木头
上一篇 2016-07-04
下一篇 2016-07-04

相关推荐

  • Shell 编 程 之 until循 环 语 句-20160817

    Shell 编 程 之 until循 环 语 句 §·练习题: 1 每隔3秒钟到系统上获取已经登录的用户的信息;如果发现用户hacker登录,则将登录时间和主机记录于日志/var/log/login.log中,并提示该用户退出系统? 解:解题思路:按照题意该脚本一直无限循环,一直探测用户h…

    Linux干货 2016-08-22
  • 浅谈Linux终端类型

    Linux终端类型 作者:任飞鹏            日期:2016-10-13 终端是什么: 终端(Terminal)也称终端设备,是计算机网络中处于网络最外围的设备,主要用于用户信息的输入以及处理结果的输出等。 早期计算机系统中,由于计算机主机…

    Linux干货 2016-10-19
  • shell编程中的三种流程控制

    流程控制 v 一 、过程式编程语言: 1.顺序执行 2.选择执行 3.循环执行  条件选择if 语句   选择执行:   注意: :if 语句可 嵌套    单分支 if 判断条件;then 条件为真的分支代码 fi    双分支 if 判断条件; then …

    Linux干货 2016-08-21
  • 在马哥学习linux第一天的感受

         来马哥教育好几天了,昨天算是正式开始,在昨天早上,举行了开班典礼,各位老师助教为我们介绍了在马哥教育进行培训的相关注意事项,下午进行了两场测试,首先有一个摸底测试,不得不说我真的是太菜了,除了一些比较简单的题目我还有些把握,相当一部分我都是似曾相识,但是也不是很确定,还有很大一部分我根本听都没听说过,看到别人都写的满满…

    Linux干货 2017-07-11
  • IP路由

    IP路由

    2018-05-22
  • keepalived的安装和配置

    一、简介 Keepalived是一个免费开源的,用C编写的类似于layer3, 4 & 7交换机制软件,具备我们平时说的第3层、第4层和第7层交换机的功能。主要提供loadbalancing(负载均衡)和 high-availability(高可用)功能,负载均衡实现需要依赖Linux的虚拟服务内核模块(ipvs),而高可用是通过VRRP协议实现多台…

    Linux干货 2017-10-30

评论列表(1条)

  • 马哥教育
    马哥教育 2016-07-04 13:53

    写的很好,有的题目答的不是很全啊,加油