Entering the Linux world [3. Linux files and paths]

Linux system learning

Entering the Linux world [1. Overview of Linux]

Entering the Linux world [2. VM and Linux installation]

Entering the Linux world [3. Linux files and paths]

Enter the Linux world [4, Linux basic commands 1]

Enter the Linux world [5, Linux basic commands 2]

Enter the Linux world [6, Linux editor vim]

Enter the Linux world [7, Linux network and snapshot and clone]

Enter the Linux world [eight, Linux shell commands]

Entering the Linux world [Nine, Linux software installation]

Chapter 3 Linux Files and Paths

1. File structure

​ Differences between Windows and Linux file systems

​ On the Windows platform, open "This Computer", we can see the drive letter partition

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-VmGdI1Yg-1689062931409)(imgs/04_107.png)]

​ Each drive has its own root directory structure, which forms a situation where multiple trees are juxtaposed

​ But under Linux, we can't see these drive letters, what we see are folders (directories):

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-Y7NaqX9h-1689062931410)(imgs/04_108.png)]

​ Centos does not have the concept of a drive letter, there is only one root directory /, and all files are under it

[root@localhost ~]# ls /
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

​ When we enter ls /, we can view the files in the directory and view the system files in the root directory

Table of contents illustrate Remark
bin Store executable instructions for ordinary users Ability to perform processing even in single-user mode
boot boot directory Including the Linux kernel file and the files required for booting
dev Equipment catalog All hardware devices and peripherals are placed in this device directory
etc Various configuration file directories Most configuration properties are stored here
lib/lib64 Commonly used dynamic link libraries at boot time The bin and sbin instructions will also call the corresponding lib library
media Removable device mount directory Temporary hanging directory like floppy disk, U disk, CD, etc.
mnt User temporarily mounts other file systems Additional devices can be mounted here, relatively temporarily
opt Third-party software installation directory Now habitually placed in /usr/local
proc virtual file system Usually it is a mapping in memory. Pay special attention to deleting data files by mistake, such as DB, as long as the system does not restart, there is still a high probability that the data can be retrieved
root sysadmin home directory Except root, other users are placed in the /home directory
run System operation is the required file It was previously prevented from being in /var/run, and later split into a separate /run directory. Regenerate the corresponding directory data after restarting
sbin Administrative commands that only root can run Similar to bin, but only belongs to the root administrator
srv The data directory that needs to be accessed after the service starts
sys Virtual file system like proc Record core system hardware information
tmp Store temporary files directory All users can read and write this directory
usr application placement directory
was Store files that are frequently changed during system execution

​ In the Linux system, several directories are more important, and you need to be careful not to accidentally delete or change internal files at will.

​/ etc : As mentioned above, this is the configuration file in the system. If you change a file in this directory, the system may not start.

​/ bin, /sbin, /usr/bin, /usr/sbin : This is the directory where the system presets the execution files. For example, ls is in the /bin/ls directory.

​ It is worth mentioning that /bin, /usr/bin are commands for system users (common users except root), while /sbin, /usr/sbin are commands for root.

​/ var : This is a very important directory. There are many programs running on the system, and each program will have a corresponding log, and these logs will be recorded in this directory, specifically in the /var/log directory. In addition, the default placement of mail is also here.

2. Basic concepts

​User directory: located in /home/user, called the user's working directory or home directory, expressed as:

# 在home有一个user  这里就是之前创建的msb123用户
[root@localhost ~]# cd /home
[root@localhost home]# ls
msb123

# 使用~回到root目录,使用/是回到根目录下
[root@localhost msb123]# cd ~
[root@localhost ~]# 


​login information

[root@localhost /]#

Linux的bash解析器终端用来显示主机名和当前用户的标识;

# root表示bai当前用户叫root(系统管理员账户)
# localhost表示当前使用的主机名叫localhost(没有设置系bai统名字的时候默认名称是localhost)
# / 表示你当前所处的目录位置 (这里的'/'表示你当前在根目录下)

​Relative and absolute paths

​absolute path

​ The path described starting from the / directory is an absolute path, such as:

[root@localhost /]# cd /home/msb123
[root@localhost /]# ls /usr

​relative path

​ The path described starting from the current location is a relative path, such as:

[root@localhost /]# cd ../../
[root@localhost /]# ls abc/def

​. and…

​ Each directory has **. and …**

. 表示当前目录

.. 表示上一级目录,即父目录

​ For example, when switching paths here

# 从 / 根目录切换到 home目录
[root@localhost /]# cd home

# 确认路径/home
[root@localhost home]# pwd
/home

# 切换到当前目录cd .  目录无变化
[root@localhost home]# cd .

# 切换到当前目录cd ..  目录回到上一级根目录
[root@localhost home]# cd ..

[root@localhost /]# 

(Note that . and ... in the root directory both indicate the current directory )

​File permissions

​ File permissions are the access control permissions of files, that is, which users and groups can access files and what operations they can perform.

​ The Unix/Linux system is a typical multi-user system. Different users are in different positions and have different access rights to files and directories. In order to protect the security of the system, the Unix/Linux system not only strictly defines user rights, but also carefully controls user identity authentication, access control, transmission security, and file read and write permissions.

​ Every file or directory in Unix/Linux contains access permissions, which determine who can access and how to access these files and directories.

​Access user

​ Access permissions can be restricted from the following three access methods by setting permissions:

- 只允许用户自己访问(所有者) 所有者就是创建文件的用户,用户是所有用户所创建文件的所有者,用户可以允许所在的用户组能访问用户的文件。
- 允许一个预先指定的用户组中的用户访问(用户组) 用户都组合成用户组,例如,某一类或某一项目中的所有用户都能够被系统管理员归为一个用户组,一个用户能够授予所在用户组的其他成员的文件访问权限。
- 允许系统中的任何用户访问(其他用户) 用户也将自己的文件向系统内的所有用户开放,在这种情况下,系统内的所有用户都能够访问用户的目录或文件。在这种意义上,系统内的其他所有用户就是 other 用户类

​Access rights

​ Users can control the level of access to a given file or directory. A file or directory may have read, write, and execute permissions:

- ​        读权限(r) 对文件而言,具有读取文件内容的权限;对目录来说,具有浏览目录的权限。
- ​        写权限(w) 对文件而言,具有新增、修改文件内容的权限;对目录来说,具有删除、移动目录内文件的权限。
- ​        可执行权限(x) 对文件而言,具有执行文件的权限;对目录了来说该用户具有进入目录的权限。

​ Note: Usually, Unix/Linux systems only allow the owner (owner) or superuser of the file to change the read and write permissions of the file.

[root@localhost /]# ls -l
总用量 20
lrwxrwxrwx.   1 root root    7 831 15:48 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 831 15:58 boot
...

​ Let's disassemble the structure, here I only list part of the contents of the root directory

​ Use the ls -l command to view detailed information in the current folder, specific commands and parameters, which will be explained in depth later

​ What we need to pay attention to is the permission of the file or directory

l  rwx  rwx  rwx
d  r-x  r-x  r-x

# 首先第一个字母 在Linux中第一个字符代表这个文件是目录、文件或链接文件等等。
[ d ] 表示目录
[ l ] 表示为链接文档(link file)
[ - ] 表示为文件
[ b ] 表示为装置文件里面的可供储存的接口设备(可随机存取装置)
[ c ] 表示为装置文件里面的串行端口设备,例如键盘、鼠标(一次性读取装置)

# 其次接下来的字符中,以三个为一组,且均为 [ rwx ] 的三个参数的组合
[ r ]代表可读(read)
[ w ]代表可写(write)
[ x ]代表可执行(execute)
[ - ]

# 要注意的是,这三个权限的位置不会改变,如果没有权限,就会出现减号[ - ]而已。

  此时问题来了那么这三组一样是有什么区分尼?
# 这里就涉及到刚才所描述的访问用户权限
# 所有者    所有者表示该文件的所有者
# 用户组    表示当前用户再同一组
# 其他用户  允许系统中的任何用户访问,系统内的其他所有用户就是 other 用户类

# 可以将这个权限进行类比,如我的篮球,
# 所有者表示的是我可以玩 
# 用户组表示,我可以借给我同班同学玩
# 其他用户表示,我可以借给其他班的同学玩

​File owner and group

​ For a file, it has a specific owner, that is, the user who has ownership of the file.

​ At the same time, in the Linux system, users are classified by group, and a user belongs to one or more groups.

​ Users other than the file owner can be divided into users in the same group as the file owner and other users.

Therefore, the Linux system specifies different file access permissions according to the file owner, the user in the same group as the file owner, and other users.

[root@localhost /]# ls -l
总用量 20
...
dr-xr-xr-x.   5 root root 4096 831 15:58 boot
...

[root@localhost /]# cd /home
[root@localhost home]# ls -l
总用量 0
drwx------. 2 msb123 msb123 83 92 15:54 msb123


# 在以上实例中,msb123 文件是一个目录文件,属主和属组都为 msb123,属主有可读、可写、可执行的权限;与属主同组的用户无权限读写执行;其他用户也无权限读写执行

# 对于 root 用户来说,一般情况下,文件的权限对其不起作用。

3. Basic command information

​ Familiar with some introductory commands

​ 1、ls

ls 命令


作用:Linux ls命令用于显示指定工作目录下之内容(列出目前工作目录所含之文件及子目录)。



语法: ls   [-alrtAFR](选项)    [name...](参数)



参数:

-a 显示所有文件及目录 (ls内定将文件名或目录名称开头为"."的视为隐藏档,不会列出) 示例如下:
[root@localhost ~]# ls -a
.  ..  anaconda-ks.cfg  .bash_history  .bash_logout  .bash_profile  .bashrc  .cshrc  .tcshrc




-l 除文件名称外,亦将文件型态、权限、拥有者、文件大小等资讯详细列出  示例如下:
[root@localhost ~]# ls -l
总用量 4
-rw-------. 1 root root 1437 831 15:54 anaconda-ks.cfg




-r 将文件以相反次序显示(原定依英文字母次序) 示例如下:
[root@localhost ~]# ls -ra
.tcshrc  .cshrc  .bashrc  .bash_profile  .bash_logout  .bash_history  anaconda-ks.cfg  ..  .




-t 将文件依建立时间之先后次序列出   示例如下:
[root@localhost ~]# ls -lt
总用量 4
-rw-------. 1 root root 1437 831 15:54 anaconda-ks.cfg




-A-a ,但不列出 "." (目前目录)".." (父目录)   示例如下:
[root@localhost ~]# ls -A
anaconda-ks.cfg  .bash_history  .bash_logout  .bash_profile  .bashrc  .cshrc  .tcshrc




-F 在列出的文件名称后加一符号;例如可执行档则加 "*", 目录则加 "/"   示例如下:
[root@localhost ~]# ls -F /home
msb123/




-R 若目录下有文件,则以下之文件亦皆依序列出  示例如下:
[root@localhost ~]# ls -R /home
/home:
msb123

/home/msb123:

常用组合
[1]查看文件详情:ls -l 或 ll
[2]增强对文件大小易读性,以人类可读的形式显示文件大小: ls -lh
[3]对文件或者目录进行从大到小的排序: ls -lhs
[4]查看当前目录下的所有文件或者目录,包括隐藏文件: ls -la
[5]只查看当前目录下的目录文件: ls -d .
[6]按照时间顺序查看,从上到倒下时间越来越近: ls -ltr
[7]查看文件在对应的inode信息:ls -li

​ 2、cd

cd 命令


作用:变换当前目录到dir。默认目录为home,可以使用绝对路径、或相对路径。


语法:cd [dir](路径)

# 跳到用户目录下
[root@localhost ~]# cd /home/msb123
[root@localhost msb123]# 
 
 

# 回到home目录
[root@localhost msb123]# cd ~
[root@localhost ~]# 



# 跳到上次所在目录
[root@localhost ~]# cd -
/home/msb123
[root@localhost msb123]#



# 跳到父目录(也可以直接使用 cd ..)
[root@localhost msb123]# cd ./..
[root@localhost home]# 



# 再次跳到上次所在目录
[root@localhost home]# cd -
/home/msb123
[root@localhost msb123]# 


# 跳到当前目录的上两层
[root@localhost msb123]# cd ../..
[root@localhost /]#




# 把上个命令的最后参数作为dir
这里我们先将文件夹cd 到python2.7路径
[root@localhost /]# cd /usr/include/python2.7/
[root@localhost python2.7]#

# 这里使用cd ./..参数作为引子
[root@localhost python2.7]# cd ./..

# 这里我们使用命令,重复最后一个命令参数,直到回到了根目录
[root@localhost include]# cd !$
cd ./..
[root@localhost usr]# cd ./..
[root@localhost /]# 

3、pwd

pwd  命令


作用:可立刻得知目前所在的工作目录的绝对路径名称


语法:pwd [--help][--version]


参数说明:
--help 在线帮助。
--version 显示版本信息。


查看当前所在目录:
[root@localhost /]# cd /home
[root@localhost home]# pwd
/home
[root@localhost home]# 


ot@localhost python2.7]# cd ./…

Here we use the command to repeat the last command parameter until we are back to the root directory

[root@localhost include]# cd !$
cd ./…
[root@localhost usr]# cd ./…
[root@localhost /]#


3、pwd

```bash
pwd  命令


作用:可立刻得知目前所在的工作目录的绝对路径名称


语法:pwd [--help][--version]


参数说明:
--help 在线帮助。
--version 显示版本信息。


查看当前所在目录:
[root@localhost /]# cd /home
[root@localhost home]# pwd
/home
[root@localhost home]# 


Guess you like

Origin blog.csdn.net/qq_27566167/article/details/131662737