首页·终端命令

ls

文件与目录

用法

ls -la [path]

列出目录里有什么;以点开头的名字要加 -a 才会显示。

常用选项

选项含义
-lOne line per entry with mode, owner, size and time
-aInclude names that begin with a dot
-hSizes as 4.0K instead of 4096, together with -l
-tSort by modification time, newest first
-rReverse whatever order is in effect
-SSort by size, largest first
-RWalk into subdirectories
-dShow the directory itself instead of its contents

示例

ls -lh

Long listing with readable sizes.

ls -lat

Newest first, hidden files included.

ls -d */

Only the directories in this folder.

移动、删除和查找。有些命令不会再问一遍,所以顺手加 -i 是在救自己。

怎么看

  • 方括号 [ ] 表示这部分可以不写。
  • 省略号 … 表示可以写多个。
  • 选项区分大小写——有些命令里 -r 和 -R 不是一回事。

常见问题

Q. ls 是做什么的?

列出目录里有什么;以点开头的名字要加 -a 才会显示。

Q. 怎么写?

ls -la [path] —— 方括号表示可以省略的部分。

Q. 值得记的选项有几个?

这里列了 8 个,完整列表在 man ls。这条命令属于文件与目录。

相关命令

man 手册: man ls