当前位置:首页>Linux>Linux05-Linux文件与目录管理

Linux05-Linux文件与目录管理

  • 2026-06-30 16:02:03
Linux05-Linux文件与目录管理

一、目录与路径

1.1 相对路径与绝对路径

绝对路径 :路径的写法'一定由根目录/写起',如:/usr/share/doc

相对路径:路径的写法'不是由根目录/写起',指相对于目录工作目录的路径。

在所有目录底下都会存在的两个目录,分别是'.'与'..' 分别代表此层与上层目录的意思。

pwd[root@localhost data]# pwd
/data
[root@localhost data]# ls -la
总用量 2233656
drwxr-xr-x   5 root root      409611月 1014:55 .
dr-xr-xr-x. 21 root root      40964月 112025 ..
drwxr-xr-x   733 tape      40969月 172025 betterdocs
-rw-r--r--1 root root  1261549610月 272025 betterdocs.zip
-rw-------1 root root 54544435211月 1014:53 debian12.tar
-rw-------1 root root 40188467210月 272025 mariadb.10.7.tar
-rw-------1 root root 58377932810月 272025 phpmyadmin.tar
drwxr-xr-x   3 root root      40964月 152025 .temp
drwxr-xr-x   2 root root      40969月 172025 wordpress-kb
-rw-------1 root root 74349772810月 272025 wordpress.php8.1-apache.tar

1.2 目录的相关操作

cd:切换目录change dirctory

[root@localhost data]# pwd
/data
[root@localhost data]# cd ~ 
#[回到家目录,root用户的家目录是/root,普通用户的家目录是“/home/对应用户名”]
[root@localhost ~]# pwd  [显示当前目录]
/root
[root@localhost ~]# cd -  [回到刚刚的目录]
/data
[root@localhost data]# pwd
/data
[root@localhost data]# cd ..  [回到上层目录]
[root@localhost /]# pwd
/
[root@localhost /]# cd /usr/local/java/   [使用绝对路径]
[root@localhost java]# pwd
/usr/local/java
[root@localhost java]# cd ../src/  [使用相对路径]
[root@localhost src]# pwd
/usr/local/src
[root@localhost src]# pwd -P
/usr/local/src
[root@localhost src]# ln -s ../src/ src.link
[root@localhost src]# ls
src.link
[root@localhost src]# ls -l
总用量 0
lrwxrwxrwx 1 root root 74月 3011:22 src.link -> ../src/
[root@localhost src]# cd src.link/
[root@localhost src.link]# pwd
/usr/local/src/src.link
[root@localhost src.link]# pwd -P   
#[如果当前目录是一个软链接文件,链接到一个目录,-P选项会显示真实的路径,而不是软链接的路径]
/usr/local/src

mkdir:创建新目录

命令常用选项:

-m 设置权限,如不配置则按umask配置的权限创建

-p 创建多级目录,如果父目录不存在,则逐级创建

man mkdir 原文
-m, --mode=MODE
              set file mode (as in chmod), not a=rwx - umask
-p, --parents
              no error if existing, make parent directories as needed
[root@localhost src.link]# umask
0022
[root@localhost src.link]# cd /home/zhaohong/
[root@localhost zhaohong]# mkdir test
[root@localhost zhaohong]# ls -ld test/
drwxr-xr-x 2 root root 64月 3015:01 test/
[root@localhost zhaohong]# mkdir test1/test2/test3
mkdir: 无法创建目录 “test1/test2/test3”: 没有那个文件或目录
[root@localhost zhaohong]# mkdir -p test1/test2/test3
[root@localhost zhaohong]# ls -l
drwxr-xr-x  2 root     root      64月 3015:01 test
drwxr-xr-x  3 root     root     194月 3015:03 test1
drwxr-xr-x. 2 zhaohong zhaohong  64月  22025 thinclient_drives
[root@localhost zhaohong]# mkdir -m 700 test2  [指定权限为700]
[root@localhost zhaohong]# ls -ld test2/
drwx------ 2 root root 64月 3015:03 test2/
[root@localhost zhaohong]#

rmdir:删除空目录

[root@localhost zhaohong]# ls
公共  模板  视频  图片  文档  下载  音乐  桌面  test  test1  test2  thinclient_drives
[root@localhost zhaohong]# rmdir test2
[root@localhost zhaohong]# ls
公共  模板  视频  图片  文档  下载  音乐  桌面  test  test1  thinclient_drives
[root@localhost zhaohong]# rmdir -p test1/test2/test3/
[root@localhost zhaohong]# ls
公共  模板  视频  图片  文档  下载  音乐  桌面  test  thinclient_drives
[root@localhost zhaohong]# cd test/
[root@localhost test]# touch tet.txt
[root@localhost test]# cd ..
[root@localhost zhaohong]# rmdir test
rmdir: 删除 'test' 失败: 目录非空

1.3 关于可执行文件路径的变量:$PATH

ls 命令的绝对路径 为:/bin/ls ,但是我们可以在任何地方 执行ls命令,这就是因为环境变量PATH的帮助来实现的。PATH(一定是大写)这个变量由一堆目录所组成,每个目录中间用冒号来隔开。

切换用户,使用su - username,与su username,两种切换方式后,环境变量是不一样的,建议使用带-命令进行切换用户。

[root@localhost zhaohong]# echo $PATH
/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/java/jdk1.8.0_311/bin
[root@localhost zhaohong]# which ls
alias ls='ls --color=auto'
        /usr/bin/ls
[root@localhost zhaohong]# su zhaohong
[zhaohong@localhost ~]$ echo$PATH
/home/zhaohong/.local/bin:/home/zhaohong/bin:/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/java/jdk1.8.0_311/bin
[zhaohong@localhost ~]$ su- zhaohong
密码:
[zhaohong@localhost ~]$ echo$PATH
/home/zhaohong/.local/bin:/home/zhaohong/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/local/java/jdk1.8.0_311/bin

二、文件与目录管理

2.1 文件与目录查看:ls

选项与参数:

  • -a列出所有文件,包括隐藏文件(以点 . 开头的文件),常用

  • -A:列出所有文件,包括隐藏文件,但不包括 .(当前目录)与 ..(上级目录)这两个目录项

  • -d仅列出目录本身,而不是列出目录内的文件数据,常用

  • -f:直接列出结果,不进行排序(ls 默认会按文件名排序)

  • -F:根据文件、目录等信息,附加表示其类型的符号,例如:

    • * 代表可执行文件

    • / 代表目录

    • = 代表 socket 文件

    • | 代表 FIFO 文件

  • -h将文件容量以人类较易读的格式显示(如 GB、KB 等)

  • -i:列出 inode 号码

  • -l以长格式列出,显示文件的属性与权限等信息,常用

  • -n:列出 UID 与 GID,而不是用户与群组的名称

  • -r:将排序结果反向输出,例如原本文件名从小到大排序,反向则变为从大到小

  • -R连同子目录内容一起列出,即显示该目录下的所有文件(包括子目录中的)

  • -S:按文件容量大小排序,而不是按文件名排序

  • -t:按修改时间(内容改变时间)排序,而不是按文件名

  • --color=never:不根据文件特性给予颜色显示

  • --color=always:总是显示颜色

  • --color=auto:让系统自行根据设置判断是否给予颜色

  • --full-time:以完整时间模式输出(包含年、月、日、时、分)

  • --time={atime,ctime}:输出 access 时间(访问时间)或改变权限属性时间(ctime),而不是内容变更时间(modification time)

命令演示示例:

[root@localhost test]# ls
test.fifo  test.txt
[root@localhost test]# pwd
/home/zhaohong/test
[root@localhost test]# mkdir -p test1/test2
[root@localhost test]# touch test1/test2/test.file
[root@localhost test]# ls -a
.  ..  test1  test.fifo  test.txt
[root@localhost test]# ls -al
总用量 4
drwxr-xr-x   3 root     root       524月 3016:51 .
drwx------. 17 zhaohong zhaohong 40964月 3015:27 ..
drwxr-xr-x   3 root     root       194月 3016:51 test1
prw-r--r--   1 root     root        04月 3015:32 test.fifo
-rw-r--r--1 root     root        04月 3015:07 test.txt
[root@localhost test]# ls -ld test1
drwxr-xr-x 3 root root 194月 3016:51 test1
[root@localhost test]# ls -ld .
drwxr-xr-x 3 root root 524月 3016:51 .
[root@localhost test]# ls -alF
总用量 4
drwxr-xr-x   3 root     root       524月 3016:51 ./
drwx------. 17 zhaohong zhaohong 40964月 3015:27 ../
drwxr-xr-x   3 root     root       194月 3016:51 test1/
prw-r--r--   1 root     root        04月 3015:32 test.fifo|
-rw-r--r--1 root     root        04月 3015:07 test.txt
[root@localhost test]# ls -alFn
总用量 4
drwxr-xr-x   300524月 3016:51 ./
drwx------. 171000100040964月 3015:27 ../
drwxr-xr-x   300194月 3016:51 test1/
prw-r--r--   10004月 3015:32 test.fifo|
-rw-r--r--10004月 3015:07 test.txt
[root@localhost test]# ls -alFnR
.:
总用量 4
drwxr-xr-x   300524月 3016:51 ./
drwx------. 171000100040964月 3015:27 ../
drwxr-xr-x   300194月 3016:51 test1/
prw-r--r--   10004月 3015:32 test.fifo|
-rw-r--r--10004月 3015:07 test.txt

./test1:
总用量 0
drwxr-xr-x 300194月 3016:51 ./
drwxr-xr-x 300524月 3016:51 ../
drwxr-xr-x 200234月 3016:51 test2/

./test1/test2:
总用量 0
drwxr-xr-x 200234月 3016:51 ./
drwxr-xr-x 300194月 3016:51 ../
-rw-r--r--10004月 3016:51 test.file
[root@localhost test]# ls -alFn --full-time
总用量 4
drwxr-xr-x   300522026-04-3016:51:10.298511042 +0800 ./
drwx------. 171000100040962026-04-3015:27:22.569328686 +0800 ../
drwxr-xr-x   300192026-04-3016:51:10.298511042 +0800 test1/
prw-r--r--   10002026-04-3015:32:58.666572770 +0800 test.fifo|
-rw-r--r--10002026-04-3015:07:22.933812166 +0800 test.txt
[root@localhost test]# ls -alFn --full-time --time=atime
总用量 4
drwxr-xr-x   300522026-04-3016:51:15.374318398 +0800 ./
drwx------. 171000100040962026-04-3015:27:31.613985414 +0800 ../
drwxr-xr-x   300192026-04-3016:51:17.752228149 +0800 test1/
prw-r--r--   10002026-04-3015:32:58.666572770 +0800 test.fifo|
-rw-r--r--10002026-04-3015:44:24.110558083 +0800 test.txt
[root@localhost test]# ls -alFn --full-time --time=ctime
总用量 4
drwxr-xr-x   300522026-04-3016:51:10.298511042 +0800 ./
drwx------. 171000100040962026-04-3015:27:22.569328686 +0800 ../
drwxr-xr-x   300192026-04-3016:51:10.298511042 +0800 test1/
prw-r--r--   10002026-04-3015:32:58.666572770 +0800 test.fifo|
-rw-r--r--10002026-04-3015:39:34.922533647 +0800 test.txt
[root@localhost test]# ls -alFnt --full-time
总用量 4
drwxr-xr-x   300522026-04-3016:51:10.298511042 +0800 ./
drwxr-xr-x   300192026-04-3016:51:10.298511042 +0800 test1/
prw-r--r--   10002026-04-3015:32:58.666572770 +0800 test.fifo|
drwx------. 171000100040962026-04-3015:27:22.569328686 +0800 ../
-rw-r--r--10002026-04-3015:07:22.933812166 +0800 test.txts

Linux文件是四个时间

缩写中文英文记录什么会影响对应时间的命令
atime访问时间Access time最后一次读取文件catlessheadtailmorecp source destvim -R file./script.sh
mtime内容修改时间Modify time文件内容被修改echo "abc" >> file      # 写入vim file               # 修改内容cp new file            # 覆盖写truncate -s 0 file     # 清空文件
ctime属性变更时间Change timeinode 元数据变化chmod 777 file     # 改权限chown user file    # 改属主ln file link       # 新增硬链接rm link            # 删除硬链接mv file newname    # 改文件名echo hi >> file    # 修改内容(inode大小变化)
crtime / btime创建时间Creation/Birth time文件创建时间不能修改,创建时固定

四个时间关系图

创建文件
   ↓
crtime = ctime = mtime = atime

读取文件
   ↓
atime 更新

修改内容
   ↓
mtime + ctime 更新

修改权限/重命名
   ↓
ctime 更新

查看文件的四个时间命令:stat

[root@localhost test]# stat test.txt
  文件:test.txt
  大小:0               块:0          IO 块:4096   普通空文件
设备:fd00h/64768d      Inode:52963786    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2026-04-30 15:44:24.110558083 +0800#[access time]
最近更改:2026-04-30 15:07:22.933812166 +0800#[modify time内容变更]
最近改动:2026-04-30 15:39:34.922533647 +0800#[ctime改变权限属性时间]
创建时间:2026-04-30 15:07:22.933812166 +0800#[创建时间]

2.2 复制、删除与移动:cp、rm、mv

2.2.1 cp命令

复制文件(或目录),本质上就是创建新的文件或目录,因此,在执行cp命令前,需要确保操作用户对要拷贝的文件(或目录)所在的目录拥有写权限,对要拷贝的文件(或目录)有读权限。拷贝后的文件权限由操作用户决定,与原文件没有关系,即使使用了-a选项,除非是使用root用户进行操作。

[zhaohong@localhost test]$ ll
总用量 0
-rw-r--r--1 zhaohong zhaohong 05月  615:10 123.txt
[zhaohong@localhost test]$ ls-ld .
drwxr-xr-x 2 zhaohong zhaohong 215月  615:10 .
[zhaohong@localhost test]$ chmod-w .
[zhaohong@localhost test]$ ls-ld .                      #[取消test目录的写权限]
dr-xr-xr-x 2 zhaohong zhaohong 215月  615:10 .
[zhaohong@localhost test]$ cp-av123.txt 123.txt.bak    #[拷贝时报权限不足]
'123.txt'-'123.txt.bak'
cp: 无法创建普通文件'123.txt.bak': 权限不够
[zhaohong@localhost test]$ chmod u+w .                   #[增加test目录的写权限]
[zhaohong@localhost test]$ ls-ld .
drwxr-xr-x 2 zhaohong zhaohong 215月  615:10 .
[zhaohong@localhost test]$ cp-av123.txt 123.txt.bak    #[拷贝时不报权限不足]
'123.txt'-'123.txt.bak'
[zhaohong@localhost test]$ ll
总用量 0
-rw-r--r--1 zhaohong zhaohong 05月  615:10 123.txt
-rw-r--r--1 zhaohong zhaohong 05月  615:10 123.txt.bak
[root@localhost test]# ll
总用量 0
-rw-r--r--1 zhaohong zhaohong 05月  615:10 123.txt
-rw-r--r--1 zhaohong zhaohong 05月  615:10 123.txt.bak
[root@localhost test]# ls -ld .
drwxr-xr-x 2 zhaohong zhaohong 405月  615:11 .
[root@localhost test]# chmod o+w .
[root@localhost test]# ls -ld .
drwxr-xrwx 2 zhaohong zhaohong 405月  615:11 .
[root@localhost test]# su test
[test@localhost test]$ cp-av123.txt 123.txt.testuser.bak  #[使用test用户拷贝所有者为zhaohong的文件]
'123.txt'-'123.txt.testuser.bak'
[test@localhost test]$ ll
总用量 0
-rw-r--r--1 zhaohong zhaohong 05月  615:10 123.txt
-rw-r--r--1 zhaohong zhaohong 05月  615:10 123.txt.bak
-rw-r--r--1 test     test     05月  615:10 123.txt.testuser.bak #[拷贝后的文件所有者和属组是操作用户test]

命令格式:

[root@study ~]# cp [-adfilprsu] 源文件或目录(source) 目标文件或目录(destination)
选项全称作用典型场景
-rrecursive递归复制目录复制目录
-Rrecursive同 -r,更规范复制目录
-a-dprarchive原样复制(最重要)递归复制、保留权限、保留软链接、保留时间、保留属主备份目录
-ppreserve保留权限/时间/属主保持文件属性
-fforce强制覆盖自动化脚本
-iinteractive覆盖前询问手动操作防误删
-nno-clobber不覆盖已有文件防止误覆盖
-vverbose显示复制过程排错/查看进度
-dno-dereference复制符号链接本身,不复制链接指向的文件,没有-d时,复制的是链接指向的文件复制软链接
-Ldereference复制链接指向文件跟随软链接
-xone-file-system不跨文件系统备份系统
-llink创建硬链接去重备份
-ssymbolic-link创建符号链接创建软链接
-t DIRtarget-dir指定目标目录,复制多个文件到指定目录cp -t /backup file1 file2 file3批量复制

高频组合命令(最实用)

命令含义
cp file1 file2复制文件
cp -r dir1 dir2复制目录
cp -a src dst 完整备份复制
cp -av src dst备份并显示过程
cp -ax / /backup备份系统根目录
cp -i file /tmp覆盖前询问
cp -n file /tmp不覆盖已有文件
[root@localhost study]# touch 123.txt             [准备一个文件123.txt]
[root@localhost study]# echo 123 > 123.txt        [123.txt文件中写入内容123]
[root@localhost study]# cat 123.txt               [查看文件内容]
123
[root@localhost study]# ls -ld 123.txt --full-time [查看文件属性]
-rw-r--r--1 root root 42026-05-0611:26:03.006498115 +0800123.txt
[root@localhost study]# mkdir test                 [准备一个目录]
[root@localhost study]# ls
123.txt  test
[root@localhost study]# cd test/                   [进入目录test]
[root@localhost test]# touch 234.txt               [test目录中有一个234.txt的文件]
[root@localhost test]# echo 234 > 234.txt
[root@localhost test]# cat 234.txt
234
[root@localhost test]# ls -ld 234.txt --full-time
-rw-r--r--1 root root 42026-05-0611:27:57.830628917 +0800234.txt
[root@localhost test]# cd ..
[root@localhost study]# ls -l --full-time
总用量 4
-rw-r--r--1 root root  42026-05-0611:26:03.006498115 +0800123.txt
drwxr-xr-x 2 root root 212026-05-0611:27:50.149954624 +0800 test
[root@localhost study]# cp -a 123.txt 123.txt.bak    [拷贝文件至文件,前提是123.txt.bak这个文件不存在]
[root@localhost study]# ls -l --full-time
总用量 8
-rw-r--r--1 root root  42026-05-0611:26:03.006498115 +0800123.txt
-rw-r--r--1 root root  42026-05-0611:26:03.006498115 +0800123.txt.bak
drwxr-xr-x 2 root root 212026-05-0611:27:50.149954624 +0800 test
[root@localhost study]# cat 123.txt.bak
123
[root@localhost study]# cp -a test/ test.bak   [拷贝test目录为test.bak,前提是test.bak不存在]
[root@localhost study]# ls -l --full-time
总用量 8
-rw-r--r--1 root root  42026-05-0611:26:03.006498115 +0800123.txt
-rw-r--r--1 root root  42026-05-0611:26:03.006498115 +0800123.txt.bak
drwxr-xr-x 2 root root 212026-05-0611:27:50.149954624 +0800 test
drwxr-xr-x 2 root root 212026-05-0611:27:50.149954624 +0800 test.bak
[root@localhost study]# cp -a 123.txt test   [如果test是一个存在的目录,拷贝文件至目录。如果test文件不存在,创建一个名为test的文件,内容与属性与123.txt一样。如果test是一个存在的文件,则会提示是否覆盖test的内容为123.txt]
[root@localhost study]# ls -l test --full-time
总用量 8
-rw-r--r--1 root root 42026-05-0611:26:03.006498115 +0800123.txt
-rw-r--r--1 root root 42026-05-0611:27:57.830628917 +0800234.txt
[root@localhost study]# cp -a test test.bak/  [拷贝目录至另一个目录内,前提是test.bak这个目录已经存在]
[root@localhost study]# ls -l test.bak/ --full-time
总用量 4
-rw-r--r--1 root root  42026-05-0611:27:57.830628917 +0800234.txt
drwxr-xr-x 2 root root 362026-05-0611:30:17.381814771 +0800 test
[root@localhost study]# ls -il               [查看文件的inode]
总用量 16
52963784-rw-r--r--1 root root  45月  611:26 123.txt
52963786-rw-r--r--1 root root  45月  611:26 123.txt.bak
2538405 drwxr-xr-x 2 root root 365月  611:30 test
52963787-rw-r--r--1 root root  45月  611:26 test10
52365131-rw-r--r--1 root root  45月  611:26 test11
22176856 drwxr-xr-x 3 root root 335月  611:30 test.bak
[root@localhost study]# cp -l 123.txt 123.txt.hardlink  [创建硬链接文件]
[root@localhost study]# ls -il
总用量 20
52963784-rw-r--r--2 root root  45月  611:26 123.txt           
#与123.txt.hardlink硬链接文件的inode号一样
52963786-rw-r--r--1 root root  45月  611:26 123.txt.bak
52963784-rw-r--r--2 root root  45月  611:26 123.txt.hardlink
2538405 drwxr-xr-x 2 root root 365月  611:30 test
52963787-rw-r--r--1 root root  45月  611:26 test10
52365131-rw-r--r--1 root root  45月  611:26 test11
22176856 drwxr-xr-x 3 root root 335月  611:30 test.bak
[root@localhost study]# cp -s 123.txt 123.txt.softlink       [创建软链接文件]
[root@localhost study]# ls -il
总用量 20
52963784-rw-r--r--2 root root  45月  611:26 123.txt
52963786-rw-r--r--1 root root  45月  611:26 123.txt.bak
52963784-rw-r--r--2 root root  45月  611:26 123.txt.hardlink
53421985 lrwxrwxrwx 1 root root  75月  611:51 123.txt.softlink -123.txt  #软链接文件指向实际的文件
2538405 drwxr-xr-x 2 root root 365月  611:30 test
52963787-rw-r--r--1 root root  45月  611:26 test10
52365131-rw-r--r--1 root root  45月  611:26 test11
22176856 drwxr-xr-x 3 root root 335月  611:30 test.bak
[root@localhost study]# ls -al test     [目录下有一个隐藏文件.config]
总用量 8
drwxr-xr-x 2 root root  515月  612:00 .
drwxr-xr-x 4 root root 1445月  612:02 ..
-rw-r--r--1 root root   45月  611:26 123.txt
-rw-r--r--1 root root   45月  611:27 234.txt
-rw-r--r--1 root root   05月  612:00 .config
[root@localhost study]# mkdir testdir
[root@localhost study]# mkdir testdir1
[root@localhost study]# cp -av test/. testdir [复制目录中的文件至另一目录,包含隐藏文件,为什么.可以代表目录中的所有内容,因为.表示当前目录对象]
'test/./.config'-'testdir/./.config'
'test/./234.txt'-'testdir/./234.txt'
'test/./123.txt'-'testdir/./123.txt'
[root@localhost study]# cp -av test/* testdir1 [复制目录中的文件至另一目录,不包含隐藏文件]
'test/123.txt'-'testdir1/123.txt'
'test/234.txt'-'testdir1/234.txt'

2.2.2 rm命令

删除文件或目录,语法:

rm [选项] 文件/目录
选项全称作用说明
-rrecursive递归删除目录删除目录必备
-fforce强制删除不提示、不报错
-iinteractive删除前询问防误删
-vverbose显示删除过程排错/确认
[root@localhost test]# ls
123.txt  123.txt.bak  123.txt.testuser.bak
[root@localhost test]# rm -i 123.txt
rm:是否删除普通空文件 '123.txt'?y
[root@localhost test]# ls
123.txt.bak  123.txt.testuser.bak
[root@localhost test]# rm -iv 123.txt.bak
rm:是否删除普通空文件 '123.txt.bak'?y
已删除 '123.txt.bak'
[root@localhost test]# cd ..
[root@localhost zhaohong]# rm -rf test/
[root@localhost zhaohong]# ls
公共  模板  视频  图片  文档  下载  音乐  桌面  study  thinclient_drives
[root@localhost zhaohong]# ls -l test/
总用量 0
-rw-r--r--1 root root 05月  615:29 123.txt
[root@localhost zhaohong]# rm -rfv test/
已删除 'test/123.txt'
已删除目录 'test/'

2.2.3 mv命令

mv = move 用于:

  • 移动文件/目录

  • 重命名文件/目录

mv file1 file2      # 重命名
mv file dir/        # 移动
选项全称作用说明
-iinteractive覆盖前询问防误覆盖
-fforce强制覆盖不提示
-nno-clobber不覆盖已有文件安全移动
-vverbose显示移动过程排错/确认
-uupdate只移动较新的文件增量移动
-bbackup覆盖前创建备份自动备份
[root@localhost zhaohong]# ls -ld 123.txt
-rw-r--r--1 root root 05月  615:34 123.txt
[root@localhost zhaohong]# ls -l study/123.txt --full-time                [这个文件更新]
-rw-r--r--1 root root 42026-05-0615:36:06.702341782 +0800 study/123.txt
[root@localhost zhaohong]# ls -ld 123.txt --full-time                      [这个文件较旧]
-rw-r--r--1 root root 02026-05-0615:34:57.647695091 +0800123.txt
[root@localhost zhaohong]# mv -u 123.txt study/                            [-u移动时,由于移动的文件较旧,不移动]
[root@localhost zhaohong]# ls -l study/123.txt --full-time
-rw-r--r--1 root root 42026-05-0615:36:06.702341782 +0800 study/123.txt
[root@localhost zhaohong]# mv -b 123.txt study/                         [覆盖前自动备份]
mv:是否覆盖'study/123.txt'? y
[root@localhost zhaohong]# ls study/                                [自动备份的文件名在原文件名后加~]
123.txt  123.txt~
[root@localhost zhaohong]# mv study/123.txt study/234.txt           [改名]
[root@localhost zhaohong]# ls study/
123.txt~  234.txt

2.3 查看文件内容命令

2.3.1 cat命令

命令:cat 文件名

-A  :相当于 -vET 的整合选项,可列出一些特殊字符而不是空白而已;
-b  :列出行号,仅针对非空白行做行号显示,空白行不标行号!
-E  :将结尾的换行字符 $ 显示出来;
-n  :打印出行号,连同空白行也会有行号,与 -b 选项不同;
-T  :将 [tab] 键以 ^I 显示出来;
-v  :列出一些看不出来的特殊字符
[root@localhost zhaohong]# cat /etc/issue
\S
Kernel \r on an \m

[root@localhost zhaohong]# cat -b /etc/issue
1  \S
2  Kernel \r on an \m

[root@localhost zhaohong]# cat -A /etc/issue
\S$
Kernel \r on an \m$
$

2.3.2 less命令

命令:less  选项  文件名

  • 空格键 :向下翻动一页;

  • [pagedown]:向下翻动一页;

  • [pageup] :向上翻动一页;

  • /字符串 :向下搜索『字串』的功能;

  • ?字符串 :向上搜索『字串』的功能;

  • n :重复前一个搜索 (与 / 或 ? 有关! )

  • N :反向的重复前一个搜索 ( 与 / 或 ? 有关! )

  • g :前进到这个数据的第一行去;

  • G :前进到这个数据的最后一行去 (注意大小写);

  • q :离开 less 这个程序;

选项作用使用频率说明
-N显示行号查看配置文件必开
-S长行不换行查看日志/代码
-i搜索忽略大小写配合 / 搜索
-I强制忽略大小写全忽略
-F内容一屏显示则自动退出适合小文件
-R显示颜色查看带颜色日志
-c整屏刷新减少闪烁
-p pattern打开时定位到关键字快速定位
+行号打开到指定行定位报错行
+G打开到文件末尾查看最新日志

less 使用的正则类型

less 使用 POSIX 正则(基础正则)

支持:

  • . 任意字符

  • * 重复

  • ^ 行首

  • $ 行尾

  • [] 字符集合

  • \{n,m\} 次数

  • | 或(需转义)

最常用的正则搜索

  • 同时搜索多个关键字

    查 error 或 warn:

    /error|warn

    查 fail 或 denied:

    /fail|denied
  • 搜索整行匹配

    行首匹配 ^

    查以 ERROR 开头:

    /^ERROR

    查以时间开头:

    /^[0-9]

    行尾匹配 $

    查以 .conf 结尾:

    /\.conf$
  • 匹配数字

    查 HTTP 状态码:

    /[0-9][0-9][0-9]

    查 500 错误:

    / 500 

    查 4xx 或 5xx:

    / [45][0-9][0-9]
  • 匹配IP地址 

    /((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
  • 只显示匹配行

    在 less 里输入:

    &关键字

    例:

    &error

    效果:只显示包含 error 的行, 其他行全部隐藏!

2.3.3 head、tail命令

head 常用选项表

选项作用示例
-n 行数指定显示行数head -n 20 file
-c 字节数按字节显示head -c 100 file
-q不显示文件名多文件时
-v强制显示文件名多文件时

查看前20行

head -n 20 log.txt

同时查看多个文件

head file1 file2
[root@localhost zhaohong]# cp -av /var/log/messages /var/log/messages.bak
'/var/log/messages'-'/var/log/messages.bak'
[root@localhost zhaohong]# cd /var/log/
[root@localhost log]# head -v messages messages.bak
==> messages <==
192.168.1.1
Apr 3009:33:15 localhost kernel: The list of certified hardware and cloud instances for Red Hat Enterprise Linux 9 can be viewed at the Red Hat Ecosystem Catalog, https://catalog.redhat.com.
Apr 3009:33:15 localhost kernel: Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-432.el9.x86_64 root=/dev/mapper/cs-root ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=/dev/mapper/cs-swap rd.lvm.lv=cs/root rd.lvm.lv=cs/swap rhgb quiet
Apr 3009:33:15 localhost kernel: [Firmware Bug]: TSC doesn't count with P0 frequency!
Apr 3009:33:15 localhost kernel: x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
Apr 3009:33:15 localhost kernel: x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
Apr 3009:33:15 localhost kernel: x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
Apr 3009:33:15 localhost kernel: x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
Apr 3009:33:15 localhost kernel: x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
Apr 3009:33:15 localhost kernel: signal: max sigframe size: 1776

==> messages.bak <==
192.168.1.1
Apr 3009:33:15 localhost kernel: The list of certified hardware and cloud instances for Red Hat Enterprise Linux 9 can be viewed at the Red Hat Ecosystem Catalog, https://catalog.redhat.com.
Apr 3009:33:15 localhost kernel: Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-432.el9.x86_64 root=/dev/mapper/cs-root ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=/dev/mapper/cs-swap rd.lvm.lv=cs/root rd.lvm.lv=cs/swap rhgb quiet
Apr 3009:33:15 localhost kernel: [Firmware Bug]: TSC doesn't count with P0 frequency!
Apr 3009:33:15 localhost kernel: x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
Apr 3009:33:15 localhost kernel: x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
Apr 3009:33:15 localhost kernel: x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
Apr 3009:33:15 localhost kernel: x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
Apr 3009:33:15 localhost kernel: x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
Apr 3009:33:15 localhost kernel: signal: max sigframe size: 1776

tail 常用选项表 

选项作用说明
-n 行数显示最后 N 行最常用
-f实时跟踪文件日志神器
-F文件轮转也跟踪日志轮转必用
-c 字节数按字节显示
--pid=PID进程结束停止脚本用

tail 最重要功能:实时看日志

tail -f /var/log/messages

查看最后50行

tail -n 50 log.txt

实时查看最后100行

tail -n 100 -f log.txt

最常用:

tail -f -n 100 log.txt

2.2.4 touch命令

touch 用于:

  • 创建空文件

  • 修改文件时间戳

基本语法:

touch [选项] 文件

默认修改文件的atime + mtime,由于atime + mtime也是元数据的一部分,所以ctime会改变。

选项作用说明命令示例
无选项创建空文件文件不存在就创建,文件存在则是修改文件是atime + mtime创建单个文件:touch file.txt创建多个文件:touch file1 file2 file3批量创建文件:touch log{1..5}.txt 生成log1.txt log2.txt log3.txt log4.txt log5.txt
-a只修改访问时间(atime)touch -a file.txt
-m只修改修改时间(mtime)内容修改时间touch -m file.txt
-t指定时间戳最常用格式:[[CC]YY]MMDDhhmm[.ss]示例:touch -t 202501011200 file.txt 表示修改atime + mtime为2025-01-01 12:00
-d使用日期字符串更直观touch -d "2025-01-01 12:00" file.txttouch -d "yesterday" file.txttouch -d "2 days ago" file.txttouch -d "next monday" file.txt
-c不创建文件如果文件不存在,不要自动创建,如果文件存在,仍然会修改时间。touch -c file.txt
-r参考文件时间时间复制touch -r file1 file2 让 file2 时间 = file1注意 atime/mtime 是一个合理的时间(不早于它的 birth time 且不晚于当前时间)
[root@localhost study]# touch file.txt   [文件不存在,创建文件,时间为当前时间]
[root@localhost study]# stat file.txt
  文件:file.txt
  大小:0               块:0          IO 块:4096   普通空文件
设备:fd00h/64768d      Inode:52963781    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2026-05-07 10:18:22.099636896 +0800
最近更改:2026-05-07 10:18:22.099636896 +0800
最近改动:2026-05-07 10:18:22.099636896 +0800
创建时间:2026-05-07 10:18:22.099636896 +0800
[root@localhost study]# touch file.txt      
#[文件存在,修改时间atime+mtime,由于atime和mtime也是元数据的一分部,所以ctime也改变了]#
[root@localhost study]# stat file.txt
  文件:file.txt
  大小:0               块:0          IO 块:4096   普通空文件
设备:fd00h/64768d      Inode:52963781    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2026-05-07 10:19:04.584804159 +0800
最近更改:2026-05-07 10:19:04.584804159 +0800
最近改动:2026-05-07 10:19:04.584804159 +0800
创建时间:2026-05-07 10:18:22.099636896 +0800
[root@localhost study]# touch -a file.txt   [只修改atime,同时也会修改ctime]
[root@localhost study]# stat file.txt
  文件:file.txt
  大小:0               块:0          IO 块:4096   普通空文件
设备:fd00h/64768d      Inode:52963781    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2026-05-07 10:24:17.498192723 +0800
最近更改:2026-05-07 10:19:04.584804159 +0800
最近改动:2026-05-07 10:24:17.498192723 +0800
创建时间:2026-05-07 10:18:22.099636896 +0800
[root@localhost study]# touch -m file.txt  [只修改mtime,同时也会修改ctime]
[root@localhost study]# stat file.txt
  文件:file.txt
  大小:0               块:0          IO 块:4096   普通空文件
设备:fd00h/64768d      Inode:52963781    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2026-05-07 10:24:17.498192723 +0800
最近更改:2026-05-07 10:25:01.387652382 +0800
最近改动:2026-05-07 10:25:01.387652382 +0800
创建时间:2026-05-07 10:18:22.099636896 +0800
[root@localhost study]# touch -t 202601011200 file.txt    [指定时间atime+mtime,ctime会变成当前时间]
[root@localhost study]# stat file.txt
  文件:file.txt
  大小:0               块:0          IO 块:4096   普通空文件
设备:fd00h/64768d      Inode:52963781    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2026-01-01 12:00:00.000000000 +0800
最近更改:2026-01-01 12:00:00.000000000 +0800
最近改动:2026-05-07 10:26:05.818391131 +0800
创建时间:2026-05-07 10:18:22.099636896 +0800
[root@localhost study]# touch -d "2025-02-02 13:00"  file.txt  [指定时间atime+mtime,ctime会变成当前时间]
[root@localhost study]# stat file.txt
  文件:file.txt
  大小:0               块:0          IO 块:4096   普通空文件
设备:fd00h/64768d      Inode:52963781    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2025-02-02 13:00:00.000000000 +0800
最近更改:2025-02-02 13:00:00.000000000 +0800
最近改动:2026-05-07 10:27:22.016716886 +0800
创建时间:2026-05-07 10:18:22.099636896 +0800
[root@localhost study]# stat file.txt
  文件:file.txt
  大小:0               块:0          IO 块:4096   普通空文件
设备:fd00h/64768d      Inode:52963781    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2026-05-07 10:39:44.942243522 +0800
最近更改:2026-05-07 10:39:44.942243522 +0800
最近改动:2026-05-07 10:39:44.942243522 +0800
创建时间:2026-05-07 10:18:22.099636896 +0800
[root@localhost study]# stat 234.txt
  文件:234.txt
  大小:0               块:0          IO 块:4096   普通空文件
设备:fd00h/64768d      Inode:52963786    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2026-05-07 10:28:29.148360843 +0800
最近更改:2026-05-07 10:28:29.148360843 +0800
最近改动:2026-05-07 10:28:51.250585149 +0800
创建时间:2026-05-06 15:34:57.647695091 +0800
[root@localhost study]# touch -r file.txt 234.txt  [修改234.txt文件的时间为file.txt的时间,如果file.txt的时间被手动修改为比创建时间更早的时间,touch -r命令不生效]
[root@localhost study]# stat 234.txt
  文件:234.txt
  大小:0               块:0          IO 块:4096   普通空文件
设备:fd00h/64768d      Inode:52963786    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2026-05-07 10:39:44.942243522 +0800
最近更改:2026-05-07 10:39:44.942243522 +0800
最近改动:2026-05-07 10:40:32.477190826 +0800
创建时间:2026-05-06 15:34:57.647695091 +0800

2.2.5 预设权限与隐藏权限(特殊权限)

预设权限

umask = 创建文件时“去掉哪些权限”

文件默认最大权限666, 为什么不是777,因为文件默认不能有执行权限。如果默认有执行权限,任何新文件能直接执行,对于系统来说不安全。Linux的设计理念,是默认最小权限。

目录默认最大权限777, 因为目录需要x才能进入。

文件:666 - umask
目录:777 - umask
[root@localhost study]# umask
0022
[root@localhost study]# touch 123.txt
[root@localhost study]# ls -ld 123.txt
-rw-r--r--1 root root 05月  715:07 123.txt
[root@localhost study]# mkdir testdir
[root@localhost study]# ls -ld testdir/
drwxr-xr-x 2 root root 65月  715:07 testdir/
[root@localhost study]#

特殊权限

Linux 权限体系全景

类型示例解释示例应用场景
普通权限rwx
特殊权限SUID / SGID / StickySUID,显示为rws,普通用户执行程序时,临时拥有文件owner权限。SGID,目录中新文件,自动继承目录所属组。对于文件基本不用。Sticky,目录中只能删除自己的文件,root不受控制。SUID配置:chmod u+s file.txt SGID配置:chmod g+s dir(取消把+换成-,无x权限,显示为大写S,有x权限显示为小写s)sticky配置:chmod +t dir(或者chmod 1xxx dir)取消把+换成-,无x权限,显示为大写T,有x权限显示为小写tSUID应用:/usr/bin/passwd 普通用户可修改自己的密码SGID应用:团队协作常用。Sticky应用:/tmp目录下的临时文件,只能删除自己的文件
ACL权限setfacl普通rwx不够细时,单独给某个用户权限配置:setfacl -m u:user1:rwx test.file取消:setfacl -m u:user1:--- test.file普通rwx不够细时,单独给某个用户权限
文件属性(隐藏权限)chattri属性,设置后,文件变成只读锁定状态,不允许修改内容、删除、重命名、修改权限。a属性,追加模式,设置后,可以追加内容,不能删除和覆盖修改。设置:chattr +i/a xxxx查看:lsattr xxxx取消:chattr -i/a xxxxi属性:防止误删日志文件,只能追加,防止清空日志
SUID配置命令演示:
-----------------------------------------------------------------------------------------------------------
[root@localhost study]# ls -l
总用量 0
-rw-r--r--1 root root 05月 1416:00 test.file
[root@localhost study]# chmod u+s test.file  [添加SUID权限,由于没有x权限,显示为大写的S]
[root@localhost study]# ls -l
总用量 0
-rwSr--r--1 root root 05月 1416:00 test.file
[root@localhost study]# chmod u+x test.file  [添加SUID权限,添加x权限,显示为小写的s]
[root@localhost study]# ls -l
总用量 0
-rwsr--r--1 root root 05月 1416:00 test.file
[root@localhost study]# chmod u-s test.file   [取消s权限]
[root@localhost study]# ls -l
总用量 0
-rwxr--r--1 root root 05月 1416:00 test.file
[root@localhost study]# ls -ld /usr/bin/passwd
-rwsr-xr-x1 root root 326488月 102021 /usr/bin/passwd
-----------------------------------------------------------------------------------------------------------

SGID配置命令演示:
-----------------------------------------------------------------------------------------------------------
[root@localhost study]# su zhangsan  [切换用户至zhangsan]
[zhangsan@localhost study]$ mkdir testdir  #[创建目录,目录的属组也是zhangsan]
[zhangsan@localhost study]$ ls-l
总用量 0
drwxr-xr-x 2 zhangsan zhangsan 65月 1416:27 testdir
-rwxr--r--1 root     root     05月 1416:00 test.file
[zhangsan@localhost testdir]$ exit
exit
[root@localhost study]# ll
总用量 0
drwxr-xr-x 2 zhangsan zhangsan 65月 1416:27 testdir
-rwxr--r--1 root     root     05月 1416:00 test.file
[root@localhost study]# chmod o+w testdir/  [为目录其他人添加w权限,不角其他用户无法在该目录下创建文件]
[root@localhost study]# ll
总用量 0
drwxr-xrwx 2 zhangsan zhangsan 65月 1416:27 testdir
-rwxr--r--1 root     root     05月 1416:00 test.file
[root@localhost study]# su lisi
[lisi@localhost study]$ ll
总用量 0
drwxr-xrwx 2 zhangsan zhangsan 65月 1416:27 testdir
-rwxr--r--1 root     root     05月 1416:00 test.file
[lisi@localhost study]$ cd testdir/
[lisi@localhost testdir]$ ll
总用量 0
[lisi@localhost testdir]$ touch test.file  #[lisi创建的文件所有者和属组都是lisi]
[lisi@localhost testdir]$ ll
总用量 0
-rw-r--r--1 lisi lisi 05月 1416:32 test.file
[lisi@localhost testdir]$ exit
exit
[root@localhost study]# ls -ld testdir/
drwxr-xrwx 2 zhangsan zhangsan 235月 1416:32 testdir/
[root@localhost study]# chmod g+s testdir/   [testdir目录增加SGID权限,配置后drwxr-srwx]
[root@localhost study]# ls -ld testdir/
drwxr-srwx 2 zhangsan zhangsan 235月 1416:32 testdir/
[root@localhost study]# su lisi
[lisi@localhost study]$ ls-l
总用量 0
drwxr-srwx 2 zhangsan zhangsan 235月 1416:32 testdir
-rwxr--r--1 root     root      05月 1416:00 test.file
[lisi@localhost study]$ cd testdir/
[lisi@localhost testdir]$ ls-l
总用量 0
-rw-r--r--1 lisi lisi 05月 1416:32 test.file
[lisi@localhost testdir]$ touch test.file1  #[目录配置SGID权限后,lisi用户创建的文件属组不是lisi,而是zhangsan]
[lisi@localhost testdir]$ ls-l
总用量 0
-rw-r--r--1 lisi lisi     05月 1416:32 test.file
-rw-r--r--1 lisi zhangsan 05月 1416:35 test.file1
[lisi@localhost testdir]$ exit
exit
[root@localhost study]# ll
总用量 0
drwxr-srwx 2 zhangsan zhangsan 415月 1416:35 testdir
-rwxr--r--1 root     root      05月 1416:00 test.file
[root@localhost study]# chmod g-s testdir/           [取消SGID权限]
[root@localhost study]# ll
总用量 0
drwxr-xrwx 2 zhangsan zhangsan 415月 1416:35 testdir
-rwxr--r--1 root     root      05月 1416:00 test.file
-----------------------------------------------------------------------------------------------------------

Sticky配置命令演示:
-----------------------------------------------------------------------------------------------------------
[root@localhost study]# ls -ld /tmp
drwxrwxrwt. 19 root root 40965月 1416:22 /tmp
[lisi@localhost tmp]$ ls-ld zhangsan.file
-rwxrwxrwx1 zhangsan zhangsan 05月 1416:40 zhangsan.file
[lisi@localhost tmp]$ rm-rf zhangsan.file
rm: 无法删除 'zhangsan.file': 不允许的操作
-----------------------------------------------------------------------------------------------------------


setfacl配置命令演示:
-----------------------------------------------------------------------------------------------------------
[root@localhost study]# touch test.file    [创建文件]
[root@localhost study]# ll
总用量 0
-rw-r--r--1 root root 05月 1416:00 test.file
[root@localhost study]# getfacl test.file  [查看test.file这个文件的acl权限,这时跟ls -l看到的结果一样]
# file: test.file
# owner: root
# group: root
user::rw-
group::r--
other::r--

[root@localhost study]# useradd user1      [创建用户user1]
[root@localhost study]# setfacl -m u:user1:rwx test.file  
#[配置权限,对象是test.file这个文件,用户是user1,权限是rwx]
[root@localhost study]# getfacl test.file  [查看acl权限,对比没配置之前,多了`user:user1:rwx`]
# file: test.file
# owner: root
# group: root
user::rw-
user:user1:rwx
group::r--
mask::rwx
other::r--
[root@localhost study]# setfacl -m u:user1:--- test.file    [配置user1对test.file的权限为---,也就是无权限]
[root@localhost study]# getfacl test.file
# file: test.file
# owner: root
# group: root
user::rw-
user:user1:---
group::r--
mask::r--
other::r--

[root@localhost study]# setfacl -x u:user1 test.file  [删除 user1 的所有权限(恢复为无任何特殊权限)]
[root@localhost study]# getfacl test.file
# file: test.file
# owner: root
# group: root
user::rw-
group::r--
mask::r--
other::r--
[root@localhost study]# ls -l
总用量 0
-rw-r--r--+1 root root 05月 1416:00 test.file  #[最后的+号,表示:标准权限 + ACL]
[root@localhost study]# setfacl -b test.file  [去掉+号]
[root@localhost study]# ls -l
总用量 0
-rw-r--r--1 root root 05月 1416:00 test.file
-----------------------------------------------------------------------------------------------------------

chattr命令演示:
-----------------------------------------------------------------------------------------------------------
[root@localhost study]# ls -l
总用量 0
-rwxr--r--1 root root 05月 1416:00 test.file
[root@localhost study]# lsattr test.file
---------------------- test.file
[root@localhost study]# chattr +i test.file  [添加i属性,后不可删除,不可修改权限、属组、所有者]
[root@localhost study]# lsattr test.file
----i----------------- test.file
[root@localhost study]# rm -rf test.file
rm: 无法删除 'test.file': 不允许的操作
[root@localhost study]# chmod 777 test.file
chmod: 正在更改 'test.file' 的权限: 不允许的操作
[root@localhost study]# chown zhangsan test.file
chown: 正在更改'test.file' 的所有者: 不允许的操作
[root@localhost study]# chgrp zhangsan test.file
chgrp: 正在更改'test.file' 的所属组: 不允许的操作
[root@localhost study]# echo 123 > test.file
-bash: test.file: 不允许的操作
[root@localhost study]# chattr -i test.file  [取消i属性]
[root@localhost study]# lsattr test.file
---------------------- test.file

[root@localhost study]# lsattr test.file
---------------------- test.file
[root@localhost study]# chattr +a test.file  [添加a属性,与i属性差不多,只是多了追加写]
[root@localhost study]# lsattr test.file
-----a---------------- test.file
[root@localhost study]# rm -rf test.file
rm: 无法删除 'test.file': 不允许的操作
[root@localhost study]# echo 123 > test.file
-bash: test.file: 不允许的操作
[root@localhost study]# echo 123 >> test.file
[root@localhost study]# cat test.file
123

2.4 文件与命令的搜索

2.4.1 命令搜索

which ——在PATH里查找可执行文件,-a选项:显示所有匹配路径 

whereis ——查的更全面,含源码、手册 

命令作用
whereis -b ls只找二进制
whereis -m ls只找 man 手册
whereis -s ls只找源码

type——判断命令的“真实身份”,很多命令不是程序,而是:

  • alias别名

  • shell内建命令

  • 函数

type才能看出来。

command -v —— 最标准脚本用法 

写 shell 脚本时,官方推荐用它判断命令是否存在。

command -v docker

如果存在 → 输出路径如果不存在 → 不输出

以上命令演示:

[root@localhost ~]# which -a ls
alias ls='ls --color=auto'
        /usr/bin/ls
[root@localhost ~]# which ls
alias ls='ls --color=auto'
        /usr/bin/ls
[root@localhost ~]# which python
/usr/bin/python
[root@localhost ~]# which -a python
/usr/bin/python
[root@localhost ~]# man which
[root@localhost ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
[root@localhost ~]# type cd
cd 是 shell 内建
[root@localhost ~]# type ls
ls 是“ls --color=auto”的别名
[root@localhost ~]# type ifconfig
ifconfig 是 /usr/sbin/ifconfig
[root@localhost ~]# command -v docker
/usr/bin/docker

2.4.2 locate命令

locate工作原理,locate不是实时搜索磁盘,它搜索的是系统里的一个数据库:/var/lib/mlocate/mlocate.db,这个数据库由updatedb 命令生成。locate比find快很多倍。

基本用法:locate 文件名

常用选项选项有什么用
-i忽略大小写
-N显示N条结果
-c显示结果数量
-b精确匹配(完整路径匹配),默认是模糊匹配。
-r使用正则表达式
[root@localhost study]# updatedb
[root@localhost study]# locate nginx.conf
/opt/test/test1/nginx.conf
/root/soft/nginx-1.26.2/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf.bak
/usr/local/nginx/conf/nginx.conf.default
[root@localhost study]# locate -i NGINX.CONF
/opt/test/test1/nginx.conf
/root/soft/nginx-1.26.2/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf.bak
/usr/local/nginx/conf/nginx.conf.default
[root@localhost study]# locate -i  -n 3NGINX.CONF
locate: 3NGINX.CONF 有无效的值 `limit'
[root@localhost study]# locate -i  -n 3 NGINX.CONF
/opt/test/test1/nginx.conf
/root/soft/nginx-1.26.2/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf
[root@localhost study]# locate -i  -c NGINX.CONF
5
-----------------------------------------------------------------------------------------------------------
加反斜杠 \ 的作用

反斜杠会转义第一个字符 n,但 n 本身不是特殊字符,所以转义后仍然是 n。关键在于:locate 的一个隐藏规则——如果模式中包含转义字符(如反斜杠),它会禁用通配符模式,转而进行字面字符串匹配。

因此 '\nginx.conf' 的效果是:

    将模式当作纯字符串 nginx.conf 进行匹配

    只匹配完全等于 nginx.conf 的文件名(因为 -b 只匹配 basename,不匹配路径) 
-----------------------------------------------------------------------------------------------------------

[root@localhost study]# locate -b '\nginx.conf' 
/opt/test/test1/nginx.conf
/root/soft/nginx-1.26.2/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf
[root@localhost study]# locate -b nginx.conf  [# 会匹配所有包含 "nginx.conf" 的文件名(如 nginx.conf.bak)]
/opt/test/test1/nginx.conf
/root/soft/nginx-1.26.2/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf.bak
/usr/local/nginx/conf/nginx.conf.default
[root@localhost study]# locate -r "/var/log/.*\.log"
/var/lib/docker/overlay2/05fea0ccd1abc9322bb352960231b42b5c0d18aa664ca19e2d8100538b1e3e15/diff/var/log/alternatives.log
/var/lib/docker/overlay2/05fea0ccd1abc9322bb352960231b42b5c0d18aa664ca19e2d8100538b1e3e15/diff/var/log/dpkg.log
/var/lib/docker/overlay2/05fea0ccd1abc9322bb352960231b42b5c0d18aa664ca19e2d8100538b1e3e15/diff/var/log/apt/eipp.log.xz
/var/lib/docker/overlay2/05fea0ccd1abc9322bb352960231b42b5c0d18aa664ca19e2d8100538b1e3e15/diff/var/log/apt/history.log
/var/lib/docker/overlay2/05fea0ccd1abc9322bb352960231b42b5c0d18aa664ca19e2d8100538b1e3e15/diff/var/log/apt/term.log

2.4.3 find命令

(1)、find 基本语法
说明
基本格式find 路径 条件 动作
常用示例find /etc -name nginx.conf
忽略报错2>/dev/null

(2)、按名称查找
用法命令示例说明
精确名称find / -name "nginx.conf"区分大小写
忽略大小写find / -iname "nginx.conf"不区分大小写
模糊匹配find /var -name "*.log"查所有log
多条件 ORfind / -name "*.log" -o -name "*.txt"查log或txt
排除 NOTfind / ! -name "*.log"排除log

(3)、按文件类型查找 
类型参数示例
普通文件-type ffind /etc -type f
目录-type dfind /etc -type d
软链接-type lfind / -type l
块设备-type bfind /dev -type b
字符设备-type cfind /dev -type c

(4)、按文件大小查找 
条件命令含义
大于100Mfind / -size +100M大文件
小于10Mfind / -size -10M小文件
等于50Mfind / -size 50M精确大小
大于1G文件find / -type f -size +1G查大文件神器

单位:kMG


(5)、按时间查找 
时间类型参数示例含义
修改时间-mtimefind / -mtime -11天内修改
访问时间-atimefind / -atime +77天未访问
属性时间-ctimefind / -ctime -1最近改权限
写法含义
-mtime -124小时内
-mtime +3030天前

(6)、按权限查找
用法命令说明
指定权限find / -perm 777危险权限
SUID 文件find / -perm -4000安全检查
SGID 文件find / -perm -2000安全检查

(7)、按用户 / 组查找
用法命令
按用户find / -user nginx
按组find / -group root

(8)、查空文件 / 空目录
用法命令
空文件find /tmp -type f -empty
空目录find /tmp -type d -empty

(9)、组合条件
逻辑示例含义
AND(默认)find / -type f -name "*.log"同时满足
ORfind / -name "*.log" -o -name "*.txt"满足其一
NOTfind / ! -name "*.log"取反

(10)、执行命令 (精华)
功能命令
删除文件find /tmp -name "*.log" -delete
删除30天前日志find /var/log -mtime +30 -delete
批量 rmfind /tmp -name "*.tmp" -exec rm -f {} \;
批量 chmodfind . -name "*.sh" -exec chmod +x {} \;
批量 grepfind /etc -name "*.conf" -exec grep nginx {} \;

{} = 找到的文件\; = 命令结束


(11)、运维高频实战 
场景命令
找大文件find / -type f -size +1G 2>/dev/null
清理旧日志find /var/log -mtime +30 -delete
查777权限find / -perm 777 2>/dev/null
查最近修改find / -mtime -1
查所有logfind / -name "*.log"
批量加执行权限find . -name "*.sh" -exec chmod +x {} \;

谁能执行chmod、chgrp、chown

操作谁可以做
修改权限 chmod文件 所有者 或 root
修改所属组 chgrp文件 所有者 或 root(但有限制)
修改属主 chown只有 root

chmod → owner 可改chgrp → owner 可改组(仅限自己的组)chown → 只有 root 能改属主

命令文件所有者root目录权限要求
chmod被修改文件(或目录)所在目录需要 x
chgrp✅(仅限自己组)被修改文件(或目录)所在目录需要 x
chown被修改文件(或目录)所在目录需要 x
权限对普通文件对目录
r读文件内容读目录列表 (ls) 「列出文件名与inode的映射关系]
w写文件创建/删除文件 「写入或者删除文件名与inode的映射关系]
x执行程序进入目录 (cd)[改变“当前目录 inode 指针”]
本文的pdf版本下载地址:Linux05-Linux文件与目录管理.pdf

专注于IT技术分享,欢迎大家关注。

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-03 16:35:42 HTTP/2.0 GET : https://f.mffb.com.cn/a/494367.html
  2. 运行时间 : 0.230576s [ 吞吐率:4.34req/s ] 内存消耗:4,860.30kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=a8d15354217dd03a7332ab923ebba733
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000404s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000719s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.032175s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.006132s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000599s ]
  6. SELECT * FROM `set` [ RunTime:0.003757s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000580s ]
  8. SELECT * FROM `article` WHERE `id` = 494367 LIMIT 1 [ RunTime:0.009703s ]
  9. UPDATE `article` SET `lasttime` = 1783067742 WHERE `id` = 494367 [ RunTime:0.022665s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 67 LIMIT 1 [ RunTime:0.014553s ]
  11. SELECT * FROM `article` WHERE `id` < 494367 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.005433s ]
  12. SELECT * FROM `article` WHERE `id` > 494367 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.013836s ]
  13. SELECT * FROM `article` WHERE `id` < 494367 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.012087s ]
  14. SELECT * FROM `article` WHERE `id` < 494367 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.009636s ]
  15. SELECT * FROM `article` WHERE `id` < 494367 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.026214s ]
0.232973s