官术网_书友最值得收藏!

  • Learn Linux Quickly
  • Ahmed AlKabary
  • 588字
  • 2021-06-11 18:43:43

The Linux filesystem

Alright, you are at the root of the tree and ready to climb up. In Linux, just like an actual tree, the beginning of the filesystem starts at the root directory. You can use the cd command followed by a forward slash to get to the root:

elliot@ubuntu-linux:~$ cd /

The cd command is short for Change Directory and is one of the most used commands in Linux. You can't move around in Linux without it. It's like your limbs (arms and legs), can you climb a tree without your limbs?
The forward slash character represents the root directory. Now to make sure you're at the root directory, you can run pwd:

elliot@ubuntu-linux:~$ pwd
/

And sure enough, we are at the root of the Linux filesystem. Whenever you are lost and you don't know where you are, pwd is here to rescue you.

Alright, while we are still at the root directory, let's see what's in there! Run the ls command to view the contents of the current directory:

elliot@ubuntu-linux:/$ ls
bin etc lib proc tmp var boot
dev home opt root sbin usr

To have a better view of the contents, you can use the long listing -l option with the ls command:

elliot@ubuntu-linux:/$ ls -l
drwxr-xr-x 2 root root 4096 Dec 28 15:36 bin
drwxr-xr-x 125 root root 12288 Jan 1 11:01 etc
drwxr-xr-x 21 root root 4096 Dec 26 23:52 lib
dr-xr-xr-x 227 root root 0 Jan 3 02:33 proc
drwxrwxrwt 15 root root 4096 Jan 3 02:35 tmp
drwxr-xr-x 14 root root 4096 Jul 24 21:14 var
drwxr-xr-x 3 root root 4096 Dec 29 07:17 boot
drwxr-xr-x 18 root root 4000 Jan 3 02:33 dev
drwxr-xr-x 3 root root 4096 Dec 26 23:47 home
drwxr-xr-x 3 root root 4096 Dec 27 15:07 opt
drwx------ 4 root root 4096 Dec 29 09:39 root
drwxr-xr-x 2 root root 12288 Dec 28 15:36 sbin
drwxr-xr-x 10 root root 4096 Jul 24 21:03 usr

This output gives you a lot of valuable information that we will discuss in detail in the upcoming chapters. But for now, we focus on the first letter in the first column of the output. Take a look at the first column of the output:

drwxr-xr-x 
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
.
.
.
.

You will see that the first letter is d, which means that the file is a directory. The first letter reveals the file type. The last column of the output displays the filename.

OTHER FILES!

You will have more files under your root (/) directory. I have only chosen the most important and common ones that should exist on every Linux distribution. So don't freak out when you see way more files than those listed in this book.

Now each one of these directories has a special purpose, as you can see in the following table:

Table 2: Linux Directories Explained

You can also run the man hier command to read more about the Linux filesystem hierarchy:

elliot@ubuntu-linux:/$ man hier

Alright, now let's do further climbing on the Linux directory tree. Take a look at figure 1, and you will understand why we choose a tree to describe the structure of the Linux filesystem.

Figure 1: The Linux directory tree

The preceding figure only features very few files and by no means is a representation for the whole directory tree, as the Linux filesystem literally contains thousands of files. So you can think of the preceding figure as a subtree of the actual Linux directory tree.

主站蜘蛛池模板: 昭平县| 土默特左旗| 霍邱县| 伊川县| 涿州市| 姚安县| 开江县| 西藏| 迁西县| 星座| 万山特区| 普兰店市| 奉新县| 黄冈市| 五大连池市| 贡嘎县| 马尔康县| 五寨县| 茂名市| 宝坻区| 乐至县| 尼勒克县| 确山县| 大荔县| 萍乡市| 尼勒克县| 南平市| 甘泉县| 黄大仙区| 巢湖市| 衡山县| 珲春市| 东阿县| 延津县| 平乐县| 合山市| 阳泉市| 防城港市| 当涂县| 新源县| 改则县|