Getting Started with Linux-file management

Source: Internet
Author: User
Tags touch

We know that Linux has a mind "everything is a file (including hardware)", this is a basic document management experience

File system structure elements

File system and directory structure

Features of Linux files:

    1. File names are case sensitive
    2. To. The opening file is a hidden file (available through ls–a viewing
    3. The file has two types of data

Metadata: Metadata (File attributes: Type, permissions, dependencies, size, time, etc.)

Data: Information (the contents of the file itself)

4. Maximum 255 bytes of file name

5. Classification of documents

-: Normal file D: Directory file B: Block device

C: Character device L: Symbolic link File P: Piping file pipe

S: Socket file socket

Cd: Change Directory

Switch to the top level directory: CD.

Switch to the current user home directory: CD (back to the root directory)

Switch to previous working directory: CD-(can only switch between two directories)

Creating and Viewing Files ls

LS (list): Lists the file name, if you do not specify a file name or directory name, the current directory is listed, and the file name of the first-level subdirectory is automatically expanded by default

Ls-a Show all files, including hidden files

Ls-l = (ll) lists the file type, permissions, number of links, owner, group, size, time, name

Ls-d list directory but not catalog

Ls-r Directory recursive pass (not to cite examples, I have a endless list of Cao)

Stat

Stat file name to view the status of the file, our main concern is three timestamp::

Access time: atime, read file contents (change on Access)

Modify Time: Modified, Mtime, change the contents of the file (changes in the contents of the file itself)

Change time: Changing times, CTime, metadata changes (changes in file metadata)

Touch

Touch file name If the file does not exist, create an empty file and update the timestamp if the file exists

Mkdir

mkdir Directory Name

Mkdir-p a/b/c/d/e Continuous creation of multi-level catalogs

Copy and delete files CP

CP Target File Destination file (if the destination file does not exist, create a change file, but only one level file can be created, level two does not:

Cp-r/etc/app/123/234/456 will error)

Cp-r or-R recursive replication, such as source include directory, must be recursive to replicate

Cp-d when the source of a copy is a soft link, the copied file is also a soft link, and if you do not add D, the full source file is copied

Cp-p reserve the right to copy files, Owner,group, timestamp unchanged

CP-V Show Replication Details

Rm

RM–RF * Force Delete all Files

RM–RF/Use with caution

Index node

In the current file system, the file is divided into two parts: blocks and nodes, the data stored in the block, and the node stores the metadata of the file.

A node (inode) is a table item that contains information about a file (metadata), including:

1. File type, permissions, Uid,gid

2. Number of links (pointing to the number of path names for this file name)

3. The size of the file and the different timestamps

4. Data block pointers to files on disk

5. Additional data about the file

For a file, there is only one node (the Inode node is like the file's ID)

The inode is only 126B (now it's as big as 256B) and a node size is how 2b,inode stores the file.

The inode is divided into 12 direct pointers, an indirect pointer, a double-block pointer, and a triple-indirect block pointer

An indirect pointer is a pointer to a block to store the inode.

We assume that a block (block) size is 1K, then the maximum capacity of the files we store is:

(12*1k +256*1k+256*256*1k+256*256*256*1k)/1024/1024=16g

If you have a large disk storage file, you can increase the block capacity performance (your hands are less)

The nature of the catalogue:

We have to understand that the name of the file is not unique, but the inode number is unique between the texts.

There is no sub-file in the block of the argument, all files are a peer relationship, the directory of the Inode storage directory metadata, directory block storage is the child file name and sub-file inode number

File reference one is inode number

A person is referring to a file by file name

a directory is a mapping between a file name and an inode number in a directory

The essence of the CP command:

allocate a free inode number to generate a new entry in the Inode table

Create a catalog entry in the directory, associating the name with the inode number

Copy data to generate a new file

The essence of the MV command

1. If the target and source of the MV command are in the same file system as the MV command

Create a new directory entry with a new file name

Delete old directory entries corresponding to older file names

does not affect the Inode table (except timestamp) or data location on disk: No data is being moved!?

2. If the target and source are in a different file system, MV is equivalent to CP and RM

The essence of the RM command:

The number of links is decremented so that the inode number released can be reused

Put data blocks in the free list

Delete a catalog entry

The data is not actually deleted immediately, but is overwritten when another file uses the data block.

Hard Links

Let's do an experiment.

1. We create two directory Dir1,dir2, and a file a and input content to it hi

2. Create a hard link in dir1 b,dir2 create a hard link B and view the Ls–irl

3. Delete A (at this point the B,c content is unchanged)

4. Modify B in Dir1 (the contents of C are also changed)

or the same thing. A file has only one inode . number as long as the Inode No matter how many names he has is the same file, just like people can have multiple names, but only one ID number

Use an example of an image to represent a hard link, a to call C, but he does not have C's phone, B has, b to tell a phone number, after a to contact C will not need B

We can also learn about the

1. Once a hard link is created, there is no source and destination file relationship

2. Hard links must be under the same partition

3. Hard links cannot be created on a directory

4. The number of hard links in the directory contains the name of the directory itself, as well as the. and subdirectories.

Soft connection

Also, let's give an example

1 Dir1 creates a soft connection to B b.txt through relative paths

2 Create a soft connection for B in Dir1 b1.txt through the absolute path and view

3 Remove B (B.txt,b1.txt are not available), and view

4 re-create a B and enter Hello, and view (both available)

This is good a to call C, but he does not have C phone, B has, b with their own mobile phone to dial the C number to a, after a again to contact C still need b

1. Soft connections are equivalent to WinDOS shortcuts

2. Soft links can span partitions

3. can be relative or absolute, it is recommended to go to the final directory when creating a relative path, and then create

4. Delete source, soft link is not available, while soft connection does not care what the source is, as long as the source is on the line

5. Soft connection storage is the address

6. Soft connection is equivalent to creating a new file

Getting Started with Linux-file management

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.