Linux introductory learning, directory command processing and the concepts of owner, group, and others - (2)

Introduction: Review of the last issue

        After learning from the previous chapter, I believe that most of the small partners should, probably, maybe have learned how to install VMware virtual machines and install Linux systems ? If you do not understand or the installation fails, welcome to consult. The system installation is done, and then it's time for us to type commands. There are more than 3,000 commands in the Linux system , but not all of these 3,000 commands are used. This article will also teach you some tips for memorizing commands so that you can use commands easily. I would like to remind everyone here that in the learning process, I hope you will tap the learning commands more often.

1. Learn the basic format of commands

         Let's learn the basic format of the command first. The command is divided into three parts , command [-option] [parameter] , when we enter the command, the options and parameters can be omitted , not mandatory.

    Note: 1. Our general commands follow the format of the above commands, and there are individual commands that do not follow this format.
    2. There are multiple options that can be written together, "-" represents options.
    3. The parameter can be an object or a directory.
    4. Options and parameters are optional. You can enter commands with or without options and parameters.

          Let's first look at a command we often use, such as: " ls -l / ", which is a command to view a directory

          Let's take this command apart and look at it, "ls" : This is a command to view directories, just like if you say to the linux system: "I want to see what files or folders are in these directories", then the linux system Just obediently display the files or folders in the directory, but we only see the file name, so what should we do if we want to see more information? Then we add the "-l" option to tell the linux system: "I need to see the detailed file or folder information in the directory", as long as you enter the command correctly, linux is still very obedient and listens to you. The detailed information of the files or folders in the directory comes out, but we can't keep looking at the files in this directory. The Linux system is so big and there are many directories in many places that we are not familiar with. At this time, we add a third Parameter "/" , you can view the files , "/" represents the root directory .

            

            As shown in the figure above, we can see that there are many folders in the root directory. What are these folders used for? Here I explain what several directories are used for:

                 1. "/" : The root directory is the topmost directory, and there is no upper level.

                 2. "/home" : The home directory of each user. When we create a new user, a folder named after the username will be created in the home directory.

                 3. "/tmp" : Where to temporarily store files.

                 4. "/bin" : The directory where the command is stored.

                 5. "/boot" : The startup directory, which contains files related to system startup.

                 6. "/root " :root用户的家目录,如果是用root账号登陆,起始目录就是在root文件下

                 7. 暂时了解以上目录就可以了,说多了大家也不一定都能记住,感兴趣的童鞋可以百度一下。          

二 详细介绍ls目录命令处理演示

        目录处理命令:ls ,全英文含义是:list ,这样方便大家记忆和理解

              1.查看目录下的隐藏文件:ls -a

             大家登陆后我们可以尝试输入"ls"命令然后回车查看当前目录下有什么文件或者文件夹。想必大家都知道windows中有隐藏文件,那同样在Linux中也是有隐藏文件的,那怎么查看隐藏文件呢? 只要我们在ls命令后加上一个-a的选项就可以查看到当前目录下全部的文件,在linux系统中隐藏文件的文件名是以"."开始的(如下图)。 在这里我给大家普及一下隐藏文件的意义是什么?大多数童鞋都是认为隐藏文件就是不想让别人看到,这样我们就可以把这个文件隐藏起来,别人就找不到。但隐藏文件最起始的目的是为了告诉用户这个隐藏文件是系统的文件不要随意去更改这些文件。

            在这里也跟大家分享一个小知识,我们现在所输入的"-a",只是一个简化选项还有完整选项 ,"-a"的完整选项是"--all",意思就是"-a"的效果等于"--all",大家也可以尝试一下效果肯定是一样的,一般我们也只是敲简化选项,大家只要知道有简化选项和完整选项的概念就好了。

         

              2.查看详细的文件或者文件夹信息:ls -l

              我们查看文件或者文件夹仅仅只是查看一个文件名,如果我们想要看更多详细信息呢?比如说想要看这个文件的大小是多少什么时候修改的,这个时候我们只要加上"-l"的选项l的原意是"long",这样我们就可以看到详细信息了。这个时候我们需要查看这个目录下全部文件的信息怎么写命令呢? 答案就是"ls -al",这条命令是查看当前目录下的全部文件的详细信息,那需要查看其他目录下的文件呢?那我们只需要加上命令的参数,比如我们需要查看tmp目下的文件信息,只要输入"ls -al /tmp",就可以了。

              

            3.更加人性化的显示详细信息:ls -h

            "-h"这个选项就是为了显示目录详细信息更加人性化,什么是更加人性化呢?比如我们看上图打印出来的文件或文件夹的相信信息其中第一个文件有一个"4096",其实这个就是代表文件大小,我们知道windoes中文件大小一般是显示多少M,或者多少K,这个时候我们加上"-h",我们再来看有什么变化,由原来的"4096"很人性化的显示成了"4.0k",这样大家一眼就知道这个是代表文件大小了。

            

             在这里我跟大家解释一下打印出来的文件或者文件夹的详细信息的几个参数分别代表什么意思:

              比如说 drwxr-xr-x   2   root   root   4.0k   2月   28  15:39   hsperfdata_root

              这里一共是7部分组成的,我们拆开来解释

                  1.drwxr-xr-x,我们拆成四部分来看d  rwx  r-x  r-x,首先第一个字母"d",d的英文原意是driectroy目录的意思,就代表着这个文件是个目录文件。这个第一个字母也可以是"l"、"-",如果是第一字母是"l",代表这是个软链接文件,英文原意是link,软链接这个技术我们以后会讲。如是"-",代表这是一个二进制文件。第二部是rwx,代表着所有者(什么是所有者?看下文)有什么权限,r代表"读",w代表"写",x代表"执行",由三个字母组成,那么这里的意思就是这个文件的所有者可以对文件有读写和执行的权限,再往后看第三部分 r-x,是代表所属组拥有什么权限,这里的意思是所属组可以对这个有读和执行的权限,但是没有写的权限大家可以看见中间是"-",代表着没有写的权限最后的r-x,代表着其他人可以对文件有读和执行的权限,也是没有写的权限。

                     我们在多举几个例子让大家更加清楚

                      drwxrwxr-x:这是一个目录文件,所有者和所属着都有读写和执行,但是其他人只有读和执行的权限。

                      -rwxrwxrwx:这是一个二进制文件,所有者、所属组、其他人都有读写和执行的权限。

                      lrwx------:这是一个软链接文件,所有者拥有读写和执行的权限,所属组、其他人都没有对该文件进行任何操作的权限。

               2."2",这个2代表的是一个引用技术,代表这个文件曾经被引用了几次,这里大家只要知道这是个引用技术就可以了。

                   3.root,代表这个文件的所有者是谁,那么这里这个文件的所有者是root。

                   4.root,代表这个文件的所属组是谁,这个文件的所属组是root。

                   5."4.0k",代表这个文件大小

                   6. 2月   28  15:39,代表这个文件的修改时间,在linux系统中只有文件的修改时间,没有创建时间的概念。

                7.hsperfdata_root,最后一部分就是文件的文件名称了。

          

          4.显示每个文件的i节点:ls -i

                在linux中每个文件都有一个属于自己的i节点,就相当于人的身份证号一样,但是i节点可以对应多个文件,当我们选项当中有-i,每个文件的相对应的i节点就可以被显示出来如下图。

                

三 所有者、所属组、其他人的概念

        所有者:这个很容易理解,我创建了这个文件,我就是这个文件所有者。但是这个所有者也是可以转换的,比如说小明买了一台笔记本电脑老贵了,小明就是这台笔记本的所有者,毕竟花了大价钱买来的。用了几个月小明觉得这台笔记本并不是很好,于是就卖给了张三,这个时候这台电脑的所有者就发生了改变,原来笔记本的所有者是小明,但由于小明卖给了张三,现在就是这台笔记本的所有者就是张三了。

        所属组:组很明显不止一个人,是多个人一起的。我们电脑上有一些开发手册,这些手册是给我们的开发组看的,所以我们这开发组的几个成员都可以自己查看这些开发手册。

       其他人:既不属于所有者,也不属于所属组之外的成员,就可以理解为其他人。


四 总结

       这章我们学习我们在linux常用的目录处理命令"ls",和相对应的选项-a 选项是代表显示目录下全部的文件或者文件夹、-l 显示出文件或者文件夹的详细信息、-h 更加更人性化的显示出信息 、-i 显示出每个文件或者文件夹的i节点,以及在linux系统中所有者、所属组、其他人的感念。可能有些细节方面小编可能说的不太明白,希望大家提提意见,小编会即使做出相对应的修改。还是那一句话学习贵在坚持,有不懂的地方可以留言也可以私聊我,祝大家学习愉快。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325540461&siteId=291194637