使用 Linux 终端查看你的电脑上有哪些文件
ls

> 
> 通过这个 Linux 教程学习如何使用 ls 命令在终端中列出文件。
> 
> 
> 


![](/data/attachment/album/202108/11/142450etebpqtp7bl4kupt.jpg "List files on your computer")


要在有图形界面的计算机上列出文件，你通常可以打开一个文件管理器（Linux 上的 “文件”，MacOS 上的 “访达”，Windows 上的 “文件资源管理器”）来查看文件。


要在终端中列出文件，你可以使用 `ls` 命令来列出当前目录中的所有文件。而 `pwd` 命令可以告诉你当前所在的目录：



```
$ pwd
/home/tux
$ ls
example.txt
Documents
Downloads
Music
Pictures
Templates
Videos

```

你可以通过 `--all`（简写为 `-a`） 选项看到隐藏文件：



```
$ pwd
/home/tux
$ ls --all
.               Downloads
..              .local
.bashrc         Music
.config         Pictures
example.txt     Templates
Documents       Videos

```

如你所见，列出的前两项是点。单个点（`.`）实际上是一个元位置，代表 *你当前所在的文件夹* 。两个点（`..`）表示你可以从当前位置返回的上级目录。也就是说，当前目录在另一个文件夹中。当你在计算机目录间移动时，你就可以利用这些元位置为自己创建快捷方式，或者增加你的路径的独特性。


### 文件和文件夹以及如何区分它们


你可能会注意到，文件和文件夹是很难区分的。一些 Linux 发行版有一些漂亮的颜色设置，比如所有的文件夹都是蓝色的，文件是白色的，二进制文件是粉色或绿色的，等等。如果你没有看到这些颜色，你可以试试 `ls --color`。如果你有色盲症或者使用的不是彩色显示器，你可以使用 `--classify` 选项替代：



```
$ pwd
/home/tux/Downloads
$ ls --classify
android-info.txt
cheat/
test-script.sh*

```

你会发现，文件夹末尾加了一个斜杠（`/`），以表示它们是文件系统中的某一级目录。而二进制文件，如压缩文件和可执行程序，用星号（`*`）标记。




---


via: <https://opensource.com/article/21/8/linux-list-files>


作者：[Seth Kenlon](https://opensource.com/users/seth) 选题：[lujun9972](https://github.com/lujun9972) 译者：[piaoshi](https://github.com/piaoshi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
To list files on a computer with a graphical interface, you usually open a file manager (**Files** on Linux, **Finder** on MacOS, **Windows Explorer** on Windows), and look at the files.

To list files in a terminal, you use the **ls** command to list all files in the current directory. The **pwd** commands tells you what directory you're currently in.

```
$ pwd
/home/tux
$ ls
example.txt
Documents
Downloads
Music
Pictures
Templates
Videos
```


You can view hidden files with the **--all** option:

```
$ pwd
/home/tux
$ ls --all
. Downloads
.. .local
.bashrc Music
.config Pictures
example.txt Templates
Documents Videos
```



As you can see, the first items listed are dots. The single dot is actually a meta location meaning *the folder you are currently in*. The two dots indicate that you can move back from this location. That is, you are in a folder in another folder. Once you start moving around within your computer, you can use that information to create shortcuts for yourself or to increase the specificity of your paths.

## Files and folders and how to tell the difference

You may notice that it's hard to tell a file from a folder. Some Linux distributions have some nice colors set up so that all folders are blue and the files are white and binary files are pink or green, and so on. If you don't see those colors, you can try **ls --color**. If you're color blind or on a display that doesn't provide colors, you can alternately use the **--classify** option:

```
$ pwd
/home/tux/Downloads
$ ls --classify
android-info.txt
cheat/
test-script.sh*
```


As you can see, folders are given a trailing slash (`/`

) to denote that they are steps within your file system. Binary entities, like zip files and executable programs, are indicated swith an asterisk (`*`

).

## Comments are closed.