Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example of operating a file system in Linux

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about examples of how to operate a file system in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Capacity of disks and directories

The overall data of the disk is in the superblock block, but the capacity of each individual file is recorded in inode. There are two commands commonly used to show disk usage.

Df: lists the overall disk usage of the file system

Du: evaluate the disk usage of a file system (often used to evaluate the capacity of a directory)

$df [- ahikHTm] [directory or file name] parameter:-a: lists all file systems, including system-specific file systems such as / proc (/ proc is mounted in memory and does not take up disk space) -k: display the file systems in the capacity of KB-m: display the file systems in the capacity of MB-h: display themselves in formats that are easy for people to read, such as GB, MB, KB, etc.-H: replace the carry mode of Mbike 1024K with MIMO 1000K-T: the name of the file system along with the partition is also listed (e.g. ext3)-I: not hard disk capacity, but the number of inode

Almost all the data read by df is for the entire file system, so the scope of reading is as long as it is in the super block, so this command displays the results very quickly.

$du [- ahskm] file or directory name parameter:-a lists all file and directory capacity, because by default only the number of files in the directory is counted-h shows the total at a capacity that is easier for people to read-s lists the total capacity, but does not list the occupied capacity of each individual directory-S does not include the total capacity under the subdirectory-k is shown as KB list capacity-m is displayed as MB list capacity

Du will directly find all the file data of the file system

Connection file: ln

There are two types of connection files under linux: one is a shortcut similar to Windows that allows you to quickly connect to a target file or directory. The other is to generate a new file name through an inode connection to the file system, rather than a new file, which is called a hard link.

Hard link (hard connection and actual connection)

Each file takes up an inode, and the contents of the file are pointed to by the record of the inode.

To read a file, the file name recorded in the directory must be pointed to the correct inode number before it can be read.

The file name is related to the directory, and the file content is related to inode, and hard link is to create an associated record in a directory where a file name is connected to an inode number.

Vagrant@vagrant-ubuntu-trusty-64:~$ cd / tmpvagrant@vagrant-ubuntu-trusty-64:/tmp$ touch tesvagrant@vagrant-ubuntu-trusty-64:/tmp$ ln test test1vagrant@vagrant-ubuntu-trusty-64:/tmp$ ll-I test test162273-rw-rw-r-- 2 vagrant vagrant 0 Dec 17 12:39 test62273-rw-rw-r-- 2 vagrant vagrant 0 Dec 17 12:39 test1

You can see that the inode numbers of the two files are the same, their file permission attributes are exactly the same, and the number of connections is 2.

The biggest advantage of hard connection is security. If you delete any file name, both inode and block exist. At this point, you can read the correct file data through another file name. No matter which file name you use to edit, the final result will be written to the same inode and block, so the data can be modified.

Generally speaking, when you use hard link settings to connect files, the disk space and the number of inode will not change, hard link will only write one more associated data in a directory, which will neither increase inode nor consume the number of block (unless you add one more associated data in block when the disk happens to be full, you may need to add one more block to record file name association, resulting in changes in disk space).

Limitations of hard connections:

Cannot cross file system

Cannot connect to a directory, because if you use hard link to connect to a directory, the connected data needs to be connected together with all the data under the connected directory, which will cause considerable complexity to the environment, so directories are not supported for the time being.

Symbolic link (symbolic links, or shortcuts)

Symbolic link is to create a separate file, and this file will make the data read to point to the file name of the file it is linked to. Because it is only using the file as a pointing operation, when the source file is deleted, the symbolic link file will not find the source file and cannot be opened.

Vagrant@vagrant-ubuntu-trusty-64:/tmp$ ln-s test test2vagrant@vagrant-ubuntu-trusty-64:/tmp$ ll-I test test262273-rw-rw-r-- 2vagrant vagrant 0 Dec 17 12:39 test62275 lrwxrwxrwx 1 vagrant vagrant 4 Dec 17 13:07 test2-> test

The two files point to different inode numbers, and the important thing about the connection file is that it will write the file name of the target file. Because the file to the right of the arrow is 4 Byte, the size of the connection file is 4 byte.

The file created by symbolic link is a separate new file, so it takes up inode and block.

When you modify the symbolic link file, it changes to the source file.

Ln [- sf] Source file target file parameter:-s: if you do not add any parameters to connect, it is hard link, as for-s is symbolic link-f: if the target file exists, take the initiative to delete the target file directly and then rebuild.

About the number of connections to the directory

When hard link is used to connect files, the number of connections to files increases by 1, so when we create an empty directory, because it exists. With; with. With these two directories, when we create an empty directory / tmp/testing, there are basically three things:

/ tmp/testing

/ tmp/testing/.

/ tmp/testing/..

Where / tmp/testing and / tmp/testing/. All represent the directory, and / tmp/testing/.. Represents the / tmp directory, so when we create a new directory, the number of new directory connections is 2, while the number of connections in the upper directory increases by 1.

Partitioning, formatting, verification and mounting of disks

If you want to add a hard drive to the system, you need to do the following:

Partition the disk to create a new available partition

Format the partition to create a file system available to the system.

If you want to be more careful, you can verify the file system you just created.

On linux systems, you need to create a mount point (that is, a directory) and mount it.

Disk partitions: fdisk

$fdisk [- l] device name parameter:-l: outputs all the partition contents of the devices that follow. If there is only fdisk-f, the system will list the partitions of the devices that can be found by the entire system. # for example: # find out the disk file name vagrant@vagrant-ubuntu-trusty-64:/tmp$ df / Filesystem 1K-blocks Used Available Use% Mounted on/dev/hdc1 41251136 3631948 35883276 / # enter fdisk But do not add the number vagrant@vagrant-ubuntu-trusty-64:/tmp$ fdisk / dev/hdc, it will prompt Command (m for help): enter m and you can see the relevant parameters prompt d for deleting a partition n for adding a partition p for displaying the partition table Q for no storage on the screen, and leaving the fdisk program w for writing the operation to the partition table.

Pay special attention to Q and w, as long as you press Q when you leave fdisk, then all operations will not take effect, on the contrary, pressing w means that the operation will take effect.

Delete disk Partition

To delete a partition (for example, delete all / dev/hdc partitions), you need to take the following steps:

Fdisk / dev/hdc: enter the fdisk interface first

P: take a look at the partition information first. Suppose you want to delete / dev/hdc1.

D: to select a partition at this time, choose 1

W or Q: W can be stored in a disk data table and leave fdisk;. If you regret it, press Q directly to cancel the delete operation.

New disk Partition

The action that needs to be done:

Fdisk / dev/hdc: enter the fdisk interface first

N: new partition

P or e or l: select a different partition type, where p represents primary partition, e represents extended partition, and l represents logical partition

1-4: partition number. Optional 1-4. If it is a logical partition, you do not need to enter a partition number.

Enter the ending cylinder number. If it is too troublesome to calculate the cylinder / partition size yourself, you can use a form similar to "+ 512m" to ask the system to assign the cylinder number closest to 512m for us.

P: view partition information

W or Q: W can be stored in a disk data table and leave fdisk;. If you regret it, press Q directly to cancel the delete operation.

For the form of creating a partition (primary partition / extended partition / logical partition) and the size of the partition, generally speaking, there are several situations in the form of a new partition:

There is still room for numbers 1-4, and the system does not have an extended partition: an option for you to select Primary/Extended appears, and you can specify a number between numbers 1-4

Number 1-4 is left, and the system has an extended partition: the option for you to select Primary/Logical appears. If you select p, you also need to specify the number between number 1 and 4. If you select l, you do not need to set the number, because the system will automatically specify the file name number of the logical partition.

1-4 has no left, and the system has extended partitions: you will not be allowed to pick the partition type at this time. You will enter the partition form of logical directly.

Generally, after partitioning, you need to reboot to update the partition table information of the kernel. You can use "partprobe" to force the kernel to find the partition table again.

Thank you for reading! This is the end of this article on "examples of operating file systems in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report