Linux目录系统与Windows不同,可能会使新用户感到困惑。所以把Linux目录结构想象成一棵树。树的根是它生长的地方,在Linux中,它是目录分支的地方。
目录分隔符是正斜杠 (/),缩写为slash。例如,根目录的路径通常称为斜杠 ( / )。
Linux 目录结构是什么?(What Is the Linux Directory Structure?)
对于熟悉Linux的人来说,您听说过root、lib和boot等术语。这些是Linux分发目录的示例。
Linux 系统使用文件系统层次标准(Filesystem Hierarchy Standard)( FHS )。它定义了所有Linux发行版的内容和目录结构。
基本导航(Basic Navigation)
如上所述,Linux 目录(Linux Directory)结构是指安装Linux的硬盘驱动器的文件夹。
首先运行ls (list storage) 命令,然后按Enter。此命令将向您显示当前工作目录中的文件夹列表。
请记住,每个发行版的主目录中都有不同的文件夹。
list 命令代表列表存储,但文件系统以单个正斜杠 (/) 开头,因此输入以下命令:
ls /
这将显示Linux文件系统的目录结构、硬盘驱动器的设置或默认文件夹结构。
每个文件夹都有指定的用途。主目录是用户所在的位置,因此请使用以下命令查看用户主目录中的内容。
ls /home
要清除屏幕,请键入clear或使用ctrl L。请记住,ctrl L可能不适用于所有Linux发行版,但clear命令可以。
让我们回到ls命令。这是了解和理解的最重要的命令。您想要列出您所在目录中的项目。
但是您也可以向ls添加其他命令。例如,键入ls -l / /不同的输出。尝试使用以下命令:
ls -l /
您可以在屏幕上看到更多信息。一切基本上都在自己的路线上。-l命令意味着查找长列表 。
这意味着您希望查看更多详细信息以及将每个项目放在单独的行上以使其更易于阅读。一些发行版将使用ll作为-l的别名来表示长列表命令。
您应该知道的重要文件夹(Important Folders You Should Know About)
你的Linux(Linux)系统中有很多文件夹。我们将在下面讨论最重要的一些。
主目录(The Home Directory)
默认情况下,主目录是所有用户都有自己的个人工作空间的地方。/home目录 中拥有自己的文件夹。
如果要查看主目录中所有文件夹的列表,请使用以下命令:
ls -l /home
因为您已经在您的主目录中,所以您也可以只使用ls来拉出里面的内容列表,而无需使用路径。
Linux目录结构中的每个目录都由正斜杠 (/)分隔并以正斜杠 ( / ) 开头。换句话说,没有路径的ls将显示当前目录的内容。
如果要更改正在工作的目录并返回文件系统的根目录,请使用以下命令:
cd /
如果要查看根目录中的目录,请使用:
ls
因为您回到了根目录而不是您的主目录,您将看到根目录中所有文件夹的列表。
要查看根目录中的长列表,请使用:
ls -l
The Root Directory (/root)
系统上的所有目录和文件都位于由符号/.根文件中。(root) 所有文件或目录都从根开始。任何文件或目录的路径将显示类似于以下内容:
Root/home/user/videos
根目录供单个用户使用,是Linux系统上最强大的用户。
Lib Directory Shared libraries (/lib)
/lib目录是包含代码(库)的文件所在的位置。这些文件包含用于将文件发送到硬盘驱动器、在桌面上绘制窗口或控制外围设备的代码片段。
Media Directory (/media)
媒体目录是您可以查看已安装的外部硬盘驱动器、拇指驱动器、DVD(DVDs)或蓝光光盘的数据文件的地方。
Boot Directory (/boot)
您的系统需要启动的文件和文件夹位于 /boot 目录中。它的使用在Filesystem Hierarchy Standard中被标准化。
引导机器所需的配置位于引导目录中。你不想摆脱这个目录。
其他一些标准目录包括:
- /dev是所有设备文件所在的位置,例如外部USB或网络摄像头。
- /var是变量的缩写。它是程序存储运行时信息的地方,例如用户跟踪、系统日志记录、缓存以及系统程序管理和创建的其他文件。
- 用户的个人目录位于/home。
- /proc包含有关您的系统的信息,例如CPU和您的Linux系统内核。它是一个虚拟系统。
- /bin是所有基本可运行程序(用户二进制文件)所在的位置。
- /etc 文件夹包含配置文件。
阅读 Wikipedia 的摘要(Read Wikipedia’s summary),了解每个目录是什么以及如何使用它的完整分类。
查看您当前的目录(See Your Current Directory)
如果您不知道您在哪个目录中工作,请使用命令pwd(打印工作目录)。
结果将如下所示:
/home/username
如果您随后运行ls,默认设置将显示您当前所在文件夹的内容,如上所述。
颜色是什么意思?(What Do The Colors Mean?)
假设您在/etc文件夹中并运行以下命令:
ls -l /etc
您将看到很多信息以及许多不同的颜色。
一般的经验法则是:
颜色可能因分布而异。大多数(但不是全部)发行版都带有预设颜色。
什么是权限字符串?(What Are Permission Strings?)
每个文件的列表左侧都有一个字母流。它被称为权限字符串。
查看字符串中的第一个字符。d表示目录。所以,即使你的Linux发行版没有使用不同的颜色,你仍然会知道以(Linux)d开头的字符串是一个目录。
文件和程序以连字符 (-) 开头。
l指的是链接到另一个文件的链接。
快速导航概述(Quick Navigation Overview)
ls命令列表存储向您显示当前工作目录中的内容。如果您不知道当前目录是什么,请使用pwd命令。
文件系统的开头由单个正斜杠 (/) 指定。使用cd命令在目录之间切换。要查看刚刚切换到的目录中的内容,请使用ls命令。然后,要返回您的主目录,请键入/home/username。
cd命令可帮助您浏览文件系统。ls显示您正在工作的当前目录中的内容。ls -1显示长列表。
尽管各种Linux发行版有细微差别,但文件系统布局非常相似。了解Linux目录结构的最好方法是遵循上面的一些建议并熟悉它的工作原理。
请确保不要(NOT)触摸 /boot 目录。练习(Practice)使用终端浏览系统。坚持(Stick)使用cd、ls和pwd命令,以免破坏任何内容。您很快就会直观地知道在哪里可以找到您需要使用的文档、应用程序和其他资源。
How To Navigate & Use the Linux Directory Structure
Linux directory systems are different from Windows and may confuse new users. So think of the Linux directory structure as a tree. The root of the tree is where it grows frоm and in Linux, it is where the directorieѕ brаnch out.
The directory separator is the forward-slash (/), abbreviated as slash. For example, the path to the root directory is often referred to as slash ( /).
What Is the Linux Directory Structure?
For those who are familiar with Linux, you have heard terms such as root, lib, and boot. These are examples of Linux distribution directories.
Linux systems use a Filesystem Hierarchy Standard (FHS). It defines the content and directory structure of all Linux distributions.
Basic Navigation
As mentioned above, the Linux Directory structure refers to the folder of the hard drive where Linux was installed.
Start by running the ls (list storage) command and press Enter. This command will show you a list of folders in your current working directory.
Keep in mind that each distribution comes with different folders in the home directory.
The list command stands for list storage, but the file system starts with a single forward-slash (/) so enter the following command:
ls /
This will show you the directory structure of the Linux file system, the setup of the hard drive, or the default folder structure.
Each folder has a designated purpose. The home directory is where the users are, so use the following command to see what’s in your user home directory.
ls /home
To clear the screen, type clear or use ctrl L. Keep in mind that ctrl L might not work on all Linux distributions, but the clear command will.
Let’s go back to the ls command. It is the most important command to know and understand. You want to list the items in a directory where you are located.
But you can also add additional commands to ls. For example, typing ls -l / displays a different output than just /. Try it by using the following command:
ls -l /
You can see a lot more information on the screen. Everything is basically on its own line. The -l command means to look for the long listing.
This means you want to see more details as well as every item to be on a separate line to make it easier to read. Some distributions will use ll as an alias for -l for the long list command.
Important Folders You Should Know About
There are a lot of folders in your Linux system. We will discuss the most important ones below.
The Home Directory
The home directory is by default where all users have their own personal working space. Each user will have their own folder in the /home directory.
If you want to see a listing of all the folders in your home directory, use the following command:
ls -l /home
Because you are already in your home directory, you can also just use ls to pull up a list of what’s inside without using a path.
Every directory in the Linux directory structure is separated by and starts with a forward slash (/). In other words, ls without a path will show the contents of your current directory.
If you want to change the directory you are working in and go back to the root of the file system, use the following command:
cd /
If you want to see the directories in the root, use:
ls
Because you are back in the root directory and not your home directory, you will see a list of all the folders in the root.
To see the long list in the root directory, use:
ls -l
The Root Directory (/root)
All directories and files on your system reside in the root file represented by the symbol /. All files or directories start at the root. The path of any file or directory will be displayed similar to the following:
Root/home/user/videos
The root directory is for a single user and is the most powerful user on a Linux system.
Lib Directory Shared libraries (/lib)
The /lib directory is where files containing code (the libraries) are located. These files house the code snippets used to send files to your hard drive, draw windows on your desktop, or control peripherals.
Media Directory (/media)
The media directory is where you can see the data files of mounted external hard drives, thumb drives, DVDs, or Blu-ray disks.
Boot Directory (/boot)
The files and folders your system needs to start are in the /boot directory. Its usage is standardized in the Filesystem Hierarchy Standard.
The configuration needed to boot your machine lives in the boot directory. You don’t want to get rid of this directory.
Some other standard directories include:
- /dev is where all device files live, such as an external USB or a webcam.
- /var is short for variable. It is where programs store runtime information such as user tracking, system logging, caches, and other files that system programs manage and create.
- Users’ personal directories are in /home.
- /proc contains information about your system such as CPU and your Linux system kernel. It is a virtual system.
- /bin is where all the essential runnable programs (user binaries) live.
- /etc folder contains the configuration files.
Read Wikipedia’s summary for a full breakdown of what each directory is and how it is used.
See Your Current Directory
If you don’t know which directory you are working in, use the command pwd (print working directory).
The results will look like this:
/home/username
If you then run ls, the default setting will show you the contents of the folder you are currently in, as described above.
What Do The Colors Mean?
Let’s say you are in the /etc folder and run this command:
ls -l /etc
You will see a lot of information as well as many different colors.
The general rule of thumb is that the:
- Blue is a folder
- White is a file
- Green is a program or a binary
The colors may vary by distribution. Most, but not all, distros come with pre-set colors.
What Are Permission Strings?
Every file has a stream of letters to the left of the listing. It is called a permission string.
Look at the first character in the string. The d means directory. So, even if your Linux distro doesn’t use different colors, you will still know that a character string that begins with d is a directory.
Files and programs start with a hyphen (-).
An l refers to a link that links to another file.
Quick Navigation Overview
The ls command list storage shows you what is in your current working directory. If you don’t know what your current directory is, use the pwd command.
The beginning of the file system is designated by a single forward-slash (/). Use the cd command to switch between directories. To see what’s in the directory you just switched to, use the ls command. Then, to go back to your home directory, type /home/username.
The cd command helps you navigate the file system. ls shows you what is in the current directory where you are working. ls -1 shows you the long listing.
Even though various Linux distributions have minor differences, the file system layouts are very similar. The best way to understand the Linux directory structure is to follow some of the above suggestions and familiarize yourself with how it works.
Just be sure NOT to touch the /boot directory. Practice navigating through your system using the terminal. Stick to the cd, ls, and pwd commands so that you don’t break anything. It won’t take long for you to intuitively know where to find documentation, apps and other resources you need to use.