linux基础学习——linuxfun第十章 目录

文件系统树(file system tree)是linux中用于组织和管理文件的一种层次结构。这种结构模仿了现实中的文件柜系统,使得用户可以方便地访问和管理文件。

数据目录

“Data directory”(数据目录)是计算机系统中用于存储数据文件的目录。数据目录可以存在于各种操作系统中,并且可以具有不同的用途和组织结构。

1. /home目录

home目录下会有对应每个用户的子目录,这子目录的名字与用户名相同

lilyeggy@newworld:~$ ls -l /home
总用量 20
drwxr-xr-x 24 lilyeggy lilyeggy  4096 5月  14 23:31 lilyeggy
drwx------  2 root     root     16384 5月   5 00:40 lost+found

在我的计算机下只有lilyeggy一个用户
lost+found目录是一个特殊的系统目录,通常存在于每个文件系统的根目录下,包括/home目录。这个目录是系统在启动时,特别是fsck(文件系统检查)工具运行时用来存放恢复的文件的地方。
另外,我们不能直接在/home/目录下存储文件,要在/home/yourusername目录下存储文件

2. /root目录

每个linux系统中都有一个叫root的用户。root用户能够管理系统,安装软件,添加用户等等。root用户是一个特殊用户,它具有一个特殊的home目录叫/root
普通用户无法访问/root目录

lilyeggy@newworld:~$ ls /root
ls: 无法打开目录 '/root': 权限不够

/root 不在 /home 中的真正原因是 /home 可以从网络挂载,而在单用户模式下排除系统故障时网络不可用。

3. /srv目录

当在网络环境中设置文件共享时,被共享的目录通常会放在/srv目录中。这样做的目的是为了组织和标准化服务数据的存储位置。同时,用户可以访问/srv目录来查看系统提供的共享服务内容也就是所共享的目录。

lilyeggy@newworld:~$ ls -l /srv/
总用量 0
4. /mnt目录

/mnt目录应该是空的,它用于临时挂载(mount)文件系统
mnt目录的一些常见用途:

  • 临时挂载:系统管理员或用户可能需要临时挂载一个文件系统,比如一个从外部存储设备(如USB驱动器、硬盘、网络共享等)挂载的文件系统。

  • 测试目的:在安装或配置新的文件系统之前,可以在/mnt下的一个子目录中进行测试。

  • 系统维护:在系统维护或升级时,可能会将一个文件系统挂载到/mnt下,以便于访问或替换系统文件。

  • 挂载点:/mnt目录下的子目录可以作为挂载点,用于挂载各种不同的存储设备。

  • 启动时不自动挂载:与/media目录不同,/mnt下的挂载通常不会在系统启动时自动挂载,这使得/mnt更适合临时挂载。

lilyeggy@newworld:~$ ls /mnt
lilyeggy@newworld:~$ 
5./media目录

/media 目录用于挂载和访问可移动存储设备,如USB闪存驱动器、外部硬盘、CD-ROM、DVD等。当这些设备被插入系统时,操作系统可以自动识别并挂载这些设备到/media目录下的某个子目录中。

lilyeggy@newworld:~$ ls -l /media/
总用量 4
drwxr-x---+ 2 root root 4096 5月   5 05:02 lilyeggy
6./tmp 目录

用户和应用都能在/tmp目录下存储临时数据,一个常规的Debian Linux系统会在每次启动时清空这个目录。

二进制目录

“binary directories”(二进制目录)通常指的是存储可执行文件(即程序的二进制形式)的目录。

1./bin目录

在 Debian 10 系统中,/bin 目录是指向 /usr/bin 的一个链接(链接在后面链接那一章会讨论)

lilyeggy@newworld:~$ ls -ld /bin
lrwxrwxrwx 1 root root 7 5月   5 00:40 /bin -> usr/bin

ls -ld 表示只显示目录本身的信息而不是列出目录下所有文件和子目录的信息。
/bin目录包含了基本的命令行工具,比如head,tail,tac,cat,ls,pwd等等。

lilyeggy@newworld:/bin$ ls -l head tail tac cat ls pwd
rwxr-xr-x 1 root root  43416 9月   5  2019 cat
rwxr-xr-x 1 root root  47480 9月   5  2019 head
rwxr-xr-x 1 root root 142144 9月   5  2019 ls
rwxr-xr-x 1 root root  43352 9月   5  2019 pwd
rwxr-xr-x 1 root root  43352 9月   5  2019 tac
rwxr-xr-x 1 root root  72088 9月   5  2019 tail

长格式意味着 ls 会显示文件和目录的详细信息

2./sbin目录

/sbin(system binary的缩写)目录是用来存放系统管理命令的,这些命令通常用于系统启动、维护、修复和监控等任务。/sbin目录中的程序往往需要超级用户(root)权限才能运行,因为它们提供的是系统级别的功能。

lilyeggy@newworld:~$ ls -ld /sbin
lrwxrwxrwx 1 root root 8 5月   5 00:40 /sbin -> usr/sbin
3./lib目录

/lib(library的缩写)目录用于存放库文件(也称为共享库或动态链接库)。这些库文件提供了程序运行所需的共享代码,允许多个程序共用相同的代码,从而节省内存和磁盘空间。

lilyeggy@newworld:~$ file /lib/openssh/ssh-keysign 
/lib/openssh/ssh-keysign: setuid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=557db6444599055c156ef26bb1f355a85b10f824, for GNU/Linux 3.2.0, stripped

有关ssh-keysign库文件的内容
4./opt目录

/opt(optional的缩写)目录用于存放可选的或者第三方的软件包。这些软件通常不是由系统默认的包管理器管理的软件,而是直接由软件供应商或者用户自行安装和管理的。
默认下/opt目录是空的

lilyeggy@newworld:~$ ls -l /opt
总用量 4
drwxr-xr-x 3 root root 4096 5月   5 20:38 microsoft

配置目录(configuration directory)

“Configuration directory”(配置目录)是一个用于存放系统或应用程序配置文件的目录。这些配置文件通常包含了用于初始化或定制系统和应用程序行为的设置和参数。配置目录在不同的操作系统和应用程序中可能有不同的名称和位置,但它们的基本概念是相似的。

1./etc目录

/etc 是最主要的系统级配置目录。它包含了系统启动和运行所需的配置文件,如网络配置、用户账户信息、服务配置等。配置文件包含了用于定义系统和应用程序如何运行的设置和参数。
下面是一些/etc目录下的配置文件

lilyeggy@newworld:~$ ls /etc/*.conf
/etc/adduser.conf          /etc/host.conf        /etc/pnm2ppa.conf
/etc/apg.conf              /etc/kernel-img.conf  /etc/popularity-contest.conf
/etc/appstream.conf        /etc/kerneloops.conf  /etc/resolv.conf
/etc/brltty.conf           /etc/ld.so.conf       /etc/rsyslog.conf
/etc/ca-certificates.conf  /etc/libao.conf       /etc/rygel.conf
/etc/debconf.conf          /etc/libaudit.conf    /etc/sensors3.conf
/etc/deluser.conf          /etc/logrotate.conf   /etc/sysctl.conf
/etc/e2scrub.conf          /etc/ltrace.conf      /etc/ucf.conf
/etc/fprintd.conf          /etc/mke2fs.conf      /etc/usb_modeswitch.conf
/etc/fuse.conf             /etc/mtools.conf      /etc/xattr.conf
/etc/gai.conf              /etc/nsswitch.conf
/etc/hdparm.conf           /etc/pam.conf

boot目录

/boot 目录在Linux操作系统中是一个非常重要的目录,它包含了启动(booting)系统所需的关键文件。
具体来说,/boot 目录通常包含以下类型的文件:

  • 内核文件:这是操作系统的核心,通常以 vmlinuz, vmlinuz-, 或 bzImage 等形式存在。内核文件负责管理系统的硬件资源并提供基本的运行环境。

  • 初始(initital)ramdisk (initrd) 文件:这些文件包含了系统启动时所需的临时文件系统。它们通常以 initrd, initrd0, initrd- 等形式命名。initrd 包含了启动系统所需的驱动和软件,直到实际的根文件系统可以被挂载。

  • 引导加载器(bootloader)配置文件:如 grub.cfg,这是由 GRUB(GRand Unified Bootloader)使用的配置文件,它定义了启动菜单和内核启动参数。

  • 系统映射文件:如 System.map,这是一个符号表,包含了内核符号及其地址的映射,通常用于调试。

  • 其他启动相关文件:根据Linux发行版和配置的不同,/boot 目录还可能包含其他一些文件,如内核模块、特定的驱动文件等。

/boot 目录通常位于根文件系统(/)上,并且由于它包含的是系统启动的关键文件,因此需要经常进行备份。此外,/boot 目录的大小通常受到限制,因为它需要在系统启动时能够被加载到内存中。

内存文件系统目录(directories in RAM memory)

Directories in RAM memory通常指的是内存文件系统(In-Memory File System),它与传统的磁盘文件系统不同,存储在RAM中而非硬盘上。
内存文件系统是一种临时的、易失性的文件系统,通常用于提高数据访问的速度。由于RAM的读写速度远高于传统的硬盘驱动器(HDD)或固态驱动器(SSD),因此,将频繁访问的数据或需要快速处理的数据存放在RAM文件系统中可以显著提升性能。

1./dev目录

/dev目录用于存放设备文件

  • /dev/disk
lilyeggy@newworld:~$ ls /dev/disk
by-id  by-label  by-partlabel  by-partuuid  by-path  by-uuid
/dev/disk/目录下可以找到连接的硬盘设备
  • /dev/urandom
    /dev/urandom下是一个伪设备(pseudo device),访问它可以生成随机数生成的随机数是基于系统收集到的环境噪声数据产生的(通常包括键盘输入/鼠标移动/硬件中断等)
    它的设计初衷是提供一种不会因为系统熵耗尽而阻塞的随机数生成方式,即使在熵较低的情况下也能继续提供随机数。

在这里简单介绍一下linux系统熵的概念
Linux内核通过维护一个称为熵池(entropy pool)的机制来收集系统的环境噪音,这些噪音主要来自设备驱动程序和其他来源,如键盘输入、磁盘读写以及内存错误等。理论上,熵池中的数据是完全随机的,可以用来产生真随机数序列。

  • /dev/zero(pseudo device)
    读取这一目录会源源不断地提供空字符,通常用于需要生成大量空白数据的情况,例如格式化磁盘或创建加密文件。

  • /dev/null (pseudo device)
    所有写入 /dev/null 的数据都会被系统丢弃,不会存储,也不会有任何输出。这可以用来丢弃不需要的输出信息。

2./proc目录(只读目录)

/proc目录是Linux系统中的一个虚拟文件系统,它包含了许多与系统硬件及运行中进程相关的信息。它为系统管理员和开发者提供了丰富的系统内部信息,并允许一定程度的内核(kernel)状态监控和调整。

lilyeggy@newworld:~$ ls /proc
1     1599  1810  2150  28    378   558   69   871            key-users
10    16    1825  2171  280   379   56    70   872            kmsg
1033  1604  1837  22    2808  38    560   72   88             kpagecgroup
1054  161   1838  2295  281   39    57    727  89             kpagecount
107   162   1839  24    2812  4     58    73   90             kpageflags
11    1626  1842  2436  282   40    5821  74   91             loadavg
1166  1633  1845  2439  283   412   5836  75   917            locks
12    1647  1846  2489  284   42    5894  752  92             mdstat
13    165   1847  2495  285   4236  5915  753  93             meminfo
1343  166   185   25    286   426   5921  754  936            misc
14    1677  1850  2526  2860  43    5959  755  94             modules

使用/proc还可以询问有关计算机中断、运行时间和cpu的信息

lilyeggy@newworld:~$ head /proc/cpuinfo
processor	: 0
vendor_id	: AuthenticAMD
cpu family	: 25
model		: 80
model name	: AMD Ryzen 5 5600G with Radeon Graphics
stepping	: 0
microcode	: 0xa50000c
cpu MHz		: 1400.000
cache size	: 512 KB
physical id	: 0
3. /sys目录

/sys目录与/proc相似,都包含有关内核的信息,但它们的结构不同。这个目录不是文件系统层次结构(FHS)的一部分,但在Debian Linux系统上总是存在于RAM内存中。当hot plugging devices时,会在/sys目录下创建必要的文件。

hot plugging:一种技术,允许用户在不关闭系统、不切断电源的情况下取出和更换损坏的硬盘、电源或板卡等部件

lilyeggy@newworld:~$ ls -l /sys
总用量 0
drwxr-xr-x   2 root root 0 5月  25 04:03 block
drwxr-xr-x  47 root root 0 5月  25 04:03 bus
drwxr-xr-x  80 root root 0 5月  25 04:03 class
drwxr-xr-x   4 root root 0 5月  25 04:03 dev
drwxr-xr-x  20 root root 0 5月  25 04:03 devices
drwxr-xr-x   6 root root 0 5月  25 04:03 firmware
drwxr-xr-x   9 root root 0 5月  25 04:03 fs
drwxr-xr-x   2 root root 0 5月  25 04:03 hypervisor
drwxr-xr-x  16 root root 0 5月  25 04:03 kernel
drwxr-xr-x 204 root root 0 5月  25 04:03 module
drwxr-xr-x   3 root root 0 5月  25 04:03 power
4./usr目录(short for Unix System Resources )

该目录存储只读,可分享的数据。这个目录通常用于存放系统范围内的应用程序、库文件、文档等资源,这些资源是所有用户共享的。可以在网络上挂载该目录,并在多台计算机之间共享它。

lilyeggy@newworld:~$ ls /usr
bin    include  lib32  libexec  local  share
games  lib      lib64  libx32   sbin   src
1./usr/bin和/usr/sbin

Debian系统默认在/bin和/usr/bin以及/sbin和/usr/sbin之间创建一个链接。因此这些目录都包含同样的命令。

lilyeggy@newworld:~$ ls -ld /bin
lrwxrwxrwx 1 root root 7 5月   5 00:40 /bin -> usr/bin
lilyeggy@newworld:~$ ls -ld /sbin
lrwxrwxrwx 1 root root 8 5月   5 00:40 /sbin -> usr/sbin
2./usr/include和/usr/src

/usr/src存放源代码文件(source code)
/usr/include存放头文件(include files)

下面的命令可以查看一些/usr/include下的头文件
lilyeggy@newworld:~$ find /usr/include/
/usr/include/
/usr/include/netipx
/usr/include/netipx/ipx.h
/usr/include/stdc-predef.h
/usr/include/termio.h
/usr/include/crypt.h
/usr/include/pty.h
/usr/include/scsi
/usr/include/scsi/scsi_netlink.h
/usr/include/scsi/scsi_ioctl.h
/usr/include/scsi/scsi_netlink_fc.h
/usr/include/scsi/sg.h
/usr/include/scsi/cxlflash_ioctl.h

/usr/src目录一般是空的,除非你从库(repository)中安装一些源代码

lilyeggy@newworld:~$ ls /usr/src
linux-headers-5.15.0-105-generic  linux-hwe-5.15-headers-5.15.0-105
linux-headers-5.15.0-107-generic  linux-hwe-5.15-headers-5.15.0-107
3./usr/local

/usr/local 目录能被root用户安装的软件使用

lilyeggy@newworld:~$ ls /usr/local/
bin  etc  games  include  lib  man  sbin  share  src
4./usr/share

该目录包含了可共享的与系统架构无关的文件。比如手册页(man pages)就在该目录里

lilyeggy@newworld:~$ ls /usr/share/man
cs  es  fr.ISO8859-1  id  ko    man3  man6  nl  pt_BR  sr  zh_CN
da  fi  fr.UTF-8      it  man1  man4  man7  pl  ru     sv  zh_TW
de  fr  hu            ja  man2  man5  man8  pt  sl     tr
5. /var目录

/var目录用于存放变量数据,这些数据的大小和内容会随着系统运行而变化。

lilyeggy@newworld:~$ ls /var
backups  crash  local  log   metrics  run   spool
cache    lib    lock   mail  opt      snap  tmp
1./var/cache

/var/cache 目录在Linux系统中用于存放应用程序的缓存文件。这些缓存文件是应用程序为了提高性能而存储的临时数据,它们可以是任何形式的数据,比如文本、图片、数据库查询结果等。应用程序在处理请求时,可能会首先检查 /var/cache 目录中是否有可用的缓存数据,如果有,就可以直接使用这些数据,而不必重新生成或从原始数据源中获取,这样可以显著提高应用程序的响应速度和效率。

lilyeggy@newworld:~$ ls /var/cache/
apparmor  cracklib  dictionaries-common  fwupdmgr  man         snapd
app-info  cups      fontconfig           gdm       PackageKit
apt       debconf   fwupd                ldconfig  private
2./var/log

日志文件存储在/var/log下,要么以.log结尾存储要么存储在一个子目录下

lilyeggy@newworld:~$ ls /var/log
alternatives.log          boot.log.7       kern.log.1
apport.log                bootstrap.log    kern.log.2.gz
apport.log.1              btmp             lastlog
apport.log.2.gz           cups             openvpn
apport.log.3.gz           dist-upgrade     private
apport.log.4.gz           dmesg            speech-dispatcher
apt                       dmesg.0          syslog
3./var/run

/var/run 目录是指向 /run 的符号链接。(链接的内容在后面的章节会讲到)
在传统的UNIX和类UNIX系统中,/var/run 目录用于存放系统运行时的数据,如进程ID文件、锁文件等。随着系统的发展,特别是在使用systemd的Linux发行版中,/run 目录被引入作为新的标准,用于存放运行时数据,而 /var/run 则被保留为向后兼容的符号链接,指向 /run。这样,新的系统使用 /run 目录,而旧的软件和脚本仍然可以通过 /var/run 正常工作。

lilyeggy@newworld:~$ ls -ld /var/run
lrwxrwxrwx 1 root root 4 5月   5 00:40 /var/run -> /run

这个目录包含自系统启动以来正在运行的程序的运行状态信息。

lilyeggy@newworld:~$ ls /var/run
acpid.pid      dbus        mount            snapd              udev
acpid.socket   gdm3        netns            snapd-snap.socket  udisks2
alsa           gdm3.pid    NetworkManager   snapd.socket       user
avahi-daemon   initctl     openvpn          speech-dispatcher  utmp
blkid          initramfs   openvpn-client   spice-vdagentd     uuidd
console-setup  irqbalance  openvpn-server   sudo
crond.pid      lock        plymouth         systemd
crond.reboot   log         sendsigs.omit.d  thermald
cups           motd.d      shm              tmpfiles.d
4./var/spool

这个目录包含等待处理的数据。

lilyeggy@newworld:~$ ls /var/spool/
anacron  cron  cups  mail  rsyslog
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值