ls
文件与目录
用法
ls -la [path]列出目录里有什么;以点开头的名字要加 -a 才会显示。
常用选项
| 选项 | 含义 |
|---|---|
| -l | One line per entry with mode, owner, size and time |
| -a | Include names that begin with a dot |
| -h | Sizes as 4.0K instead of 4096, together with -l |
| -t | Sort by modification time, newest first |
| -r | Reverse whatever order is in effect |
| -S | Sort by size, largest first |
| -R | Walk into subdirectories |
| -d | Show the directory itself instead of its contents |
示例
ls -lhLong listing with readable sizes.
ls -latNewest 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