马哥教育网络班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 11:33
下一篇 2016-07-04 11:33

相关推荐

  • 第一天课程内容

    一 连接VNC 主机名:172.20.0.100 二 课堂资源下载 ftp://172.16.0.1 三 博客作业     优秀示例 www.yulongjun.com     博客地址 www.178linux.com     作业要求 1.每周一篇或更多,整理当周内容。 2.老师周五发链接地址,提交博客链接。 四 职业发展线路 运维 > Pytho…

    Linux干货 2018-03-26
  • 话说CentOS6的启动流程

    1.按下开机按钮,电脑的主板通电,电脑开始加电自检(POST,Power On and Self Test),测试主机的硬件是否满足开机的要求. 2.加载主板上的BIOS(Base Input/Output System,基本输入输出系统),BIOS会加载用户设定的第一个可开机设备.,这里我们只说硬盘的加载. 可以按下键盘上的Esc或者是F2或者是Del键,…

    Linux干货 2017-05-14
  • xen虚拟化基础篇

    Xen介绍:  xen是一个开放的源代码虚拟机监视器,有剑桥大学研发。它打算在单个计算机上运行多达128个满足特征的操作系统,操作系统必须进行显示地修改("移植")以在Xen上运行(但是提供对用户应用的兼容性)。这使得无需特殊硬件支持,就能达到高性能的虚拟化。 Xen由三部分组成:     第一部分…

    Linux干货 2015-08-26
  • shell编程之循环

           当需要重复运行特定的指令以满足系统管理工作需要时,条件判断语句if、case并不能很好地提供支撑,shell提供了for、while、until循环语句来满足此需求。 一、for循环语句        for循环用于重复整个对象列表,依次遍历对列…

    Linux干货 2016-08-18
  • 脚本编程之循环:for,while,until

    shell中的循环语句一般有: for   while   until 一、for     for 变量名 in 列表;do         循环体     d…

    Linux干货 2016-08-18
  • 文本处理工具

    文本处理小工具 tr tr [选项]…SET1 [SET2] 从标准输入中替换、缩减和/或删除字符,并将结果写到标准输出。 ​ -c:取字符集的补集 ​ -d:删除所有属于第一字符集的字符 ​ -s:把连续重复的字符以单独一个字符表示(压缩) ​ -t:将第一个字符集对应字符转化为第二字符集对应的字符 #echo ‘tank zhang’ |tr a-z A…

    Linux笔记 2018-05-10

评论列表(1条)

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

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