magedu-第二周作业
1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。
- cd
用户目录切换(进入目录),如下 进入a的目录
[root@centos_1 liao]# mkdir a [root@centos_1 liao]# ll total 4 drwxr-xr-x 2 root root 6 Oct 13 21:13 a -rwxr-xr-x. 1 root root 38 Aug 23 22:18 liao.sh [root@centos_1 liao]# cd a [root@centos_1 a]# ll total 0 [root@centos_1 a]#
- pwd
显示当前路径,如下
[root@centos_1 a]# pwd /liao/a [root@centos_1 a]#
- ls
显示目录下文件及文件夹信息,默认为当前路径
[root@centos_1 liao]# ls a liao.sh [root@centos_1 liao]#
- cat
用于打开文件中内容
[root@centos_1 liao]# cat liao.sh $!/bin/bash set -x echo "test hahaha" [root@centos_1 liao]#
- mkdir
用于创建目录
[root@centos_1 liao]# mkdir b [root@centos_1 liao]# ll total 4 drwxr-xr-x 2 root root 6 Oct 13 21:13 a drwxr-xr-x 2 root root 6 Oct 13 21:20 b -rwxr-xr-x. 1 root root 38 Aug 23 22:18 liao.sh [root@centos_1 liao]#
- more
全屏的方式按页显示文件内容,按Enter(向下翻滚一行),空格(向下滚动一屏),Q(退出命令)。
[root@centos_1 b]# more test.txt this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test --More--(43%)
- rm
删除某一文件及文件夹
[root@centos_1 b]# rm test.txt rm: remove regular file ‘test.txt’? y [root@centos_1 b]# ll total 0 [root@centos_1 b]# ================== [root@centos_1 liao]# ll total 4 drwxr-xr-x 2 root root 6 Oct 13 21:13 a drwxr-xr-x 2 root root 6 Oct 13 21:25 b -rwxr-xr-x. 1 root root 38 Aug 23 22:18 liao.sh [root@centos_1 liao]# rm -rf b [root@centos_1 liao]# ll total 4 drwxr-xr-x 2 root root 6 Oct 13 21:13 a -rwxr-xr-x. 1 root root 38 Aug 23 22:18 liao.sh [root@centos_1 liao]#
2、使用命令行展开功能,创建/tmp/a1, /tmp/a2, /tmp/a1/a, /tmp/a1/b,在/tmp目录下创建目录:x_y, x_z, q_y, q_z
- 创建/tmp/a1, /tmp/a2, /tmp/a1/a, /tmp/a1/b
[root@centos_1 liao]# ll
total 0
[root@centos_1 liao]# mkdir -p a{1/{a,b},2}
[root@centos_1 liao]# tree
.
├── a1
│ ├── a
│ └── b
└── a2
4 directories, 0 files
[root@centos_1 liao]#
- /tmp目录下创建目录:x_y, x_z, q_y, q_z
[root@centos_1 liao]# mkdir {x,q}_{y,z}
[root@centos_1 liao]# ll
total 0
drwxr-xr-x 4 root root 24 Oct 13 21:30 a1
drwxr-xr-x 2 root root 6 Oct 13 21:30 a2
drwxr-xr-x 2 root root 6 Oct 13 21:35 q_y
drwxr-xr-x 2 root root 6 Oct 13 21:35 q_z
drwxr-xr-x 2 root root 6 Oct 13 21:35 x_y
drwxr-xr-x 2 root root 6 Oct 13 21:35 x_z
[root@centos_1 liao]#
3、文件的元数据信息有哪些,分别表示什么含义,如何查看?如何修改文件的时间戳信息。
- 元数据信息,如下
File:文件名称;
Size:文件大小;
Blocks:占用的磁盘块数;
IO Block:IO块大小;
regular file:这里是显示文件的类型,这是一个普通文件
Device:所在设备;
Inode:Inode节点号;
Links:被链接的次数;
Access(第一个):访问权限;
Uid:uid号和属主;
Gid:gid号和属组;
Access(第二个):文件最近一次的访问时间;
Modify:文件的修改时间;
Chang:文件的改变时间。
[root@centos_1 liao]# touch a.txt [root@centos_1 liao]# stat a.txt File: ‘a.txt’ Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 33619903 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2019-10-13 21:37:35.156320422 +0800 Modify: 2019-10-13 21:37:35.156320422 +0800 Change: 2019-10-13 21:37:35.156320422 +0800 Birth: - [root@centos_1 liao]#
- 使用stat命令查看,如上
- 修改时间戳信息
使用touch -a将Access和Change修改为当前系统时间,修改文件里内容则修改了Modify时间
[root@centos_1 liao]# date;touch -a a.txt;echo "this is test">>a.txt;stat a.txt
Sun Oct 13 21:46:38 CST 2019##date命令
======================
File: ‘a.txt’
Size: 13 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 33619903 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2019-10-13 21:46:38.371199179 +0800
Modify: 2019-10-13 21:46:38.371199179 +0800
Change: 2019-10-13 21:46:38.371199179 +0800
Birth: -
[root@centos_1 liao]#
4、在/tmp目录下创建以tfile开头,后跟当前日期和时间的文件,文件名形如:tfile-2016-05-27-09-32-22。
[root@centos_1 liao]# ll total 4 drwxr-xr-x 4 root root 24 Oct 13 21:30 a1 drwxr-xr-x 2 root root 6 Oct 13 21:30 a2 -rw-r--r-- 1 root root 13 Oct 13 21:46 a.txt drwxr-xr-x 2 root root 6 Oct 13 21:35 q_y drwxr-xr-x 2 root root 6 Oct 13 21:35 q_z drwxr-xr-x 2 root root 6 Oct 13 21:35 x_y drwxr-xr-x 2 root root 6 Oct 13 21:35 x_z [root@centos_1 liao]# touch tfile-`date "+%Y-%m-%d-%H-%M-%S"` [root@centos_1 liao]# ll total 4 drwxr-xr-x 4 root root 24 Oct 13 21:30 a1 drwxr-xr-x 2 root root 6 Oct 13 21:30 a2 -rw-r--r-- 1 root root 13 Oct 13 21:46 a.txt drwxr-xr-x 2 root root 6 Oct 13 21:35 q_y drwxr-xr-x 2 root root 6 Oct 13 21:35 q_z -rw-r--r-- 1 root root 0 Oct 13 21:51 tfile-2019-10-13-21-51-27 drwxr-xr-x 2 root root 6 Oct 13 21:35 x_y drwxr-xr-x 2 root root 6 Oct 13 21:35 x_z [root@centos_1 liao]#
5、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。
[root@centos_1 mytest1]# cp -r /etc/p[^0-9] /tmp/mytest1/ [root@centos_1 mytest1]# ll total 0 drwxr-xr-x 5 root root 52 Oct 13 21:59 pm
6、创建用户tom,指定UID为5001,指定家目录为/tmp/tom, 指定shell为/bin/zsh, 指定基本组为tom,附加组为jack
[root@centos_1 pm]# tail /etc/passwd sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin chrony:x:998:996::/var/lib/chrony:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin ntp:x:38:38::/etc/ntp:/sbin/nologin saslauth:x:997:76:Saslauthd user:/run/saslauthd:/sbin/nologin mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin zabbix:x:996:995:Zabbix Monitoring System:/var/lib/zabbix:/sbin/nologin apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
[root@centos_1 pm]# useradd tom -u 5001 -d /tmp/tom -s /bin/zsh -G jack [root@centos_1 pm]# tail /etc/passwd
postfix:x:89:89::/var/spool/postfix:/sbin/nologin chrony:x:998:996::/var/lib/chrony:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin ntp:x:38:38::/etc/ntp:/sbin/nologin saslauth:x:997:76:Saslauthd user:/run/saslauthd:/sbin/nologin mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin zabbix:x:996:995:Zabbix Monitoring System:/var/lib/zabbix:/sbin/nologin apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin tom:x:5001:5001::/tmp/tom:/bin/zsh [root@centos_1 pm]#
7、常用的用户以及文件管理命令有哪些,并演示命令以及用法。
常用用户有 root ftp sshd apache等,
- cd
用户目录切换(进入目录),如下 进入a的目录
[root@centos_1 liao]# mkdir a [root@centos_1 liao]# ll total 4 drwxr-xr-x 2 root root 6 Oct 13 21:13 a -rwxr-xr-x. 1 root root 38 Aug 23 22:18 liao.sh [root@centos_1 liao]# cd a [root@centos_1 a]# ll total 0 [root@centos_1 a]#
- pwd
显示当前路径,如下
[root@centos_1 a]# pwd /liao/a [root@centos_1 a]#
- ls
显示目录下文件及文件夹信息,默认为当前路径
[root@centos_1 liao]# ls a liao.sh [root@centos_1 liao]#
- cat
用于打开文件中内容
[root@centos_1 liao]# cat liao.sh $!/bin/bash set -x echo "test hahaha" [root@centos_1 liao]#
- mkdir
用于创建目录
[root@centos_1 liao]# mkdir b [root@centos_1 liao]# ll total 4 drwxr-xr-x 2 root root 6 Oct 13 21:13 a drwxr-xr-x 2 root root 6 Oct 13 21:20 b -rwxr-xr-x. 1 root root 38 Aug 23 22:18 liao.sh [root@centos_1 liao]#
- more
全屏的方式按页显示文件内容,按Enter(向下翻滚一行),空格(向下滚动一屏),Q(退出命令)。
[root@centos_1 b]# more test.txt this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test --More--(43%)
- rm
删除某一文件及文件夹
[root@centos_1 b]# rm test.txt rm: remove regular file ‘test.txt’? y [root@centos_1 b]# ll total 0 [root@centos_1 b]# ================== [root@centos_1 liao]# ll total 4 drwxr-xr-x 2 root root 6 Oct 13 21:13 a drwxr-xr-x 2 root root 6 Oct 13 21:25 b -rwxr-xr-x. 1 root root 38 Aug 23 22:18 liao.sh [root@centos_1 liao]# rm -rf b [root@centos_1 liao]# ll total 4 drwxr-xr-x 2 root root 6 Oct 13 21:13 a -rwxr-xr-x. 1 root root 38 Aug 23 22:18 liao.sh [root@centos_1 liao]#
浙公网安备 33010602011771号