linux文件系统

一、文件系统相关知识

Linux中一切皆文件,其中从根目录开始“/”往下呈现倒置的树桩结构。文件系统中有以下特点:

1.区分大小写

2.每个路径以/分割

3.文件名最长255个字节

4.蓝色-->目录 绿色-->可执行文件 红色-->压缩文件 浅蓝色-->链接文件 灰色-->其他文件

5.以点开头的文件是隐藏文件

6.每个文件都有两类相关数据:元数据:metadata,即属性, 数据:data,即文件内容

1.1 绝对路径和相对路径

绝对路径以根目录开头,相对路径不以根目录开头。绝对路径表示了一个文件的具体位置,不管现在所处在哪个路径都能使用绝对路径获取到文件或者切换路径。相对路径表示的是相对于当时所处的路径的相对位置下的目录或者文件路径。若是所处的当前目录位置不正确则无法使用相对路径。

1.2 文件系统常用的命令

1.cd命令
cd命令用于切换当前目录如:
切换值根目录
[root@rocky8-200 ~]#cd /
切换至etc目录
[root@rocky8-200 /]#cd /etc/
[root@rocky8-200 etc]#

2.ls命令
ls命令用于列出当前目录下的内容
[root@rocky8-200 etc]#ls
adjtime                  dracut.conf.d  localtime                 rc5.d                            services
aliases                  environment    login.defs                rc6.d                            sestatus.conf
....
常用参数有: -l -a -h ...

3.stat命令
显示文件的元数据、大小、链接数等详细信息和时间戳
[root@rocky8-200 etc]#stat sysconfig/
  File: sysconfig/
  Size: 4096      	Blocks: 8          IO Block: 4096   directory
Device: fd00h/64768d	Inode: 100663974   Links: 5
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2024-07-31 16:36:55.910251509 +0800
Modify: 2024-06-05 21:27:42.226314556 +0800
Change: 2024-06-05 21:27:42.226314556 +0800
 Birth: 2024-01-12 20:00:21.621008972 +0800

4.file
查看文件的所属类型
[root@rocky8-200 ~]#file anaconda-ks.cfg 
anaconda-ks.cfg: ASCII text

5.mkdir
创建目录
[root@rocky8-200 ~]#mkdir test
递归创建目录加上-p选项
[root@rocky8-200 ~]#mkdir -p  test/test1/test2
[root@rocky8-200 ~]#ls test/
test1

6.touch
创建文件或者刷新文件的时间
[root@rocky8-200 test]#touch hello.txt
[root@rocky8-200 test]#ls
hello.txt  test1
-a 仅改变 atime和ctime
-m 仅改变 mtime和ctime
-t [[CC]YY]MMDDhhmm[.ss] 指定atime和mtime的时间戳
-c 如果文件不存在,则不予创建

7.移动文件和重命名
移动文件
[root@rocky8-200 test]#mv hello.txt test1/
[root@rocky8-200 test]#ls test1/
hello.txt  test2
重命名文件
[root@rocky8-200 test]#mv test1/hello.txt test1/hello1.txt 
[root@rocky8-200 test]#ls test1/
hello1.txt  test2

posted on 2024-07-31 16:57  lyon_11  阅读(7)  评论(0编辑  收藏  举报