ls 命令详解

文章目录

ls 命令详解

ls 命令 是非常常用的一个命令,用来显示 当前目录 有多少文件,目录,以及其他文件类型

你运行的是 ls -lh 命令,输出的每一行代表一个文件或目录,各列含义如下(以这一行为例)

bash 复制代码
root@frank:~# ls -lh
total 2.2G
-rw-r--r--  1 root root 2.2G Oct 24 10:19 aioo20251024.tar
-rw-r--r--  1 root mail  17M Feb  2 17:09 dead.letter
-rw-r--r--  1 root root   89 Feb  2 16:25 log.txt
drwxr-xr-x 21 root root 4.0K Oct 23 16:34 Python-3.13.7
-rw-r--r--  1 root root  29M Oct 23 16:22 Python-3.13.7.tgz
-rw-r--r--  1 root root    0 Feb  2 16:13 recive.pdf
drwxr-xr-x  2 root root 4.0K Oct 15 11:23 workspace


# 我们单独看 这个文件进行分析
-rw-r--r--  1 root root 2.2G Oct 24 10:19 aioo20251024.tar

每一列说明:

权限 链接数 所有者 所属组 大小 修改日期(mtime) 文件名

内容示例 含义
1 -rw-r--r-- 文件类型与权限
2 1 硬链接数(Hard Link Count)
3 root 文件所有者(User)
4 root 文件所属组(Group)
5 2.2G 文件大小(以易读单位显示,因用了 -h
6--8 Oct 24 10:19 最后修改时间(mtime)
9 aioo20251024.tar 文件名

1.文件类型与权限: -rw-r--r--

  • 第1个字符:

    文件类型

    • -:普通文件
    • d:目录(如 drwxr-xr-x
    • l:符号链接
    • c/b:字符/块设备
    • s:套接字,p:管道 等
  • 接下来的9个字符,每3个一组:

    • rw-所有者(user)权限 → 可读、可写、不可执行
    • r--所属组(group)权限 → 只读
    • r--其他用户(others)权限 → 只读

所以 -rw-r--r-- 表示:这是一个普通文件,所有者可读写,组和其他人只读。


2.硬链接数: 1

  • 普通文件通常为 1
  • 目录的硬链接数 = 2(. 和父目录中的条目) + 子目录数量(每个子目录有 .. 指向它)
  • 如果你创建了硬链接(ln file link),这个数字会增加

3.所有者(User): root

  • 文件属于哪个用户
  • chown user file 修改

4.所属组(Group): root

  • 文件属于哪个用户组
  • chgrp group filechown user:group file 修改

注意:第二行 dead.letter 的组是 mail,说明它可能由邮件系统(如 sendmail)生成。


5.文件大小: 2.2G

  • 因为用了 -h(human-readable),所以显示为 KMG
  • 实际字节数:2.2G ≈ 2,200,000,000 字节
  • 目录的大小通常是 4KB(存储目录元数据的最小块)

6--8.最后修改时间(mtime): Oct 24 10:19

  • 表示文件内容最后一次被修改的时间
  • 如果是今年以内 的文件,显示为 月 日 时:分
  • 如果是超过6个月前 的文件,会显示为 月 日 年(例如 Oct 24 2024
  • 注意:当前系统时间是 2026年1月31日 ,但这里显示 Oct 24 10:19,说明系统认为该文件是 2025年10月24日 修改的(因为文件名含 20251024,可能是故意设置的时间戳)

9.文件名: aioo20251024.tar

  • 如果是符号链接,会显示为 linkname -> target
  • 文件名以 / 开头?不会,ls 默认不显示路径,只显示 basename

常用选项介绍

让我们开始进入比较常用的选项, ls的选项 还是比较多,刚刚我们使用的是 -h, -l 以人类可读的方式显示当前目录中的文件和目录大小

-l 表示 长格式显示,

-h 表示 显示 文件大小

--time-style 指定显示的时间的样式

-a 显示所有文件,包含隐藏文件

参数 说明
-a--all 显示所有文件(包括以 . 开头的隐藏文件)。
-A--almost-all 显示除 ... 外的所有文件(包括隐藏文件)。
-l 以长格式(详细信息)列出文件(权限、所有者、大小、修改时间等)。
-h--human-readable -l 一起使用时,以人类可读的格式显示文件大小(如 KB、MB)。
-t 按修改时间排序(最新优先)。
-r--reverse 反向排序(配合 -t-S 等使用)。
-S 按文件大小排序(大文件优先)。
-R--recursive 递归列出子目录内容。
-F--classify 在文件名后附加标识符(如 / 表示目录,* 表示可执行文件)。
--color 彩色输出(通常默认启用,--color=auto)。
-i--inode 显示文件的 inode 编号。
-n--numeric-uid-gid 以数字形式显示 UID 和 GID(替代用户名和组名)。
-d--directory 仅显示目录本身,而非其内容(常用于配合 -l)。
-1 每行只显示一个文件(默认在终端宽度不足时自动启用)。-1 横线数字1
-m 以逗号分隔的列表形式显示文件。
-Q--quote-name 用引号括住文件名(适用于含空格的文件名)。
--group-directories-first 先显示目录,后显示文件。
--time-style=<格式> 自定义时间显示格式(如 +%Y-%m-%d)。

修改时间的显示方式

有时候 默认显示 很难受

Oct 24 10:19 这里我会感觉不舒服,因为我们都希望 年月日时分秒, 而不是 月年 时分 这样的默认格式 。

bash 复制代码
# 1这样显示是不是看起来舒服一点点
root@frank:~# ls -lh   --time-style=long-iso
total 2.2G
-rw-r--r--  1 root root 2.2G 2025-10-24 10:19 aioo20251024.tar
-rw-r--r--  1 root mail  17M 2026-02-02 17:17 dead.letter
-rw-r--r--  1 root root   89 2026-02-02 16:25 log.txt
drwxr-xr-x 21 root root 4.0K 2025-10-23 16:34 Python-3.13.7
-rw-r--r--  1 root root  29M 2025-10-23 16:22 Python-3.13.7.tgz
-rw-r--r--  1 root root    0 2026-02-02 16:13 recive.pdf
drwxr-xr-x  2 root root 4.0K 2025-10-15 11:23 workspace
root@frank:~# 



# 2以纳秒显示
root@frank:~# ls -lh   --time-style=full-iso 
total 2.2G
-rw-r--r--  1 root root 2.2G 2025-10-24 10:19:23.635418668 +0800 aioo20251024.tar
-rw-r--r--  1 root mail  17M 2026-02-02 17:18:04.064698016 +0800 dead.letter
-rw-r--r--  1 root root   89 2026-02-02 16:25:03.883127553 +0800 log.txt
drwxr-xr-x 21 root root 4.0K 2025-10-23 16:34:28.626408262 +0800 Python-3.13.7
-rw-r--r--  1 root root  29M 2025-10-23 16:22:21.749307493 +0800 Python-3.13.7.tgz
-rw-r--r--  1 root root    0 2026-02-02 16:13:45.216225606 +0800 recive.pdf
drwxr-xr-x  2 root root 4.0K 2025-10-15 11:23:40.957021763 +0800 workspace


# 3 自定义显示
root@frank:~# ls -lh  --time-style='+%Y-%m-%d %H:%M:%S'
total 2.2G
-rw-r--r--  1 root root 2.2G 2025-10-24 10:19:23 aioo20251024.tar
-rw-r--r--  1 root mail  17M 2026-02-02 17:19:03 dead.letter
-rw-r--r--  1 root root   89 2026-02-02 16:25:03 log.txt
drwxr-xr-x 21 root root 4.0K 2025-10-23 16:34:28 Python-3.13.7
-rw-r--r--  1 root root  29M 2025-10-23 16:22:21 Python-3.13.7.tgz
-rw-r--r--  1 root root    0 2026-02-02 16:13:45 recive.pdf
drwxr-xr-x  2 root root 4.0K 2025-10-15 11:23:40 workspace

第三种方式 写起来 太长了, 我们可以自定义一个环境变量 TIME_STYLE,写到PATH中,

bash 复制代码
# 定义一个默认的变量
export TIME_STYLE='+%Y-%m-%d %H:%M:%S'

root@frank:~# ls -lh
total 2.2G
-rw-r--r--  1 root root 2.2G 2025-10-24 10:19:23 aioo20251024.tar
-rw-r--r--  1 root mail  17M 2026-02-02 17:37:02 dead.letter
-rw-r--r--  1 root root   89 2026-02-02 16:25:03 log.txt
drwxr-xr-x 21 root root 4.0K 2025-10-23 16:34:28 Python-3.13.7
-rw-r--r--  1 root root  29M 2025-10-23 16:22:21 Python-3.13.7.tgz
-rw-r--r--  1 root root    0 2026-02-02 16:13:45 recive.pdf
drwxr-xr-x  2 root root 4.0K 2025-10-15 11:23:40 workspace

export TIME_STYLE='+%Y-%m-%d %H:%M:%S' 可将此行加入 ~/.bashrc 永久生效,或者 Mac ~/.zshrc 文件中

显示所有文件

-a 包含隐藏文件 把所有文件显示

当使用 -a 之后 , . .. 以及 ··.开头的文件,目录 都能显示

bash 复制代码
root@frank:~# ls -l
total 2254968
-rw-r--r--  1 root root 2261999104 2025-10-24 10:19:23 aioo20251024.tar
-rw-r--r--  1 root mail   17676852 2026-02-03 15:39:03 dead.letter
-rw-r--r--  1 root root         89 2026-02-02 16:25:03 log.txt
drwxr-xr-x 21 root root       4096 2025-10-23 16:34:28 Python-3.13.7
-rw-r--r--  1 root root   29382166 2025-10-23 16:22:21 Python-3.13.7.tgz
-rw-r--r--  1 root root          0 2026-02-02 16:13:45 recive.pdf
drwxr-xr-x  2 root root       4096 2025-10-15 11:23:40 workspace


root@frank:~# ls  -al
total 2264500
drwx------  9 root root       4096 2026-02-02 16:15:09 .
drwxr-xr-x 23 root root       4096 2025-12-26 09:50:02 ..
-rw-r--r--  1 root root 2261999104 2025-10-24 10:19:23 aioo20251024.tar
-rw-------  1 root root      21487 2026-02-02 18:06:19 .bash_history
-rw-r--r--  1 root root       3106 2024-04-22 21:04:27 .bashrc
drwx------  3 root root       4096 2025-10-23 16:43:30 .cache
drwx------  3 root root       4096 2025-12-22 11:33:37 .config
-rw-r--r--  1 root mail   17676852 2026-02-03 15:39:03 dead.letter
-rw-r--r--  1 root root     336111 2026-01-14 04:13:01 .jattach-2026-01-13T20-12-01.639.log.gz
-rw-r--r--  1 root root     366605 2026-01-16 05:34:01 .jattach-2026-01-15T21-33-02.489.log.gz
-rw-r--r--  1 root root     336820 2026-01-18 07:36:01 .jattach-2026-01-17T23-36-01.269.log.gz
-rw-r--r--  1 root root     336349 2026-01-20 09:39:02 .jattach-2026-01-20T01-38-01.792.log.gz
-rw-r--r--  1 root root     335660 2026-01-22 11:41:01 .jattach-2026-01-22T03-40-02.459.log.gz
-rw-r--r--  1 root root     336809 2026-01-24 23:19:01 .jattach-2026-01-24T15-18-01.882.log.gz
-rw-r--r--  1 root root     337062 2026-01-27 01:21:01 .jattach-2026-01-26T17-20-02.020.log.gz
-rw-r--r--  1 root root     365395 2026-01-29 02:42:01 .jattach-2026-01-28T18-42-01.374.log.gz
-rw-r--r--  1 root root     336966 2026-01-31 04:45:02 .jattach-2026-01-30T20-44-01.957.log.gz
-rw-r--r--  1 root root     337743 2026-02-02 06:47:01 .jattach-2026-02-01T22-46-02.302.log.gz
-rw-r--r--  1 root root    6201772 2026-02-03 15:39:01 .jattach.log
-rw-r--r--  1 root root       3219 2026-02-03 15:39:01 .jattach_record.json
-rw-------  1 root root         58 2026-01-31 10:11:23 .lesshst
-rw-r--r--  1 root root         89 2026-02-02 16:25:03 log.txt
drwxr-xr-x  2 root root       4096 2025-09-16 11:08:09 .pip
-rw-r--r--  1 root root        161 2024-04-22 21:04:27 .profile
-rw-r--r--  1 root root         72 2025-09-16 11:08:09 .pydistutils.cfg
drwxr-xr-x 21 root root       4096 2025-10-23 16:34:28 Python-3.13.7
-rw-r--r--  1 root root   29382166 2025-10-23 16:22:21 Python-3.13.7.tgz
-rw-------  1 root root         25 2026-01-31 12:57:32 .python_history
-rw-r--r--  1 root root          0 2026-02-02 16:13:45 recive.pdf
drwx------  2 root root       4096 2025-10-24 10:47:09 .ssh
drwxr-xr-x  2 root root       4096 2025-10-27 10:53:17 .vim
-rw-------  1 root root      10998 2025-12-27 09:05:34 .viminfo

排序功能

有时候 一个目录有一堆文件,我们需要进行排序,常用的两个选项

-t 按照时间 列排序,默认是降序排序的,最新的时间在第一个

-r 逆序 当配合-t 使用就是 最新的时间在最后一个 (这个有时候是我们需要的)

-S 按照文件大小进行排序

我们来演示一下

从修改时间角度 进行排序

bash 复制代码
# 按照修改时间 从大到小 排序 
root@frank:~# ls -lt
total 2254552
-rw-r--r--  1 root mail   17252088 2026-02-02 17:48:01 dead.letter
-rw-r--r--  1 root root         89 2026-02-02 16:25:03 log.txt
-rw-r--r--  1 root root          0 2026-02-02 16:13:45 recive.pdf
-rw-r--r--  1 root root 2261999104 2025-10-24 10:19:23 aioo20251024.tar
drwxr-xr-x 21 root root       4096 2025-10-23 16:34:28 Python-3.13.7
-rw-r--r--  1 root root   29382166 2025-10-23 16:22:21 Python-3.13.7.tgz
drwxr-xr-x  2 root root       4096 2025-10-15 11:23:40 workspace




# 按照修改时间 从小到大 排序 
root@frank:~# ls -ltr 
total 2254552
drwxr-xr-x  2 root root       4096 2025-10-15 11:23:40 workspace
-rw-r--r--  1 root root   29382166 2025-10-23 16:22:21 Python-3.13.7.tgz
drwxr-xr-x 21 root root       4096 2025-10-23 16:34:28 Python-3.13.7
-rw-r--r--  1 root root 2261999104 2025-10-24 10:19:23 aioo20251024.tar
-rw-r--r--  1 root root          0 2026-02-02 16:13:45 recive.pdf
-rw-r--r--  1 root root         89 2026-02-02 16:25:03 log.txt
-rw-r--r--  1 root mail   17252088 2026-02-02 17:48:01 dead.letter

有时候 我想看文件的情况, 我想按照文件大小排序

-S 就发挥作用了,按照文件大小排序,默认 大文件在前面 ,小文件排在后面

-r 可以配置这个 进行 逆序操作

bash 复制代码
root@frank:~# ls -lhS
total 2.2G
-rw-r--r--  1 root root 2.2G 2025-10-24 10:19:23 aioo20251024.tar
-rw-r--r--  1 root root  29M 2025-10-23 16:22:21 Python-3.13.7.tgz
-rw-r--r--  1 root mail  17M 2026-02-02 17:54:03 dead.letter
drwxr-xr-x 21 root root 4.0K 2025-10-23 16:34:28 Python-3.13.7
drwxr-xr-x  2 root root 4.0K 2025-10-15 11:23:40 workspace
-rw-r--r--  1 root root   89 2026-02-02 16:25:03 log.txt
-rw-r--r--  1 root root    0 2026-02-02 16:13:45 recive.pdf

#此时大文件就在上面第一个显示了


root@frank:~# ls -lhSr
total 2.2G
-rw-r--r--  1 root root    0 2026-02-02 16:13:45 recive.pdf
-rw-r--r--  1 root root   89 2026-02-02 16:25:03 log.txt
drwxr-xr-x  2 root root 4.0K 2025-10-15 11:23:40 workspace
drwxr-xr-x 21 root root 4.0K 2025-10-23 16:34:28 Python-3.13.7
-rw-r--r--  1 root mail  17M 2026-02-02 17:55:03 dead.letter
-rw-r--r--  1 root root  29M 2025-10-23 16:22:21 Python-3.13.7.tgz
-rw-r--r--  1 root root 2.2G 2025-10-24 10:19:23 aioo20251024.tar


# -r 就是逆序的意思, 此时大文件就在上面最后一个显示了

查看目本身

Python-3.13.7 这个是目录文件, 我想查看其本身 ,而不是文件夹的内容

此时可以使用 -d 选项

bash 复制代码
root@frank:~# ls -l   Python-3.13.7
total 129392
-rw-r--r--  1 root root    26738 2025-08-14 19:12:11 aclocal.m4
drwxr-xr-x  3 root root     4096 2025-08-14 19:12:11 Android
-rwxr-xr-x  1 root root 30015408 2025-10-23 16:34:26 _bootstrap_python
drwxr-xr-x  4 root root     4096 2025-10-23 16:33:07 build
-rwxr-xr-x  1 root root    49348 2025-08-14 19:12:11 config.guess
-rw-r--r--  1 root root   853601 2025-10-23 16:29:56 config.log
-rwxr-xr-x  1 root root    58775 2025-10-23 16:29:55 config.status
-rwxr-xr-x  1 root root    37009 2025-08-14 19:12:11 config.sub
-rwxr-xr-x  1 root root   893450 2025-08-14 19:12:11 configure
-rw-r--r--  1 root root   255942 2025-08-14 19:12:11 configure.ac
drwxr-xr-x 18 root root     4096 2025-08-14 19:12:11 Doc
drwxr-xr-x  2 root root     4096 2025-08-14 19:12:11 Grammar
drwxr-xr-x  4 root root     4096 2025-08-14 19:12:11 Include
-rwxr-xr-x  1 root root    15358 2025-08-14 19:12:11 install-sh
drwxr-xr-x  2 root root     4096 2025-08-14 19:12:11 InternalDocs
drwxr-xr-x  4 root root     4096 2025-08-14 19:12:11 iOS
drwxr-xr-x 39 root root     4096 2025-10-23 16:34:26 Lib
-rw-r--r--  1 root root 69097538 2025-10-23 16:34:28 libpython3.13.a
...


### 
root@frank:~# ls -lh  -d   Python-3.13.7
drwxr-xr-x 21 root root 4.0K 2025-10-23 16:34:28 Python-3.13.7

递归查看文件夹

递归查看文件内容 ,默认查看文件夹的内容只显示 文件夹里面的文件,目录,但是文件夹里面如果是目录,不会显示子目录的文件,

使用 -R 可以递归显示 文件夹,以及子文件的内容,以及子子文件夹的内容

如下面 看 直接文件夹 clinic, icons,layout ,

layout 文件夹中又有support 文件夹 , -R 会把每一级都列出来

bash 复制代码
root@frank:~/Python-3.13.7/PC# ls -l 
total 532
drwxr-xr-x  5 root root  4096 2025-08-14 19:12:11 ./
drwxr-xr-x 21 root root  4096 2025-10-23 16:34:28 ../
-rw-r--r--  1 root root  7020 2025-08-14 19:12:11 classicAppCompat.can.xml
-rw-r--r--  1 root root 10984 2025-08-14 19:12:11 classicAppCompat.cat
-rw-r--r--  1 root root 23092 2025-08-14 19:12:11 classicAppCompat.sccd
drwxr-xr-x  2 root root  4096 2025-08-14 19:12:11 clinic/
-rw-r--r--  1 root root  6118 2025-08-14 19:12:11 config.c
-rw-r--r--  1 root root  1760 2025-08-14 19:12:11 config_minimal.c
-rw-r--r--  1 root root  1738 2025-08-14 19:12:11 crtlicense.txt
-rw-r--r--  1 root root   808 2025-08-14 19:12:11 dl_nt.c
-rw-r--r--  1 root root  5132 2025-08-14 19:12:11 errmap.h
-rw-r--r--  1 root root  3986 2025-08-14 19:12:11 frozen_dllmain.c
drwxr-xr-x  2 root root  4096 2025-08-14 19:12:11 icons/
-rw-r--r--  1 root root   549 2025-08-14 19:12:11 invalid_parameter_handler.c
-rw-r--r--  1 root root 89995 2025-08-14 19:12:11 launcher2.c
-rw-r--r--  1 root root 67181 2025-08-14 19:12:11 launcher.c
-rw-r--r--  1 root root  1108 2025-08-14 19:12:11 launcher-usage.txt
drwxr-xr-x  3 root root  4096 2025-08-14 19:12:11 layout/
-rw-r--r--  1 root root 17214 2025-08-14 19:12:11 msvcrtmodule.c
-rw-r--r--  1 root root 22814 2025-08-14 19:12:11 pyconfig.h.in
-rw-r--r--  1 root root  1675 2025-08-14 19:12:11 pylauncher.rc
-rw-r--r--  1 root root 18744 2025-08-14 19:12:11 pyshellext.cpp
-rw-r--r--  1 root root   120 2025-08-14 19:12:11 pyshellext.def
-rw-r--r--  1 root root  1270 2025-08-14 19:12:11 pyshellext.rc
-rwxr-xr-x  1 root root 30185 2025-08-14 19:12:11 python3dll.c*
-rw-r--r--  1 root root  1314 2025-08-14 19:12:11 python_exe.rc
-rw-r--r--  1 root root  1319 2025-08-14 19:12:11 python.manifest
-rw-r--r--  1 root root  1258 2025-08-14 19:12:11 python_nt.rc
-rw-r--r--  1 root root  7377 2025-08-14 19:12:11 python_uwp.cpp
-rw-r--r--  1 root root   969 2025-08-14 19:12:11 python_ver_rc.h
-rw-r--r--  1 root root  1320 2025-08-14 19:12:11 pythonw_exe.rc
-rw-r--r--  1 root root  3141 2025-08-14 19:12:11 readme.txt
-rw-r--r--  1 root root  1426 2025-08-14 19:12:11 sqlite3.rc
-rw-r--r--  1 root root  6307 2025-08-14 19:12:11 store_info.txt
-rw-r--r--  1 root root  4533 2025-08-14 19:12:11 _testconsole.c
-rw-r--r--  1 root root  2757 2025-08-14 19:12:11 validate_ucrtbase.py
-rw-r--r--  1 root root 13531 2025-08-14 19:12:11 venvlauncher.c
-rw-r--r--  1 root root   492 2025-08-14 19:12:11 WinMain.c
-rw-r--r--  1 root root 68002 2025-08-14 19:12:11 winreg.c
-rw-r--r--  1 root root  7559 2025-08-14 19:12:11 winsound.c
-rw-r--r--  1 root root 11250 2025-08-14 19:12:11 _wmimodule.cpp


root@frank:~/Python-3.13.7/PC# ls -lR 
.:
total 524
-rw-r--r-- 1 root root  7020 2025-08-14 19:12:11 classicAppCompat.can.xml
-rw-r--r-- 1 root root 10984 2025-08-14 19:12:11 classicAppCompat.cat
-rw-r--r-- 1 root root 23092 2025-08-14 19:12:11 classicAppCompat.sccd
drwxr-xr-x 2 root root  4096 2025-08-14 19:12:11 clinic
-rw-r--r-- 1 root root  6118 2025-08-14 19:12:11 config.c
-rw-r--r-- 1 root root  1760 2025-08-14 19:12:11 config_minimal.c
-rw-r--r-- 1 root root  1738 2025-08-14 19:12:11 crtlicense.txt
-rw-r--r-- 1 root root   808 2025-08-14 19:12:11 dl_nt.c
-rw-r--r-- 1 root root  5132 2025-08-14 19:12:11 errmap.h
-rw-r--r-- 1 root root  3986 2025-08-14 19:12:11 frozen_dllmain.c
drwxr-xr-x 2 root root  4096 2025-08-14 19:12:11 icons
-rw-r--r-- 1 root root   549 2025-08-14 19:12:11 invalid_parameter_handler.c
-rw-r--r-- 1 root root 89995 2025-08-14 19:12:11 launcher2.c
-rw-r--r-- 1 root root 67181 2025-08-14 19:12:11 launcher.c
-rw-r--r-- 1 root root  1108 2025-08-14 19:12:11 launcher-usage.txt
drwxr-xr-x 3 root root  4096 2025-08-14 19:12:11 layout
-rw-r--r-- 1 root root 17214 2025-08-14 19:12:11 msvcrtmodule.c
-rw-r--r-- 1 root root 22814 2025-08-14 19:12:11 pyconfig.h.in
-rw-r--r-- 1 root root  1675 2025-08-14 19:12:11 pylauncher.rc
-rw-r--r-- 1 root root 18744 2025-08-14 19:12:11 pyshellext.cpp
-rw-r--r-- 1 root root   120 2025-08-14 19:12:11 pyshellext.def
-rw-r--r-- 1 root root  1270 2025-08-14 19:12:11 pyshellext.rc
-rwxr-xr-x 1 root root 30185 2025-08-14 19:12:11 python3dll.c
-rw-r--r-- 1 root root  1314 2025-08-14 19:12:11 python_exe.rc
-rw-r--r-- 1 root root  1319 2025-08-14 19:12:11 python.manifest
-rw-r--r-- 1 root root  1258 2025-08-14 19:12:11 python_nt.rc
-rw-r--r-- 1 root root  7377 2025-08-14 19:12:11 python_uwp.cpp
-rw-r--r-- 1 root root   969 2025-08-14 19:12:11 python_ver_rc.h
-rw-r--r-- 1 root root  1320 2025-08-14 19:12:11 pythonw_exe.rc
-rw-r--r-- 1 root root  3141 2025-08-14 19:12:11 readme.txt
-rw-r--r-- 1 root root  1426 2025-08-14 19:12:11 sqlite3.rc
-rw-r--r-- 1 root root  6307 2025-08-14 19:12:11 store_info.txt
-rw-r--r-- 1 root root  4533 2025-08-14 19:12:11 _testconsole.c
-rw-r--r-- 1 root root  2757 2025-08-14 19:12:11 validate_ucrtbase.py
-rw-r--r-- 1 root root 13531 2025-08-14 19:12:11 venvlauncher.c
-rw-r--r-- 1 root root   492 2025-08-14 19:12:11 WinMain.c
-rw-r--r-- 1 root root 68002 2025-08-14 19:12:11 winreg.c
-rw-r--r-- 1 root root  7559 2025-08-14 19:12:11 winsound.c
-rw-r--r-- 1 root root 11250 2025-08-14 19:12:11 _wmimodule.cpp

./clinic:
total 92
-rw-r--r-- 1 root root 18690 2025-08-14 19:12:11 msvcrtmodule.c.h
-rw-r--r-- 1 root root  2373 2025-08-14 19:12:11 _testconsole.c.h
-rw-r--r-- 1 root root 57495 2025-08-14 19:12:11 winreg.c.h
-rw-r--r-- 1 root root  2932 2025-08-14 19:12:11 winsound.c.h
-rw-r--r-- 1 root root  2140 2025-08-14 19:12:11 _wmimodule.cpp.h

./icons:
total 2160
-rw-r--r-- 1 root root  20537 2025-08-14 19:12:11 idlex150.png
-rw-r--r-- 1 root root   3473 2025-08-14 19:12:11 idlex44.png
-rw-r--r-- 1 root root 264476 2025-08-14 19:12:11 launcher.icns
-rw-r--r-- 1 root root  87263 2025-08-14 19:12:11 launcher.ico
-rw-r--r-- 1 root root   4476 2025-08-14 19:12:11 launcher.svg
-rw-r--r-- 1 root root   1871 2025-08-14 19:12:11 logo.svg
-rw-r--r-- 1 root root   1189 2025-08-14 19:12:11 logox128.png
-rw-r--r-- 1 root root 212125 2025-08-14 19:12:11 pyc.icns
-rw-r--r-- 1 root root  78396 2025-08-14 19:12:11 pyc.ico
-rw-r--r-- 1 root root   2878 2025-08-14 19:12:11 pyc.svg
-rw-r--r-- 1 root root 223199 2025-08-14 19:12:11 pyd.icns
-rw-r--r-- 1 root root  83351 2025-08-14 19:12:11 pyd.ico
-rw-r--r-- 1 root root   7604 2025-08-14 19:12:11 pyd.svg
-rw-r--r-- 1 root root 195977 2025-08-14 19:12:11 py.icns
-rw-r--r-- 1 root root  75809 2025-08-14 19:12:11 py.ico
-rw-r--r-- 1 root root   8534 2025-08-14 19:12:11 py.png
-rw-r--r-- 1 root root   2766 2025-08-14 19:12:11 py.svg
-rw-r--r-- 1 root root 201868 2025-08-14 19:12:11 python.icns
-rw-r--r-- 1 root root  77671 2025-08-14 19:12:11 python.ico
-rw-r--r-- 1 root root   2962 2025-08-14 19:12:11 python.svg
-rw-r--r-- 1 root root 193222 2025-08-14 19:12:11 pythonw.icns
-rw-r--r-- 1 root root  76102 2025-08-14 19:12:11 pythonw.ico
-rw-r--r-- 1 root root   3015 2025-08-14 19:12:11 pythonw.svg
-rw-r--r-- 1 root root   5085 2025-08-14 19:12:11 pythonwx150.png
-rw-r--r-- 1 root root   1844 2025-08-14 19:12:11 pythonwx44.png
-rw-r--r-- 1 root root   5232 2025-08-14 19:12:11 pythonx150.png
-rw-r--r-- 1 root root   1789 2025-08-14 19:12:11 pythonx44.png
-rw-r--r-- 1 root root   2154 2025-08-14 19:12:11 pythonx50.png
-rw-r--r-- 1 root root 220699 2025-08-14 19:12:11 setup.icns
-rw-r--r-- 1 root root  78328 2025-08-14 19:12:11 setup.ico
-rw-r--r-- 1 root root   3173 2025-08-14 19:12:11 setup.svg

./layout:
total 32
-rw-r--r-- 1 root root     0 2025-08-14 19:12:11 __init__.py
-rw-r--r-- 1 root root   371 2025-08-14 19:12:11 __main__.py
-rw-r--r-- 1 root root 23915 2025-08-14 19:12:11 main.py
drwxr-xr-x 2 root root  4096 2025-08-14 19:12:11 support

./layout/support:
total 76
-rw-r--r-- 1 root root 17927 2025-08-14 19:12:11 appxmanifest.py
-rw-r--r-- 1 root root  1049 2025-08-14 19:12:11 arch.py
-rw-r--r-- 1 root root   822 2025-08-14 19:12:11 catalog.py
-rw-r--r-- 1 root root  2635 2025-08-14 19:12:11 constants.py
-rw-r--r-- 1 root root  2667 2025-08-14 19:12:11 filesets.py
-rw-r--r-- 1 root root     0 2025-08-14 19:12:11 __init__.py
-rw-r--r-- 1 root root  1980 2025-08-14 19:12:11 logging.py
-rw-r--r-- 1 root root  2883 2025-08-14 19:12:11 nuspec.py
-rw-r--r-- 1 root root  4484 2025-08-14 19:12:11 options.py
-rw-r--r-- 1 root root  2213 2025-08-14 19:12:11 pip.py
-rw-r--r-- 1 root root  3853 2025-08-14 19:12:11 props.py
-rw-r--r-- 1 root root  8787 2025-08-14 19:12:11 pymanager.py
-rw-r--r-- 1 root root  2736 2025-08-14 19:12:11 python.props

Q1: 如何查看一个文件中 直接子文件夹有多少?

ls 配合g rep 过滤 d 这个目录属性

  • 每行开头的字符表示文件类型,d 表示目录。
  • grep '^d' 只保留以 d 开头的行。
bash 复制代码
root@frank:~/Python-3.13.7# ls -l |grep '^d'
drwxr-xr-x  3 root root     4096 2025-08-14 19:12:11 Android
drwxr-xr-x  4 root root     4096 2025-10-23 16:33:07 build
drwxr-xr-x 18 root root     4096 2025-08-14 19:12:11 Doc
drwxr-xr-x  2 root root     4096 2025-08-14 19:12:11 Grammar
drwxr-xr-x  4 root root     4096 2025-08-14 19:12:11 Include
drwxr-xr-x  2 root root     4096 2025-08-14 19:12:11 InternalDocs
drwxr-xr-x  4 root root     4096 2025-08-14 19:12:11 iOS
drwxr-xr-x 39 root root     4096 2025-10-23 16:34:26 Lib
drwxr-xr-x  8 root root     4096 2025-08-14 19:12:11 Mac
drwxr-xr-x  3 root root     4096 2025-10-23 16:29:55 Misc
drwxr-xr-x 18 root root    20480 2025-10-23 16:34:29 Modules
drwxr-xr-x  5 root root     4096 2025-10-23 16:33:32 Objects
drwxr-xr-x  4 root root     4096 2025-10-23 16:33:18 Parser
drwxr-xr-x  5 root root     4096 2025-08-14 19:12:11 PC
drwxr-xr-x  2 root root     4096 2025-08-14 19:12:11 PCbuild
drwxr-xr-x  2 root root     4096 2025-10-23 16:34:28 Programs
drwxr-xr-x  4 root root    12288 2025-10-23 16:34:27 Python
drwxr-xr-x 24 root root     4096 2025-08-14 19:12:11 Tools

ls -dl */

  • -d 表示"不展开目录内容",只列出目录本身。
  • */ 是一个通配符,匹配所有以 / 结尾的项(即目录)。
bash 复制代码
ls  -dl   */ 
drwxr-xr-x  3 root root  4096 2025-08-14 19:12:11 Android/
drwxr-xr-x  4 root root  4096 2025-10-23 16:33:07 build/
drwxr-xr-x 18 root root  4096 2025-08-14 19:12:11 Doc/
drwxr-xr-x  2 root root  4096 2025-08-14 19:12:11 Grammar/
drwxr-xr-x  4 root root  4096 2025-08-14 19:12:11 Include/
drwxr-xr-x  2 root root  4096 2025-08-14 19:12:11 InternalDocs/
drwxr-xr-x  4 root root  4096 2025-08-14 19:12:11 iOS/
drwxr-xr-x 39 root root  4096 2025-10-23 16:34:26 Lib/
drwxr-xr-x  8 root root  4096 2025-08-14 19:12:11 Mac/
drwxr-xr-x  3 root root  4096 2025-10-23 16:29:55 Misc/
drwxr-xr-x 18 root root 20480 2025-10-23 16:34:29 Modules/
drwxr-xr-x  5 root root  4096 2025-10-23 16:33:32 Objects/
drwxr-xr-x  4 root root  4096 2025-10-23 16:33:18 Parser/
drwxr-xr-x  5 root root  4096 2025-08-14 19:12:11 PC/
drwxr-xr-x  2 root root  4096 2025-08-14 19:12:11 PCbuild/
drwxr-xr-x  2 root root  4096 2025-10-23 16:34:28 Programs/
drwxr-xr-x  4 root root 12288 2025-10-23 16:34:27 Python/
drwxr-xr-x 24 root root  4096 2025-08-14 19:12:11 Tools/

总结

这个基本上就是ls 命令比较常用的功能,多多熟悉,多多练习就能慢慢熟练起来。 如果有写的不对,或者有疑问的地方 欢迎提出,一起探讨 。

参考文档

Linux command 菜鸟教程
分享快乐,留住感动. '2026-02-03 20:30:39' --frank

相关推荐
桌面运维家2 小时前
vDisk一键部署怎么应用?自动化脚本使用指南
运维·自动化
倔强的石头1062 小时前
【Linux指南】基础IO系列(一)Linux 文件本质揭秘 —— 从 “磁盘文件” 到 “一切皆文件”
linux·运维·服务器
robitmind2 小时前
操作input子系统,用模拟按键输入解锁ubuntu锁屏
linux·运维·ubuntu
Code小翊2 小时前
re标准库模块一天学完
运维·服务器·网络
2023自学中2 小时前
imx6ull , 4.3寸800*480屏幕,触摸芯片型号 gt9147,显示触摸点的坐标数据
linux·嵌入式硬件
Warren982 小时前
Allure 常用装饰器:实战用法 + 最佳实践(接口自动化)
运维·服务器·git·python·单元测试·自动化·pytest
2501_943695332 小时前
高职大数据运维与管理专业,怎么学习Hadoop的基础操作?
大数据·运维·学习
落羽的落羽2 小时前
【Linux系统】文件IO:理解文件描述符、重定向、缓冲区
linux·服务器·开发语言·数据结构·c++·人工智能·机器学习
xie_pin_an2 小时前
Linux 基础入门:从历史到核心指令全解析
linux·运维·服务器