文件管理相关基础

1.描述Linux发行版的系统目录名称命名规则以及用途?

命名规则

1、文件名最长字节数255个
2、包括路径在内文件名称最长4095个字节
3、除了斜杠和NUL,所有字符都有效,但使用特殊字符的目录名和文件不推荐使用,有些字符需要用括号来引用它们。
4、Linux文件系统,文件名称大小写敏感。

各目录用途

/boot 引导文件存放目录,内核文件(vmlinuz)、引导加载器(bootloader,grub)都存放于此目录
/bin 所有用户使用基本命令,不能关联至独立分区,OS启动即会用到的程序。
/sbin 管理类的基本命令,不能关联至独立分区,OS启动即会用到的程序。
/lib 启动时程序依赖的基本共享库文件以及内核模块文件(/lib/modules)
/etc 配置文件目录
/home 普通用户家目录
/root 管理员家目录
/media 便携式移动设备挂载点
/mnt 临时文件系统挂载点
/dev 设备文件及特殊文件存储位置,
/opt 第三方应用程序安装位置
/srv 系统运行的服务用到的数据
/tmp 临时文件存储位置

2.描述文件元数据信息有哪些,分别代表什么含义,如何查看?如何修改文件的时间戳信息?

元数据信息:文件时间,文件大小,文件权限,文件属主和属组,文件链接数,
查看文件元数据信息:stat 文件名字 ,如下
修改文件时间戳

[14:51:36 root@centos7 ~]#ll test 
-rw-r--r--. 1 root root 0 Jun 21 14:51 test
[14:51:41 root@centos7 ~]#stat test 
  File: ‘test’
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d	Inode: 201326662   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2020-06-21 14:51:35.519064670 +0800
Modify: 2020-06-21 14:51:35.519064670 +0800
Change: 2020-06-21 14:51:35.519064670 +0800
 Birth: -
修改访问时间如下
[14:52:48 root@centos7 ~]#touch -a -d"2010-01-01 01:01:01" test 
[14:52:54 root@centos7 ~]#stat test
  File: ‘test’
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d	Inode: 201326662   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2010-01-01 01:01:01.000000000 +0800
Modify: 2020-06-21 14:51:35.519064670 +0800
Change: 2020-06-21 14:52:54.164066292 +0800
 Birth: -
修改文件修改时间(文件内容改变)如下
[14:53:01 root@centos7 ~]#touch -m -d"2010-01-01 01:01:01" test 
[14:53:13 root@centos7 ~]#stat test 
  File: ‘test’
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d	Inode: 201326662   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2010-01-01 01:01:01.000000000 +0800
Modify: 2010-01-01 01:01:01.000000000 +0800
Change: 2020-06-21 14:53:13.202066685 +0800
 Birth: -

3.总结软链接和硬链接区别,并用实例操作说明?

硬链接和软链接区别
1本质:硬链接:同一个文件多个名字,软链接指向另一个文件
2跨分区:硬链接不能跨分区,软链接可跨分区
3inode号:每个硬链接相同的inode号,软链接inode不同。
4链接数:创建硬链接增加链接数,软链接不增加链接数
5相对路径:原始文件路径,软链接指向另一个文件的路径
6.目录:硬链接不能对目录进行,软链接可以

[15:37:17 root@centos7 data]#ll -id etc.back
67173216 drwxr-xr-x. 4 root root 57 Jun 18 21:13 etc.back
[15:37:33 root@centos7 data]#cd testdir/
[15:38:49 root@centos7 testdir]#ll -id ../bash.txt 
394823 -rw-r--r--. 1 root root 15505 Jun 20 09:17 ../bash.txt
[15:39:45 root@centos7 testdir]#ln ../bash.txt lb
[15:40:14 root@centos7 testdir]#ln  ../etc.back/ el			//硬链接不能对目录进行
ln: ‘../etc.back/’: hard link not allowed for directory
[15:40:36 root@centos7 testdir]#ln -s ../etc.back/ el		//软链接可以对目录进行
[15:41:40 root@centos7 testdir]#ln /etc/profile pl			//硬链接不能跨分区
ln: failed to create hard link ‘pl’ => ‘/etc/profile’: Invalid cross-device link
[15:42:03 root@centos7 testdir]#ln -s /etc/profile pl		//软链接可以跨分区
[15:45:33 root@centos7 testdir]#ll
total 16
lrwxrwxrwx. 1 root root    12 Jun 21 15:41 el -> ../etc.back/
-rw-r--r--. 2 root root 15505 Jun 20 09:17 lb
lrwxrwxrwx. 1 root root    12 Jun 21 15:42 pl -> /etc/profile
[15:45:41 root@centos7 testdir]#ll -id lb
394823 -rw-r--r--. 2 root root 15505 Jun 20 09:17 lb
[15:46:26 root@centos7 testdir]#ll -i ../bash.txt 		//硬链接inode号相同
394823 -rw-r--r--. 2 root root 15505 Jun 20 09:17 ../bash.txt
[15:56:38 root@centos7 testdir]#ln ../bash.txt llb		//硬链接,链接数增加
[15:56:55 root@centos7 testdir]#ll -i llb 
394823 -rw-r--r--. 3 root root 15505 Jun 20 09:17 llb
[15:57:09 root@centos7 testdir]#
[15:46:31 root@centos7 testdir]#ll -i el
100674947 lrwxrwxrwx. 1 root root 12 Jun 21 15:41 el -> ../etc.back/
[15:50:34 root@centos7 testdir]#ll -id ../etc.back/		//软链接inode号不同
67173216 drwxr-xr-x. 4 root root 57 Jun 18 21:13 ../etc.back/
[15:57:09 root@centos7 testdir]#ln -s ../etc.back/ eel
[15:58:55 root@centos7 testdir]#ll -id ../etc.back/		//增加软链接,原文件连接数不变
67173216 drwxr-xr-x. 4 root root 57 Jun 18 21:13 ../etc.back/
[15:59:03 root@centos7 testdir]#

4.Linux上的文件管理命令有哪些,其常用的方法及其相关示例演示?

文件管理类命令
ls,stat 、mkdir、、rm、cp 、mv、cat,more,less,tail,tree

[15:06:47 root@centos7 ~]#ls -d .*		//查看隐藏文件
.   .bash_history  .bash_profile  .cache   .cshrc  .lesshst  .tcshrc   .vimrc
..  .bash_logout   .bashrc        .config  .dbus   .rnd      .viminfo  .Xauthority
[15:06:49 root@centos7 ~]#ls 		//查看文件
anaconda-ks.cfg  initial-setup-ks.cfg  test
[15:06:52 root@centos7 ~]#ls -a		//查看所有文件
.                .bash_history  .bashrc  .cshrc                .lesshst  test      .Xauthority
..               .bash_logout   .cache   .dbus                 .rnd      .viminfo
anaconda-ks.cfg  .bash_profile  .config  initial-setup-ks.cfg  .tcshrc   .vimrc
[15:06:57 root@centos7 ~]#ls -l		//按列查看文件的权限、所属用户和组及时间、文件大小
total 8
-rw-------. 1 root root 1882 May  2 13:45 anaconda-ks.cfg
-rw-r--r--. 1 root root 1930 May  2 13:48 initial-setup-ks.cfg
-rw-r--r--. 1 root root    0 Jan  1  2010 test
[15:07:17 root@centos7 ~]#

mkdir命令

[15:08:09 root@centos7 ~]#mkdir a	//创建目录a
[15:08:18 root@centos7 ~]#man mkdir 
[15:09:13 root@centos7 ~]#mkdir -v b	//创建目录b并显示创建过程
mkdir: created directory ‘b’
[15:09:30 root@centos7 ~]#mkdir -pv aa/aaa/bb	//递归创建目录aa、aa/aaa、aa/aaa/bb
mkdir: created directory ‘aa’
mkdir: created directory ‘aa/aaa’
mkdir: created directory ‘aa/aaa/bb’
[15:09:50 root@centos7 ~]#tree aa		//按树状显示目录aa
aa
└── aaa
    └── bb

2 directories, 0 files
[15:09:59 root@centos7 ~]#ls
a  aa  anaconda-ks.cfg  b  initial-setup-ks.cfg  test
[15:10:06 root@centos7 ~]#

rm命令

[15:11:17 root@centos7 ~]#rm -r a	//删除目录a
rm: remove directory ‘a’? y
[15:11:37 root@centos7 ~]#rm -rf b 		//不用提示确认删除目录b
[15:11:59 root@centos7 ~]#rm -rf aa		
[15:12:13 root@centos7 ~]#ls
anaconda-ks.cfg  initial-setup-ks.cfg  test
[15:12:51 root@centos7 ~]#

cp命令、mv命令

[15:15:38 root@centos7 ~]#cp -pr /etc/ etc.bak		//递归复制/etc目录下所有文件至etc.bak目录
[15:15:47 root@centos7 ~]#ls
anaconda-ks.cfg  etc.bak  initial-setup-ks.cfg  test
[15:15:49 root@centos7 ~]#
[15:15:49 root@centos7 ~]#mv etc.bak abc.bak	//重命名etc.bak目录
[15:16:56 root@centos7 ~]#ls
abc.bak  anaconda-ks.cfg  initial-setup-ks.cfg  test
[15:17:44 root@centos7 ~]#mv abc.bak /data/		//移动etc目录至/data/目录下
[15:18:00 root@centos7 ~]#ls /data/
abc.bak  bash.txt  etc.back  his.txt  scripts47  sh.template  testdir  tmp
[15:18:07 root@centos7 ~]#ls
anaconda-ks.cfg  initial-setup-ks.cfg  test
[15:18:50 root@centos7 ~]#

5.复制/etc/profile至/tmp目录,用替换命令删除/tmp/profile文件中的行首空白字符?

[15:27:03 root@centos7 ~]#cp /etc/profile /tmp	//复制目录
[15:27:35 root@centos7 ~]#ls /tmp/
glusterdump.options
glusterfs-statedumps
profile
systemd-private-ba2d6a18eaca44688c3d637c7c44e4cc-cups.service-8rCB6E
[15:27:40 root@centos7 ~]#
[16:49:39 linux01@centos7 tmp]$vim profile	//vim打开文件,扩展命令模式
unset i
unset -f pathmunge
 
 
:%s@^[[:space:]]*@@g			//删除行首空白字符

6.如何在vim中设置tab缩进为4个字符?

vim打开一个文件,扩展命令模式键入:set tabstop=4,此设置当前生效
永久生效编辑配置用户家目录下文件~/.vimrc,增加命令set tabstop=4
是配置立即生效source ~/.vimrc

^I$
~                                                                                                      
:set tabstop=4
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值