第二周作业

2020-04-26  本文已影响0人  乔克叔叔_7917

作业
1、描述Linux发行版的系统目录名称命名规则以及用途。
2、描述文件的元数据信息有哪些,分别表示什么含义,如何查看?如何修改文件的时间戳信息?
3、总结软连接和硬连接区别,并用实例操作说明。
4、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。
5、复制/etc/profile至/tmp/目录,用查找替换命令删除/tmp/profile文件中的 行首的空白字符
6、在vim中设置tab缩进为4个字符

一 Linux目录结构

CentOS7的根目录如下:
/
├── bin -> usr/bin:所有用户使用的基本命令
├── boot:引导文件存放目录
├── dev:设备文件及特殊文件存储位置
├── etc:配置文件目录
├── home:普通用户家目录
├── lib -> usr/lib:启动时程序依赖的基本共享库文件以及内核模块文件
├── lib64 -> usr/lib64:专用于x86_64系统上的辅助共享库文件存放位置
├── media:便携式移动设备挂载点
├── mnt:临时文件系统挂载点
├── opt:第三方应用程序的安装位置
├── proc:用于输出内核与进程信息相关的虚拟文件系统
├── root:管理员的家目录
├── run:临时文件系统,存储系统启动以来的信息
├── sbin -> usr/sbin:系统管理员使用的系统管理程序
├── srv:系统上运行的服务用到的数据
├── sys:用于输出当前系统上硬件设备相关信息虚拟文件系统
├── tmp:临时文件存储位置
├── usr:universal shared, read-only data
│   ├── bin:保证系统拥有完整功能而提供的应用程序
│   ├── etc
│   ├── games
│   ├── include
│   ├── lib:32位使用
│   ├── lib64:只存在64位系统
│   ├── libexec
│   ├── local:第三方应用程序的安装位置
│   ├── sbin
│   ├── share:结构化独立的数据,例如doc, man等
│   ├── src
│   └── tmp -> ../var/tmp
└── var
   ├── adm
   ├── cache:应用程序缓存数据目录
   ├── crash
   ├── db
   ├── empty
   ├── games
   ├── gopher
   ├── kerberos
   ├── lib:应用程序状态信息数据
   ├── local:专用于为/usr/local下的应用程序存储可变数据
   ├── lock -> ../run/lock:锁文件
   ├── log:日志目录及文件
   ├── mail -> spool/mail
   ├── nis
   ├── opt
   ├── preserve
   ├── run -> ../run
   ├── spool:应用程序数据池
   ├── tmp:保存系统两次重启之间产生的临时数据
   └── yp

二 Linux文件的元数据

文件的类型

通过 ls -l 命令查看文件,输出行记录的第一个字符即为文件类型标识符

[root@localhost ~]# ll /
total 16
lrwxrwxrwx.   1 root root    7 Apr 19 11:12 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 Apr 19 11:18 boot
drwxr-xr-x.  19 root root 3200 Apr 24 20:53 dev
drwxr-xr-x.  77 root root 8192 Apr 24 20:57 etc
...
标识符 文件类型
- 普通文件
d 目录文件
b 块设备
c 字符设备
l 符号链接文件
p 管道文件pipe
s 套接字文件socket

元数据

在磁盘上存放的每一个文件可分为两部分:

可通过 stat [文件或目录] 查看文件的属性

[root@localhost ~]# stat anaconda-ks.cfg 
  File: ‘anaconda-ks.cfg’
  Size: 1623        Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d  Inode: 16797774    Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:admin_home_t:s0
Access: 2020-04-19 11:17:07.297967230 +0800
Modify: 2020-04-19 11:17:07.299967230 +0800
Change: 2020-04-19 11:17:07.299967230 +0800
 Birth: -

时间属性由三种:atime,ctime,mtime

[root@localhost ~]# ll --time=atime anaconda-ks.cfg 
-rw-------. 1 root root 1624 Apr 24 22:23 anaconda-ks.cfg
[root@localhost ~]# ll anaconda-ks.cfg 
-rw-------. 1 root root 1624 Apr 24 22:23 anaconda-ks.cfg
[root@localhost ~]# ll --time=ctime anaconda-ks.cfg 
-rw-------. 1 root root 1624 Apr 24 22:23 anaconda-ks.cfg
[root@localhost ~]# chmod a+x anaconda-ks.cfg 
[root@localhost ~]# ll --time=ctime anaconda-ks.cfg 
-rwx--x--x. 1 root root 1624 Apr 24 22:33 anaconda-ks.cfg

三 软链接和硬链接区别

四 文件管理类命令

[root@localhost /]# tree -L 1 /
/
├── bin -> usr/bin
├── boot
├── dev
├── etc
[root@localhost /]# cd /etc/
[root@localhost etc]# 
[root@localhost etc]# pwd
/etc
# 在根目录下创建test文件夹
[root@localhost /]# mkdir test
[root@localhost /]#
[root@localhost ~]# stat anaconda-ks.cfg 
  文件:"anaconda-ks.cfg"
  大小:1913       块:8          IO 块:4096   普通文件
设备:fd00h/64768d Inode:33574997    硬链接:1
权限:(0600/-rw-------)  Uid:(    0/    root)   Gid:(    0/    root)
环境:system_u:object_r:admin_home_t:s0
最近访问:2020-03-24 21:02:21.145113749 +0800
最近更改:2019-10-13 08:12:04.595947653 +0800
最近改动:2019-10-13 08:12:04.595947653 +0800
创建时间:-
[root@localhost tmp]# touch 123.txt
[root@localhost ~]# cp -a anaconda-ks.cfg /tmp/test.cfg
#把123.txt移至根目录
[root@localhost ~]# mv /tmp/123.txt /
[root@localhost tmp]# ln -s 123.txt abc.txt
[root@localhost tmp]# ll
总用量 304
-rw-r--r--. 1 root      root           0 4月  26 21:35 123.txt
lrwxrwxrwx. 1 root      root           7 4月  26 21:32 abc.txt -> 123.txt
[root@localhost tmp]# rm 123.txt 
rm:是否删除普通空文件 "123.txt"?y

五 删除 profile 文件中行首的空白字符

在扩展命令模式下完成查找替换操作

[root@localhost tmp]# cp /etc/profile /tmp/
[root@localhost tmp]# vim /tmp/profile

:%s/^[[:space:]]*//

六 在vim中设置tab缩进为4个字符

进入命令模式

:set tabstop=4

永久有效
全局:/etc/vimrc
用户:~/.vimrc

上一篇 下一篇

猜你喜欢

热点阅读