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:
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:
Figure 2: NFS basic principles
The following examples under Ubuntu Ubuntu
$ 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
$ 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:
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):
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:
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
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.
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.
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 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:
File directory and permissions
chmod chown chgrp umask
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 [-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)
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 [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:
|/ 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|