Linux (3) disk and file system Management/view hard disk, memory space/File system operations/file compression and packaging

Source: Internet
Author: User
Tags bz2

I. Disk and file System management

1. Partitioning and file systems
Partitioning: record the start and end cylinders of each partition
MasterBoot recorder: Records partition data and logs all partition information on the hard disk
After partitioning, format the partition as a file system that the system can recognize
The minimum physical storage unit for a disk is: sector
The minimum storage unit for the format file system when partitioning: logical block, sector-based, size 2 N-Times, but one block can hold only one file
Linux ext2 file system each file content is divided into two parts: the properties of the stored file (in the Inode), the contents of the file (in the block)

Cases:

Read File System Information: DUMPE2FS /dev/sda1
data read: log + meta data + data store record. cpu> main Memory (RAM) > Hard disk, in order to speed up, Linux in the way of asynchronous processing, first read the file from the hard disk, the block data will be stored in memory as the main memory of the buffer, if modified, becomes dirty data, must be written back to the hard disk.
load point: must be a directory, that is, enter the file system entrance
Linux Supported file systems:
(1) Traditional file system: Ext2,ms-dos,fat
(2) journaled file system: Ext3,ntfs
(3) Network File system: NFS

2. Operation of the file system

(1) View Current disk Capacity: (General use Df-h)
DF (disk free)-A is/proc, size 0, in-memory/-I view inode/df-h file name to view the use of files
(2) viewing individual file sizes (du-k/m/a/)
(3) Create the connection file Ln-s /bin/huhu/huhu, then the actual reading after entering/huhu is the content of/bin/huhu
(4) partition: fdisk-l device name (do not add a number, partition for the entire hard disk device, not a partition)
Delete partition: D select partition number p to view the partition information
(5) disk format : MKE2FS device Name


3. Create virtual memory swap (/dev/zero, is an input device that you can use to initialize the file.)
(1) using the DD command, create a 64M file in the/tmp directory
DD If=/tmp/zero Of=/tmp/swap bs=4k count=16382
[[email protected]/]$ dd If=/dev/zero of=/tmp/swap bs=4k count=16382
16382+0 Records in
16382+0 Records out
67100672 bytes (() copied, 9.66832 s, 6.9 mb/s
DD: convert command and copy
If: the input file format to convert
Of: Output files
BS: size of a partition
Count: How many partitions, that is, a BS
(2) Use Mkswap to convert the/tmp/swap file format to the virtual memory format
Mkswap/tmp/swap

[Email protected]/]$ Mkswap/tmp/swap
Mkswap:/tmp/swap:warning:don ' t erase bootbits sectors
On whole disk. Use-f to force.
Setting up Swapspace version 1, size = 65524 KiB
No label, UUID=CE0A57A9-DE6E-4714-BBD6-C4E81F8264DE

(3) Start/tmp/swap with Swapon (you can view memory usage with free)
Swapon/tmp/swap
(4) Swapoff/tmp/swap close swap file

two. File compression and packaging (note: When using gzip or bzip2 without parameter compression, the source file disappears, but the source and destination files are present in tar)
The name of the common compressed file: (tar is primarily to back up important files, DD can back up the entire disk and partition)
(1) Files compressed by *.bz2:bz2 program Files
(2) *.gz:gzip Program compressed files
(3) *.tar:tar program packaging data, and has not been compressed (the TAR program can package multiple files into a file (or directory))
(4) The data packaged by the *.tar.gz:tar program is also compressed with gzip.
(5) *. Z: Files compressed using the Compress program
1. Gzip/zcat
gzipA (file name): Package file a a.gz, the original does not exist
ZcatA.gz: Viewing the contents of a compressed file
gzip-dA.gz (decompression): Unzip a.gz to A, the original compressed file does not exist
gzip-c A (file name) > new Compressed file name: Package file A as a.gz, original still exists, processed with data flow redirection
You can also use gzip-d a.gz >b A and B two files appear at this time
gzip-(1-9)File name: Compression level, 9 best but slower, typically 6
2. Bzip2/bzcat/bunzip2
(1) bzip2 file name > new file nameCompress and rename
(2) Bzcat*.BZ2 Viewing Compressed file contents
[Email protected] desktop]$ Bzcat d.txt.bz2
I miss you ~
(3) bzip2-d*.BZ2 unzip or compress files with BUNZIP2 can also
3. Tar (parameter must end with F, the first three parameters cannot exist simultaneously, generally CVF,XVF,TVF)
(1)-C compression
(2)-X decompression
(3)-T view tar files
(4)-V compression shows the file name as shown in the following procedure
[Email protected] desktop]# TAR-CVF Fee.txt.tar fee.txt
Fee.txt
[Email protected] desktop]# TAR-CVF Yy.tar yy
yy/
Yy/d.txt
(5)-F Use file name, usually followed by the file name directly
(6)-Z compression with gzip mode
(7)-j compressed by bzip2 method
(8)-P use original attribute of source file
(9)-P uses absolute path to compress
(Ten)-n ' 2016/02/14 ' It's a new pack than time.
(one)--exclude file is not packaged--exclude file name-GCVF
Example:
(1) Packaging yy folder into Yy.tar
[Email protected] desktop]$ TAR-CVF Yy.tar yy
yy/
Yy/fee.txt
yy/y/
Yy/d.txt
(2) View the contents of a packaged file
[Email protected] desktop]$ tar TVF yy.tar
Drwxrwxr-x Yuanyuan/yuanyuan 0 2016-01-26 17:49 yy/
-rw-rw-r--Yuanyuan/yuanyuan 10240 2016-01-26 02:11 yy/fee.txt
Drwxrwxr-x Yuanyuan/yuanyuan 0 2016-01-26 17:49 yy/y/
-rwxrwxr-x Yuanyuan/yuanyuan 2016-01-26 00:39 yy/d.txt
(3) Unpack the package file
[Email protected] desktop]$ tar xvf yy.tar
yy/
Yy/fee.txt
yy/y/
Yy/d.txt
(4) Packaging yy with the Gzip tool
[Email protected] desktop]$ TAR-ZCVF yy.tar.gz yy
yy/
Yy/fee.txt
yy/y/
Yy/d.txt
(5) Unzip the file for gzip package backup
[Email protected] desktop]$ TAR-ZXVF yy.tar.gz
yy/
Yy/fee.txt
yy/y/
Yy/d.txt
(6) Use the Bzip2 tool to package yy as a y1y.tar.gz
[Email protected] desktop]$ TAR-JCVF y1y.tar.gz yy
yy/
Yy/fee.txt
yy/y/
Yy/d.txt
(7) After packaging yy directly decompression, do not produce intermediate files
Tar-cvf-yy | TAR-XVF-
4.dd (except for replication, the biggest use is backup)
dd if= input file of = Output file bs= (block size, default 512 bytes) Count=bs number
(1) Backing up the/dev/hda MBR
DD If=/dev/hda of=/tmp/mbr.back bs=512 count=1
(2) Backup/DEV/HDA1 entire partition
DD if=/dev/hda1 of=/some/path/file name
The of path cannot be in the IF directory, otherwise it always loops!!!

Linux (3) disk and file system Management/view hard disk, memory space/File system operations/file compression and packaging

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.