文件(file)1————An introduction to Linux filesystems

这里讲的主要是关于文件,目录以及一部分磁盘的相关知识。主要依据是操作系统第4章 文件管理(参考书:王道的书)和鸟哥的私房菜的第567章。

 在系统运行时,计算机以进程为基本单位进行资源的调度和分配;而在用户进行的输入、输出中,则以文件为基本单位。


1、什么是文件?

  从比喻的角度来讲,操作系统是图书管理员对于书的管理,则文件就是图书馆的书。

  从底层向上的角度来讲,数据项:用于描述一个对象的某种属性值,如姓名,日期或证件号(注意这三个例子中的一个就是数据项)

             --->记录:一组相关数据项的集合,如一个考生报名记录包括:姓名,出生日期,学号,身份证号等等。

             --->文件:由创建者所定义的一组相关数据集合,逻辑上可分为结构文件(类似于记录组成)和无结构文件(字符流,又称流式文件,在Linux下使用od反汇编的二进制文件?)两种。

                对于结构文件分为顺序文件和索引文件。其中的顺序文件分为串结构和顺序结构。

另外,我拜读了 David Both的三篇文件An introducition to Linux filesystemsAn introduction to Linux‘s EXT4 filesystemEverything is files

对于深刻理解什么是文件(上面三篇文章做的简述):

这三篇文章分别从3个方面讲述文件,第一篇是从一个high-level讲述Linux文件系统的概念。对应的第二篇是从low-level描述特殊的文件系统类型EXT4。最后一篇主要想说就是题目everything is files。

  第一篇:

  先讲述了电脑需要存储各种各样类型的数据在HDD(hard disk drive)或者USBmemory stick之类的地方。因为1、standard volatile RAM将会在他断电后丢失内容(如DDR3 DDR4),而flash RAM太贵了(如USB 和solid state drive SSD)2、standard RAM依然比磁盘空间贵,16GB of RAM vs. a 2TB hard drive贵71倍。如今一个典型的RAM大概是$0.0000000043743750/Byte。(注:这个价格是文章给出的,我大概算了一下某东的金士顿DDR3 8G 450/16/1024/1024/1024/6.8=$0.000000007703  貌似涨价了一倍?)。

  然后对于filesystems从不同角度进行了定义(definitions):(filesystems is)1、the entire Linux directory structure starting at the top(/)root directory;2、A specific type of data storage format,such as EXT34,BTRS,XFS and so on.(Linux supports almost 100 types of filesystems),3、A partition or logical volume formatted with a specific type of filesystem that can be mounted on a specified mount point on a Linux filesystem.

  1、  Basic filesystem function is to provide space for non-volatile storage of data.All filesystems need to provide a namespace --that is ,a naming and organizational methodology.It also defines the logical structure of data on a disk ,such as the use of directories for organizing files instead of just dumping them all together in a single,huge conglomeration(混合物) of files.

  Once the namespace has been defined,a metadata structure is necessary to provide the logical foundation for that namespace.

  Filesystem also require an Application Programming Interface(API) that provide access to system function calls which manipulate filesystem objects like files amd directories.APIs provide for tasks such as creating,moving,and deleting files.It also provides algorithms that determine things like where a file is placed on filesystem.

  Modern filesystem also provide a security model,which is a scheme for defining access rights of files and directories.

  The final building block is the software required to implement all of these functions.Linux use a two-part software implementation as a way to improve both system and programmer efficiency.

(First Part)Virtual File System provides a single set of commands for the kernel,and developers, to access all types of filesystems.

(Second Part)the filesystem-specific device drivers (特定文件系统的设备驱动) interprets  the standard set of filesystem commands to ones secific to the type of filesystem on the paratition or logical volume.

Directory Structure--------Tree-like hierarchy

The Linux directory structure is well defined and documented in the Linux Filesystem Hierarchy Standard (FHS).

/    :The root filesystem is the top-level directory of the filesystem.All the things(such as files executables and libraries)required to boot are in it.After the system is booted,all other filesystems are mounted on standard .well-defined mount points as subdirectories of the root filesystem.

/bin    :This directory contains user executable files.

/boot  :Contains the static bootloader and kernel executable and configuration files required to boot the Linux computer.

/dev   :This deirectory contains the device files for every hardware device attached to the system.These are not device drivers,rather they are files that represent each divice on the computer and facilitate(帮助) access to those devices.

/etc    :Contains the local system configuration files for the host computer.    

/home  :Home directory storage for user files. Each user has a subdirectory in /home.

/lib     :Contains shared library files that are required to boot the system.

/media :A place to mount external removable media devices such as USB thumb drives that may be connected to the host.

/mnt     :A temporary mountpoint for regular filesystems (as in not removable media) that can be used while the administrator is repairing or working on a filesystem.

/opt   :Optional files(鸟叔书中称为第三方协力文件) such as vendor supplied application programs should be located here.

/root  :This is not the root (/) filesystem. It is the home directory for the root user.

/sbin :System binary files. These are executables used for system administration.

/tmp :Temporary directory. Used by the operating system and many programs to store temporary files. Users may also store files here temporarily. Note that files stored here may be deleted at any time without prior notice.

/usr  :(Unix software resource,like ProgramFiles in windows)These are shareable, read-only files, including executable binaries and libraries, man files, and other types of documentation.

/var  :Variable data files are stored here. This can include things like log files, MySQL, and other database files, web server data files, email inboxes, and much more.

  1、All the red directories and their subdirectories cannot be created as a separate filesystem and mounted at startup time. This is because they (specifically, their contents) must be present at boot time in order for the system to boot properly.

  2、The /media and /mnt directories are part of the root filesystem, but they should never contain any data. Rather, they are simply temporary mount points.

  3、All the black directories do not need to be present during the boot sequence, but will be mounted later, during the startup sequence that prepares the host to perform useful work.

Linux unified directory structure

  In windows you need to know a file or program is located on which hard drives,such as C: D: E:.Then you can use cd command to change to the correct directory to locate the desired file. Each hard drive has its own separate and complete directory tree.But linux filesystem unifies all physical hard drives and partitions into a single directory structure.

  This can work only because a filesystem, such as /home, /tmp, /var, /opt, or /usr can be created on separate physical hard drives, a different partition, or a different logical volume from the / (root) filesystem and then be mounted on a mountpoint (directory) as part of the root filesystem tree. Even removable drives such as a USB thumb drive or an external USB or ESATA hard drive will be mounted onto the root filesystem and become an integral part of that directory tree.

  One good reason to do this is apparent during an upgrade from one version of a Linux distribution to another, or changing from one distribution to another. There are other reasons for maintaining certain parts of the Linux directory tree as separate filesystems.

Mounting

A mount point is simply a directory, like any other, that is created as part of the root filesystem. So, for example, the home filesystem is mounted on the directory /home. Filesystems can be mounted at mount points on other non-root filesystems but this is less common.

The Linux root filesystem is mounted on the root directory (/) very early in the boot sequence. Other filesystems are mounted later, by the Linux startup programs, either rc under SystemV or by systemd in newer Linux releases. Mounting of filesystems during the startup process is managed by the /etc/fstab configuration file.  An easy way to remember that is that fstab stands for "file system table," and it is a list of filesystems that are to be mounted, their designated mount points, and any options that might be needed for specific filesystems.

Filesystems are mounted on an existing directory/mount point using the mountcommand.

原文地址:https://www.cnblogs.com/SsoZhNO-1/p/9196739.html

时间: 2024-10-22 00:33:17

文件(file)1————An introduction to Linux filesystems的相关文章

查找目录下的所有文件中是否含有某个字符串 linux

查找目录下的所有文件中是否含有某个字符串 find .|xargs grep -ri "IBM" 查找目录下的所有文件中是否含有某个字符串,并且只打印出文件名 find .|xargs grep -ri "IBM" -l 1.正则表达式    (1)正则表达式一般用来描述文本模式的特殊用法,由普通字符(例如字符a-z)以及特殊字符(称为元字符,如/.*.?等)组成.   (2)基本元字符集及其含义       ^ :只匹配行首.   如^a 匹配以a开头的行abc,

A Quick Introduction to Linux Policy Routing

A Quick Introduction to Linux Policy Routing 29 May 2013 In this post, I’m going to introduce you to policy routing as implemented in recent versions of Ubuntu Linux (and possibly other Linux distributions as well, but I’ll be using Ubuntu 12.04 LTS)

Introduction to Linux

Part 1: Introduction 1. Linux Evolution and Popular Operating Systems The definition of the word Linux depends on the context in which it is used. Linux means the kernel of the system, which is the central controller of everything that happens on the

Java学习记录(补充八:Date类;Java流(Stream),文件(File)和IO)

Date类,Calendar类package Box1; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Random; //Date类 public class DateTest { public static void main(String[] args) { Date

流Stream 文件File 流IO

Java 流(Stream).文件(File)和IO Java.io 包几乎包含了所有操作输入.输出需要的类.所有这些流类代表了输入源和输出目标. Java.io 包中的流支持很多种格式,比如:基本类型.对象.本地化字符集等等. 一个流可以理解为一个数据的序列.输入流表示从一个源读取数据,输出流表示向一个目标写数据. Java 为 I/O 提供了强大的而灵活的支持,使其更广泛地应用到文件传输和网络编程中. 但本节讲述最基本的和流与 I/O 相关的功能.我们将通过一个个例子来学习这些功能. 读取控

文件File

前面的话 不能直接访问用户计算机中的文件,一直都是Web应用开发中的一大障碍.2000年以前,处理文件的唯一方式就是在表单中加入<input type="file">字段,仅此而已.FileAPI(文件API)的宗旨是为Web开发人员提供一种安全的方式,以便在客户端访问用户计算机中的文件,并更好地对这些文件执行操作.本文将详细介绍文件File API [注意]IE9-浏览器不支持 File File API在表单中的文件输入字段的基础上,又添加了一些直接访问文件信息的接口.

Java流(Stream)、文件(File)和IO

Java流(Stream).文件(File)和IO Java.io包几乎包含了所有操作输入.输出需要的类.所有这些流类代表了输入源和输出目标. Java.io包中的流支持很多种格式,比如:基本类型.对象.本地化字符集等等. 一个流可以理解为一个数据的序列.输入流表示从一个源读取数据,输出流表示向一个目标写数据. Java为I/O提供了强大的而灵活的支持,使其更广泛地应用到文件传输和网络编程中. 但本节讲述最基本的和流与I/O相关的功能.我们将通过一个个例子来学习这些功能. 读取控制台输入 Jav

Java笔记:Java 流(Stream)、文件(File)和IO

更新时间:2018-1-7 12:27:21 更多请查看在线文集:http://android.52fhy.com/java/index.html java.io 包几乎包含了所有操作输入.输出需要的类.所有这些流类代表了输入源和输出目标. 输入输出流 简介 一个流被定义为一个数据序列.输入流用于从源读取数据,输出流用于向目标写数据. 下图是一个描述输入流和输出流的类层次图: 在java.io包中操作文件内容的主要有两大类:字节流.字符流,两类都分为输入和输出操作. 在字节流中输出数据主要是使用

Java ——流(Stream)、文件(File)和IO

本节重点思维导图 示例:将指定的字符写到文件中 public static void main(String[] args) { try { //1.创建一个空的文件 File file = new File("abc.txt"); if (!file.exists()) { file.createNewFile(); } //2.准备数据 StringBuffer data = new StringBuffer(); for(int i = 0;i<8000;i++) { da