Linux tutorial-Disk Management

Source: Internet
Author: User
Article title: Linux tutorial-Disk Management. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
In the Liunx system, how to effectively use and manage buckets is a very important technology. This chapter describes how to view the usage of the storage space in the system, how to dump files, and how to format a floppy disk.
  
Disk space management
  
System software and application software must be stored in the disk space of a computer in the form of files. Therefore, the disk space usage should be monitored at any time. Linux provides a set of commands for disk space management.
  
Df command
  
Function: checks disk space usage of the file system. You can use this command to obtain the space occupied by the hard disk and the remaining space.
  
Syntax: df [option]
  
Note: The df command displays the I node and disk block usage of all file systems.
  
The meaning of each option of this command is as follows:
  
-A: displays the disk usage of all file systems, including 0 block file systems, such as/proc file systems.
  
-K is displayed in k bytes.
  
-I: displays the I node information instead of the disk block.
  
-T: displays the disk space usage of each specified type of file system.
  
-X lists the disk space usage of a file system of a specified type (opposite to the t option ).
  
-T displays the file system type.
  
Example 1: list the disk space usage of each file system.
  
$ Df
  
Filesystem 1 K-blocks Used Available Use % Mounted on
  
/Dev/hda2 1361587 1246406 44823 97%/
  
Column 1st of the output list of the df command represents the path name of the device file corresponding to the file system (usually the partition on the hard disk); column 2nd shows the data block contained in the partition (1024 bytes) number; Column 3 and 4 indicate the number of used and available data blocks, respectively. The user may be surprised that the sum of the blocks in column 3 and 4 is not equal to the number of blocks in column 3. This is because by default, each partition leaves a small amount of space for the system administrator to use. Even if the common user space is full, the administrator can still log on and leave the workspace required to solve the problem. The Use % column in the list indicates the percentage of space used by normal users. even if the number reaches 100%, the partition still has space for the system administrator. Finally, the Mounted on column indicates the installation point of the file system.
  
Example 2: list the I node usage of each file system.
  
$ Df-ia
  
Filesystem Inodes IUsed IFree Iused % Mounted on
  
/Dev/hda2 352256 75043 277213 21%/
  
None 0 0 0%/proc
  
Localhost :( pid221) 0 0 0 0%/net
  
Example 3: list the types of file systems.
  
$ Df-T
  
Filesystem Type 1K-blocks Used Available use % Mounted on
  
/Dev/hda2 ext2 1361587 1246405 44824 97%/
  
In this example, the file system is of the ext2 type.
  
Du command
  
The original English meaning of du is "disk usage", which means to display the usage of disk space.
  
Function: calculates the disk space occupied by Directories (or files.
  
Syntax: du [option] [Names…]
  
Note: this command step by step enters each sub-directory of the specified directory and displays the directory's usage of file system data blocks (1024 bytes. If no Names is provided, the current directory is counted.
  
The options of this command are as follows:
  
-S indicates the total number of data blocks occupied by each Names parameter.
  
-A recursively displays the number of data blocks occupied by each file in the specified directory and its descendants. If neither-s nor-a is specified, only the disk blocks occupied by each directory and its subdirectories in Names are displayed.
  
-B lists disk space usage in bytes (the system defaults to k bytes ).
  
-K lists the disk space usage in 1024 bytes.
  
-C is followed by a total (system default setting ).
  
-L calculate the size of all files, and calculate hard-linked files multiple times.
  
-X skipping directories on different file systems is not counted.
  
The following is an example of the use of the du command:
  
Example 1: view the disk space occupied by the/mnt directory. $ Cd/mnt $ ls-lFR total 10-rwxrwxrwx 2 root ll0 Ju1 3l 00:33 aa *
  
Drwxr-xr-x 2 root l024 Ju1 20 14:16 dev/
  
-Rw-r -- 1 root 6229 Aug 2 0l: 39 s1ack
  
Drwxrwxrwx 2 root 1024 Aug 2 02: 09 var/
  
1 rwxrwxrwx 1 root l0 Aug 2 0l: 51 wei->/home/wei/
  
Dev:
  
Tota1 0
  
Lrwxrwxrwx 1 root 8 Ju1 20 l4: l6 cdrom->/dev/hdb
  
Var:
  
Tata1 37
  
-R-xr-x l root 36064 Aug 2 rawrite. exe *
  
Example 2: list the disk space occupied by each directory, but not the space occupied by each file.
  
$ Du
  
L./dev
  
38./var
  
48.
  
The first column in the output list is the disk space capacity measured in blocks, and the second column lists the directory names that use these spaces.
  
Note that the "du" command without options will run down the directory structure from the current directory until the capacity of all directories is listed. This may be a very long list, and sometimes only one total number is required. In this case, you can add the-s option in the du command to obtain the total number:
  
$ Du? S/mnt
  
/Mnt
  
Example 3: list the space occupied by all files and directories (using option a), and calculate the size in bytes (using option B.
  
$ Du-AB
  
8./dev/cdrom
  
L032./dev
  
36064./var/rawrite. exe
  
37088./var
  
6229./s1ack
  
1l0./aa
  
L0./wei
  
45493.
  
Disk operation
  
Dd command
  
Function: copies the specified input file to the specified output file, and supports format conversion during the copy process. You can use this command to implement the diskcopy command in DOS. Use the dd command to write the data on the floppy disk as a storage file on the hard disk, and then write the storage file to the second disk to complete the diskcopy function. Note that you should delete the storage file on the hard disk with the rm command. Standard input files and standard output files are used by default.
  
Syntax: dd [option]
  
If = input file (or device name ).
  
Of = output file (or device name ).
  
Ibs = bytes: the number of bytes read from the buffer zone.
  
Skip = blocks skip the ibs * blocks block at the beginning of the read buffer.
  
Obs = bytes: the number of bytes written to the buffer zone.
  
Bs = bytes: set the number of bytes in the read/write buffer at the same time (equal to setting ibs and obs ).
  
Cbs = byte: bytes are converted once.
  
Count = blocks only copies the input blocks block.
  
Conv = ASCII converts the EBCDIC code to the ASCIl code.
  
Conv = ebcdic converts an ASCIl code to an EBCDIC code.
  
Conv = IBM converts an ASCIl code to an alternate EBCDIC code.
  
Conv = block converts a variable bit to a fixed character.
  
Conv = ublock converts a fixed bit to a variable bit.
  
Conv = ucase converts lowercase letters to uppercase letters.
  
Conv = lcase converts uppercase letters to lowercase letters.
  
Conv = notrunc: the output file is not truncated.
  
Conv = swab exchange each pair of input bytes.
  
Conv = do not stop processing when noerror occurs.
  
Conv = sync adjusts the size of each input record to the ibs size (filled with NUL ).
  
Example 1: copy the content of a floppy disk to another floppy disk and use/tmp as the temporary storage area. Insert the source disk into the drive and enter the following command:
  
$ Dd if =/dev/fd0 of =/tmp/tmpfile
  
After the copy is complete, extract the source disk from the drive and insert the Target Disk. enter the following command:
  
$ Dd if =/tmp/tmpfile of =/dev/fd0
  
After the floppy disk is copied, delete the temporary file:
  
$ Rm/tmp/tmpfile
  
Example 2: write the net. I file to a floppy disk and set the number of read/write buffers.
  
(Note: the content in the floppy disk will be completely overwritten)
  
$ Dd if = net. I of =/dev/fd0 bs = 16384
  
Example 3: Copy the sfile to the dfile.
  
$ Dd if = sfile of = dfile
  
Fdformat command
  
Floppy disk is a common storage medium. A floppy disk must be formatted before it can be used. then, you can use commands such as tar, dd, and cpio to store data, or you can create an installable file system on a floppy disk.
  
Function: low-level formatting floppy disk
  
Syntax: format [-n] device
  
Note: this command is used to format a floppy disk.
  
-N the disk is not verified after being formatted.
  
Device specifies the device to be formatted. it is usually one of the following devices:
  
/Dev/fd0d360
  
/Dev/fd0h1200
  
/Dev/fd0D360
  
/Dev/fd0H360
  
/Dev/fd0D720
  
/Dev/fd0000020
  
/Dev/fd0h360
  
/Dev/fd0000020
  
/Dev/fd0H1440
  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.