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

相关推荐

  • SecureCRT 8.0的安装及Linux基本命令介绍

    在CentOS虚拟中安装并打开图形界面后,可以在图形界面和命令行界面之间任意切换。在打开终端后输入init3可以切换至命令行界面,输入init5返回到图形界面。 这里我们用SecureCRT 8.0来远程的对虚拟机进行操作,对于SecureCRT 8.0的安装步骤就不详细介绍,简单介绍下如何连接到CentOS。 1. 2.点击完成。   &nbsp…

    2017-07-13
  • Liunx课前准备

            经过与家人的沟通终于来到了北京,开始了期待已久的Linux学习之路。    今天是讲课前第一天,和上学时代一样,各位同学做了自我介绍,仿佛又置身于10年前的课堂,同学们有序的介绍着自己,今天我们坐到了一起就为了同一个梦想。之前还有很大的顾虑:学不会怎么办?出来找不到工作怎么办?……但听了大家的介绍后发现很多同学与我一样,所有的顾虑瞬间消失,希…

    2018-03-26
  • Linux文件夹作用

    适用对象:本文适用于初学Linux以及有志于学习Linux的朋友们。   Linux文件系统形状类似于倒置的树状结构,所有的文件或文件夹都可以被认为是根目录/的子目录。 在Linux系统安装完成之后,系统会自动在/目录下创建一些文件,而这些文件都有自己特殊的作用。本文就/下的目录做个简单的介绍。 /bin:存放所有用户使用的二进制可执行命令 /bo…

    Linux干货 2016-10-19
  • Linux的tail 与head 命令

    head命令是用来查看具体文件的前面几行的内容,具体格式如下: head <filename>: 你可以通过head命令查看具体文件最初的几行内容,该命令默认是前10行内容,如果你想查看前面更多内容,你可以通过一个数字选项来设置,例如 head -20 install.log 通过上面命令你可以查看install.log这个文件前面20行的内容 …

    2018-04-16
  • 马哥教育网络班22期+第9周课程练习

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现;            [root@test ~]# vim&nbsp…

    Linux干货 2016-10-24
  • mount命令使用详解

    一、挂载(mount)初识     1.什么是挂载         将额外文件系统与根文件系统某现存的目录建立起关联关系,进而使得此目录作为其它文件访问入口的行为。     2.常用的文件系统类型 &…

    Linux干货 2016-09-01

评论列表(1条)

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

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