Linux 练习题(2)

3.  请使用命令行展开功能来完成以下练习:
 
   (1). 创建/tmp目录下的:a_c, a_d, b_c, b_d
[root@db146 ~]# mkdir /tmp/{a,b}_{c,d}
[root@db146 ~]# ll /tmp
总用量 0
drwxr-xr-x. 2 root root 6 12月 15 21:35 a_c
drwxr-xr-x. 2 root root 6 12月 15 21:35 a_d
drwxr-xr-x. 2 root root 6 12月 15 21:35 b_c
drwxr-xr-x. 2 root root 6 12月 15 21:35 b_d
[root@db146 ~]# 
 
   (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@db146 mylinux]# 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}}
 
4. 文件的元数据信息有哪些,分别表示什么含义,如何查看?如何修改文件的时间戳信息。
    (1)文件的元数据是指文件的属性、大小、设备、创建时间、访问时间、属主属组等信息。
[root@db146 mylinux]# stat bin
  文件:"bin"
  大小:6             块:0          IO 块:4096   目录
设备:fd00h/64768d    Inode:34355828    硬链接:2
权限:(0755/drwxr-xr-x)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:user_tmp_t:s0
最近访问:2017-12-15 21:52:54.551960700 +0800
最近更改:2017-12-15 21:52:54.551960700 +0800
最近改动:2017-12-15 21:52:54.551960700 +0800
创建时间:-
 
   ( 2)修改文件的时间戳
三个时间戳:访问时间,修改时间,改变时间     
touch:文件时间戳管理工具
 touch [OPTION]... FILE...
-a:accec time:访问时间,atime
-m:modify time:修改时间,mtime
-c:change time:改变时间,ctime:如果文件不存在,则不允许创建
-t:[CC[YY]MMDDhhmm[.ss]
 
[root@db146 mylinux]# touch passwd                                 //将passwd的档案时间修改为当前系统时间
[root@db146 mylinux]# ll|grep passwd 
-rw-r--r--. 1 root root 1258 12月 15 22:24 passwd 
[root@db146 mylinux]# touch -c -t 201611111111.11 passwd      //将passwd的档案时间修改为2016年11月11日11时11分11秒
[root@db146 mylinux]# stat passwd 
  文件:"passwd"
  大小:1258       块:8          IO 块:4096   普通文件
设备:fd00h/64768d Inode:18326919    硬链接:
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:user_tmp_t:s0
最近访问:2016-11-11 11:11:11.000000000 +0800
最近更改:2016-11-11 11:11:11.000000000 +0800
最近改动:2017-12-15 22:35:22.862958894 +0800
创建时间:-
 
5. 如何定义一个命令的别名,如何在命令中引用另一个命令的执行结果?    
使用alias命令
[root@db146 mylinux]# alias lh='ls -lh'
 
使用管道命令
COMMAND1|COMMAND2|COMMAND3|...
[root@db146 mylinux]# cat passwd|wc -l
26
 
6. 显示/var目录下所有以l开头,以一个小写字母结尾,且中间至少出现一位数字(可以有其它字符)的文件或目录。
[root@db146 mylinux]# touch /var/l2323pg
[root@db146 mylinux]# ls -d /var/l*
/var/l2323pg  /var/lib  /var/local  /var/lock  /var/log
[root@db146 mylinux]# ls -d /var/l*[0-9]*[a-z]
/var/l2323pg
 
7. 显示/etc目录下,以任意一个数字开头,且以非数字结尾的文件或目录。
[root@db146 mylinux]# mkdir /etc/211p
[root@db146 mylinux]# ls -d /etc/[[:digit:]]*[^[:digit:]]
/etc/211p
 
8. 显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录。
[root@db146 mylinux]# ls -d /etc/[^[:alpha:]][[:alpha:]]*
 
9. 在/tmp目录下创建以tfile开头,后跟当前日期和时间的文件,文件名形如:tfile-2016-05-27-09-32-22
[root@db146 mylinux]# touch /tmp/tfile-date+"%Y-%m-%d-%H-%M-%S"
[root@db146 mylinux]# ll /tmp |grep tfile*
-rw-r--r--.  1 root root    0 12月 16 01:52 tfile-date+%Y-%m-%d-%H-%M-%S
 
10. 复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中
[root@db146 mylinux]# cp -r /etc/p*[^[:digit:]] /tmp/mytest1
或#cp -r /etc/p*[^0-9]  /tmp/mytest1
[root@db146 mylinux]# ll /tmp/mytest1/
总用量 108 
-rw-r--r--. 1 root root     0 12月 16 02:00 p0ppp
drwxr-xr-x. 2 root root  4096 9月  10 20:00 pam.d
-rw-r--r--. 1 root root  1258 11月 16 20:40 passwd
-rw-r--r--. 1 root root  1217 11月 16 20:40 passwd-
drwxr-xr-x. 2 root root  4096 9月   8 07:08 php.d
-rw-r--r--. 1 root root 64960 9月   8 07:59 php.ini
drwxr-xr-x. 9 root root    91 9月   7 22:13 pki
drwxr-xr-x. 2 root root    27 9月   7 22:13 plymouth
drwxr-xr-x. 5 root root    49 9月   7 22:09 pm
drwxr-xr-x. 2 root root     6 6月  10 2014 popt.d
drwxr-xr-x. 2 root root  4096 9月   7 22:14 postfix
drwxr-xr-x. 3 root root  4096 9月   7 22:13 ppp
drwxr-xr-x. 2 root root    75 9月   7 22:13 prelink.conf.d
-rw-r--r--. 1 root root   233 6月   7 2013 printcap
-rw-r--r--. 1 root root  1750 6月   7 2013 profile
drwxr-xr-x. 2 root root  4096 9月   8 01:00 profile.d
-rw-r--r--. 1 root root  6545 6月   7 2013 protocols
drwxr-xr-x. 2 root root    34 9月   7 22:11 python              
 
11. 复制/etc目录下所有以.d结尾的文件或目录至/tmp/mytest2目录中。
[root@db146 mylinux]# mkdir /tmp/mytest2 && cp -r /etc/*.d /tmp/mytest2
[root@db146 mylinux]# ll /tmp/mytest2/
总用量 24
drwxr-xr-x.  2 root root   48 12月 16 02:13 bash_completion.d
drwxr-xr-x.  2 root root    6 12月 16 02:13 binfmt.d
drwxr-xr-x.  2 root root    6 12月 16 02:13 chkconfig.d
drwxr-xr-x.  2 root root   32 12月 16 02:13 cron.d
drwxr-xr-x.  2 root root   22 12月 16 02:13 depmod.d
drwxr-xr-x.  2 root root    6 12月 16 02:13 dnsmasq.d
 
12. 复制/etc/目录下所有以l或m或n开头,以.conf结尾的文件至/tmp/mytest3目录中。
[root@db146 mylinux]# mkdir /tmp/mytest3 && cp -r  /etc/[1,m,n]*.conf /tmp/mytest3
 
原文地址:https://www.cnblogs.com/kangfeng/p/8047820.html