马哥教育网络班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

相关推荐

  • grep、vim及用户和组练习

    grep
    chown
    chmod
    vim

    2018-07-23
  • RHCS问题汇总-深圳Eric

    拓补图: 服务器用了4个网卡 两个万兆网卡做了bond连到netgear交换机,交换机端口access 30 对应IP段10.199.16.0/22,网关10.199.16.1做在netgear上 两个千兆网卡做了bond连到cisco 3750交换机,交换机端口truck 30 40 1001-1300 对应IP段10.199.16.0/22、10.176…

    Linux干货 2016-06-22
  • hello! 我的博客第一站

    大家好!  这是我进博客的第一天,一个刚进来的新司机。在这里我就不秀我的车技了,只希望各位老司机开车不要太快,我晕车      —— 生命不息,奋斗不止

    Linux干货 2017-07-11
  • 一张图认识开源世界

    开源精神:自由,创新,团结,互助,友爱,积极,进取。在开源环境下也产生了很多优秀的软件,让我们通过一幅图认识一下开源世界里的大咖们! 看图识物     墙上挂的牛头:伟大的开源计划GNU Wiki:http://zh.wikipedia.org/zh-cn/GNU     墙上日历上的信封标志:经典的linux下的邮件…

    Linux干货 2015-03-20
  • 初学Linux

       已经学习了Linux一周了,从原来的设计网页、动画影视制作、3D模型到现在的黑白界面虚拟世界,从原来吃睡由我到现在重回高三生活,说实话,一开始还是不太能适应的,尤其是眼睛,酸胀痛。不过,越努力越幸运,也觉得linux其实很有意思。。以下是我第一篇微博的内容,也是我学习linux一周所总结的知识。 首先,学习一门知识就要先了解他的历史…

    Linux干货 2017-07-15

评论列表(1条)

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

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