Introduction to Linux file system

2010-11-19  来源:本站原创  分类:OS  人气:110 

File system is a very basic linux knowledge, but also learning the necessary knowledge of linux.

This will stand for a higher view to understand the linux file system, including the linux partition and directory, mount the basic principles of file structure, soft links hard links, and common directory introduced. Believe that with this knowledge for in-depth study will be of some help linux. Examples of the article is mainly based ubuntu release.

Please if a lot wrong with that.

1. Linux disk partition and directory

Differences between Linux distributions little difference mainly in the systems management tools and package management features different ways. Are basically the same directory structure. Windows file structure is more tied to the tree structure, the top is a different disk (partition), such as: C, D, E, F and so on.

Linux's file structure is a single tree. Can be demonstrated by tree. In the Ubuntu install tree (sudo apt-get install tree), and through the command to view it.

Every time when we will install the system partition, Linux partition and directory under the following relationship:

- Any one partition must be mounted to a directory.

- Directory is a logical distinction. Partition is the physical distinction.

- Disk partitions must be mounted to the Linux directory tree to a specific directory to read and write operations.

- Linux root directory of all files and directories where the need to mount on a disk partition.

The following is a possible relationship between the directory and partition:

Introduction to Linux file system

Figure 1: The relationship between the directory and partition

Q: How do I view and use partition and directory?

- Fdisk see the hard disk partition table

- Df: view the partition use

- Du: view the file space conditions

Q: Why partition, how to partition?

- You can put different information into different partitions, respectively, to manage and reduce risk.

- Large hard drive search, low efficiency

- Disk partitions can only be set with

- / Home / var / usr / local is often a separate partition, because often operate, prone to debris

2. Mount NFS mount and Introduction

The concept of mounting: When to use a device, for example, to read a formatted hard disk partition, CD or software and other equipment, it must first of these devices correspond to a directory and this directory is known as the "mount point (mount point)", so as to read these devices, which are the corresponding action is "mounted." Block out the details of the physical partition. Only the logic of a unified concept of the user. Everything is a file. Mount can mount command:

mount [-fnrsvw] [-t vfstype] [-o options] device dir

Q: All of the disks must be mounted on the partition to use, then we partition the hard disk on the machine is to be mounted?

A: This is mainly its use of the / etc / fstab file. Each time the kernel load it knows the file system mount from here. Each time the system starts automatically based on the definition of the file to mount. If you are not automatically mounted, partition will not be used. The following is my / etc / fstab definition is mainly based on the partition installed to the:

# <file System> <mount point> <type> <options> <dump> <pass>

proc / proc proc defaults 0 0

# / Dev/sda1 is automatically mounted as /

UUID = cb1934d0-4b72-4bbf-9fad-885d2a8eeeb1 / ext3 relatime, errors = remount-ro 0 1

# / Dev/sda5 partition is automatically mounted as / home

UUID = c40f813b-bb0e-463e-aa85-5092a17c9b94 / home ext3 relatime 0 2

# / Dev/sda7 is mounted automatically to / work

UUID = 0f918e7e-721a-41c6-af82-f92352a568af / work ext3 relatime 0 2

# Partition / dev/sda6 is mounted automatically to the swap

UUID = 2f8bdd05-6f8e-4a6b-b166-12bb52591a1f none swap sw 0 0

Q: How to mount removable hard disk? How to mount a new partition?

Mobile hard disk drive modules are mounted automatically, if you have a new hard drive, first partition, and through the mount command to mount to a folder. If you want to automatically mount, you can modify / etc / fstab file.

About NFS: NFS that are widely used in many places, is a very good file-sharing. From our service is used to upload files to a network server, the middle is achieved through the NFS.

Using the NFS client can transparently access the file server. NFS mount is achieved through the underlying communication protocol through the NFS. Rationale:

Introduction to Linux file system

Figure 2: NFS basic principles

The following examples under Ubuntu Ubuntu

Server:

$ Apt-get install nfs-kernel-server

vi / etc / exports add nfs directory: / personal / nfs_share

10.1.60.34 (rw, sync, no_root_squash)

$ Sudo exportfs-r

$ Sudo / etc / init.d / portmap start

$ Sudo / etc / init.d / nfs-kernel-server start

Client:

$ Sudo apt-get install nfs-common

$ Sudo mount 10.19.34.76: / personal / nfs_share ~ / nfsshare example:

3. File Type

Linux The following file types are:

a) normal file: C language element code, SHELL script, binary executable files. Into plain text and binary.

b) List of files: directories, files stored in the only place.

c) link to file: pointer to a file or directory with the files.

d) special file: peripherals associated with the system, usually in the / dev below. Divided into block and character devices.

By ls-l, file, stat command to view the file number of the types of information.

4. File storage structure

Orthodox Linux file system (such as ext2, ext3) a file from the directory entry, inode and data blocks.

List of items: including file name and inode node number.

Inode: also known as the inode file is the basic information stored in files and data stored in block pointer.

Block: the specific content of the file storage places.

Orthodox Linux file system (such as ext2, 3, etc.) will be carved out of hard drive partition directory block, inode Table data block and data block area. A file from a directory entry, inode blocks and data areas. Inode contains the file attributes (such as read-write property, owner, etc., and point to the data block pointer), the data area block is the file content. When viewing a file, it will start with the inode table was found in the file attributes and data storage points, and then read data from a data block.

2w-foot standing view file structure something like this:

Introduction to Linux file system

Figure 3: 2w-foot view file structure

One directory entry is structured as follows (each file change the file directory entry is stored in the contents of the file in their respective directories):

Figure 4: The directory entry structure

One file inode structure is as follows (inode in the file information contained in stat filename can see get):

Introduction to Linux file system

Figure 5: inode structure

Reflects only the general structure above, linux file system itself is constantly evolving. But the above concept is basically the same. And such as ext2, ext3, ext4 file system, there are also very different, if you want to understand the specific file system can view the introduction.

5. Soft connection, hard links

Soft link and hard link is common to both concepts:

Hard-wired: It is a copy of a file, while establishing a connection between the two relationships. Change one of them, connected to the file has been modified at the same time. If you remove one [color = red] any [/ color] the rest of the file will not be affected.

Soft connection: also called symbolic links, he only source file in a new location to create a "shortcut (to borrow wondows commonly used words)" So, when the source file is deleted, the files symbolic links will be without water -> just left a file name, of course, delete this connection, it will not affect the source file, but the use of the connection file, references are called source files directly.

Figure specific relationships may have a look:

Introduction to Linux file system

Figure 5: soft links and hard links

As can be seen from the chart hard links and soft links distinction:

1: The hard link of the original file and the file inode number of new line. The soft link is not the same.

2: Delete the original files will lead to soft link is not available, but hard links are not affected.

3: Modify the original file, soft, hard link the same file content changes, as are the same file content.

6. File directory management commands

Disk and file space

fdisk df du

Directory and management

cd pwd mkdir rmdir ls cp rm mv

View file content

cat:
cat [file]
View the contents of the file. Concatenate all the meaning of the program, the contents of the file continuous output to the screen. The first line to last line.
tac:
tac [file]
And the cat is just the opposite from the first line of the last line to be viewed.

cat has a relatively poor place, when the time when the files are large can not see, at this time can be more or Less command.

more:
more [file]
If you use a command such as grep or find, you can use with the view more page by page. If you see half want to quit, then typing 'q' to exit.
less:
less [file]
less than more flexibility, you can flip up and down.

If you want to read the file in the first few lines or a few lines at the end of the file, you can use head or tail.
head-n [file]: n lines before reading the file.
hail-n [file]: reading the file at the end of n lines.

These commands are used to view the character files, binary files are garbled out, depending on the contents of binary files, you can use the od command, such as viewing the contents of an MP3 file inside:
od shijiemori.mp3

File directory and permissions

chmod chown chgrp umask

Find file

which:
which [filename]
This command is used to query the path to the path through the PATH to search for executable files.
Such as: Which passwd: Find the executable file passwd
whereis:
whereis [-bmsu] [keyword]
The command word for the related files and directories are listed. (Linux will be recorded in a file inside the database file, the command type to query from the database, so the faster, Linux every day to update the database)

locate:
locate [filename]
The command word for the related files and directories are listed. Find data particularly fast, but also the way through a database query. Database, updated once a week, however, so there may be some data not find out. Can modify the configuration file.

find:
find [path] [parameters] [keyword]
This command is used to find files in the specified path. Not through the data to query, so the speed will be slower.

7. Common directory explanation

Various Linux distributions are basically the same directory structure, each directory briefly as follows:

Directory

Description

/

Root

/ Bin

Based system as the most basic needs of the command is placed here. Such as ls, cp, mkdir and other orders; functions and / usr / bin similar to the files in this directory is executable, ordinary users can use the command.

/ Boot

Linux kernel and the boot process the required documentation, such as vmlinuz initrd.img files are located in the directory. Under normal circumstances, GRUB or LILO bootloader is also located in this directory; boot loader file storage location, such as kernels, initrd, grub. Is generally a separate partition.

/ Dev

The necessary equipment, sound cards, disk and so on. Also, as / dev / null. / Dev / console / dev / zero / dev / full and so on.

/ Etc

System configuration files to. Some of the server's configuration file is here; such as user ID and password configuration file;

/ Etc / opt: / opt corresponding to the configuration file

/ Etc/X11: Xwindows system configuration files

/ Etc / xml: XML configuration files

... ...

/ Home

The user working directory, and personal configuration files, environment variables, such as personal, all the accounts assigned a working directory. Is generally a separate partition.

/ Lib

Stored in library files. bin and sbin required libraries. Similar to the windows of the DLL.

/ Media

Removable media mount points, such as CD-ROMs, removable hard disk, U disk, the system default will be mounted here.

/ Mnt

Temporary mount the file system. This directory is usually mounted storage device for storing the mount directory, such as a cdrom and other directories. Can be found in / etc / fstab definition.

/ Opt

Optional application packages.

/ Proc

Operating system is running, the process (running the program) information and core information (such as cpu, hard disk partitions, memory information, etc.) stored in here. / Proc proc directory disguised mount the file system directory, proc file system is not real, its definition can be found in / etc / fstab.

/ Root

Root user's working directory

/ Sbin

And the bin is similar to some executable files, but not all users need, the system management is generally required to get.

/ Tmp

Temporary file system, general system reset will not be saved.

/ Usr

Contains a system user tools and procedures.

/ Usr / bin: non-executable commands to the ordinary user

/ Usr / include: the standard header file

/ Usr / lib: / usr / bin / and / usr / sbin / libraries

/ Usr / sbin: non-executable files must be

/ Usr / src: kernel source

/ Usr/X11R6: X Window System, Version 11, Release 6.

/ Srv

This directory contains some of the services need to extract the data after the start

相关文章
  • Introduction to Linux file system 2010-11-19

    File system is a very basic linux knowledge, but also learning the necessary knowledge of linux. This will stand for a higher view to understand the linux file system, including the linux partition and directory, mount the basic principles of file st

  • [Transfer] Linux File System Introduction 2010-12-01

    File system is a very basic linux knowledge, but also learning the necessary knowledge of linux. This will stand for a higher view to understand the linux file system, including the linux partition and directory, mount the basic principles of file st

  • About the new generation Linux file system btrfs (change) 2010-06-23

    characteristics and use of btrfs Document options Print this page Send as e-mail this page Levels: Liu ( [email protected] ), Software Engineer, Shanghai Jiao Tong University Electronics and Communication Engineering August 20, 2009 Btrfs is called

  • Create a file system and mount the Linux file system processes Detailed 2010-12-12

    Study: North South North from: LinuxSir.Org http://www.linuxsir.org/main/?q=node/83 Abstract: The new hard drive, cutting the hard disk, create hard disk partition, create a file system for the hard disk partition, and load the file system summary di

  • The understanding of Linux file system 2011-05-07

    File system is the most important part of the operating system, which defines the method of storing documents on disk and the data structure. File system is the operating system to organize, access and preservation of an important means of informatio

  • About the Linux file system 2010-11-19

    Linux file system is a very basic knowledge, but also learning the necessary knowledge of linux. This will stand a higher view to understand the linux file system, including a linux disk partition and directory, mount the basic principles of file str

  • [Transfer] Linux file system description 2010-12-01

    Linux file system is a very basic knowledge, but also learning the necessary knowledge of linux. This will stand a higher view to understand the linux file system, including a linux disk partition and directory, mount the basic principles of file str

  • Understanding of Linux file system 2011-05-07

    File system is the most important part of the operating system, which defines the disk files stored on the methods and data structures. File system is the operating system organize, access and preservation of an important means of information, each h

  • linux file system commands 2010-02-04

    Linux supports a large number of local file system type (ext2, ext3, JFS, XFS, ReiserFS, vfat, NTFS), look at / proc / filesystems file to find out the contents of the current Linux kernel can provide the support on which the file system. No matter w

  • Perfect Understanding Linux file system directory structure in the 2010-03-11

    Articles Category: Operating system 1 What is the file system When you use Linux, when, if you ls-l / will be found in / under the bear with a lot of directories, such as etc, usr, var, bin ... ... and other directory, but in these directories, we go

  • Worth studying the Linux file system 2010-05-03

    Most of the windows platform transfer to the user when using the linux file system and confusion. linux file system and windows file system is very different. This article and look for the novice to present their differences and to introduce novice l

  • linux file system structure of 2010-06-11

    Structural Analysis of the file system, we can analyze it? That is, when we set out / directory, see / usr, / etc ... ... / var directory, etc. What are used, these directories are not there for a purpose. No matter which version of Linux systems whi

  • Linux file system <switch> 2010-11-09

    File system is an important part of the operating system is the operating system to computer hard drives to store and retrieve data in a logical way. Linux through the VFS (virtual file system) support multiple file formats. Linux supports a variety

  • Learning Linux - File System 2011-04-12

    [Size = large] Linux File System Overview: 1. Any one partition must be mounted to a directory 2 directory partition (logical partition), partition (physical partition) 3. Any device must be mounted to a directory to use, and this directory is the "m

  • (Reproduced) linux file system directory structure 2011-06-09

    / Linux file system entry / Bin-based system required that the command is located in this directory is the minimum required for the system command, the files in the directory are executable, ordinary users can use the command / Boot Linux kernel and

  • linux file system configuration files 2011-06-10

    Blue file ---------- directory White paper ---------- General documents, such as text files, configuration files, source files, etc. ---------- Blue file link file, mainly documents created using the ln command Green ---------- executable files, exec

  • Linux File System Overview 2011-06-16

    From: LinuxSir.Org Abstract: Speaking through the file system is defined, then quotation simply describes what the file system type; commonly used for Linux ext2, ext3 and reiserfs are also based on my experience with the general talked about, but no

  • Analysis of the Linux file system 2011-09-05

    We first look at a simple text file is how to save: Open vim, a text editor: [[email protected] ~]# vim hello.txt Editing content is as follows: opencfg.com is best website for java With the command: wq to save and then list the files [[email protected] ~]

  • Linux File System Introduction to the basic directory structure 2011-01-04

    / Root root (/), is generally recommended only in the root directory under the directory access, not directly with files in / under. Root directory is the first time the system boot mounted partition, so all files will be used during the boot process

  • Basic Linux file system directory structure Introduction 2011-01-04

    / Root of the root (/), is generally recommended only in the root directory under the directory access, not directly with files in / under. Root directory is the first system boot time to mount the partition, so all files will be used during the boot