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

相关推荐

  • Centos系统启动概括流程

    §·Centos系统启动概括流程 系统启动流程: PC (OS Llinux) POST(开机)–>BIOS–>MBR(bootloader .446字节)—>kernel–>/sbin/init(/etc/inittab)(用户空间的管理进程)   备注: POST :加电自…

    Linux干货 2016-09-08
  • 马哥教育网络班21期-第六周课程练习

    请详细总结vim编辑器的使用并完成以下练习题 vim编辑器的使用 vim模式:  a,编辑/命令模式;  b,insert/输入模式  c,末行模式 打开文件:  vim    [option]…    file…  +#:打开文件后,直接让光标…

    Linux干货 2016-08-22
  • 关于文件 atime mtime gtime 专题–2016-07-27

    Linux文件组成部分:元数据(metadata)和数据(date) 元数据的查看方式:使用stat命令; 数据的查看方式:文本格式使用 cat nano查看及修改即可; stat命令: 功能说明:显示文件或文件系统的状态 语法: stat  [OPTION] …  FILE… 参数:   举例: [ro…

    Linux干货 2016-08-04
  • N22-第五周作业

    1、显示当前系统上root、fedora或user1用户的默认shell; [root@localhost ~]# cat /etc/passwd | grep "^root" | cut -d: -f7 /bin/bash 2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello()…

    Linux干货 2016-09-15
  • Nginx 代理和缓存

    一 实验环境 Nginx 版本:nginx-1.8.1 Nginx代理服务器WAN:192.168.1.5 LAN:172.16.2.1 Web1:172.16.2.2 Web2:172.16.2.3 1.  配置好IP、DNS 、网关,确保使用远程连接工具能够连接服务器 2.      …

    Linux干货 2016-12-05
  • 内核空间与用户空间,进程与线程以及上下文

    个人理解,比较啰嗦,逻辑性也不强。如果有疑问可以讨论,或者有大佬提点也是可以的。

    2018-03-30

评论列表(1条)

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

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