Shell script learning notes (10)-File Operations

Source: Internet
Author: User
Tags touch command

File Operations

Get directory content

Ls

Getconf ARG_MAX

Determine whether a file exists

Create a file

Create a general file:

Create a file

1 use the redirection output:> text.txt

2. Use the NULL command:> test. xtx to increase script portability. Sometimes, "> file" May cause syntax errors.

3. Create a hidden file:> .test.txt

4. Run the touch command: touch test.txt.

5. Specify the initialization content when creating the file: echo 'hello'> test.txt

6. Use the ln command to create a copy of another file: ln test1.txt test2.txt

Delete an object

1 rm.test.txt

2 rm-I test.txt will ask whether to delete

3 rm-f test.txt delete without asking whether to delete it.

Create a directory:

Mkdir test

Mkdir-m 711 test-m specifies the directory permission value of 0711

Mkdir-m 700. test hide directory

Mkdir-p t1/t2/t3 multi-level directory. Can be used with-m

Delete directory:

Rmdir test

Rmdir-p t1/t2/t3 multi-layer empty directory

Rm-Rf test non-empty directory

Create a block Device File

Create a character Device File

Create a FIFO file

Create a Socket File

Create a symbolic link file

Get file attributes

In linux, each file has 13 attributes: Device number, inode number, file mode, number of connected files, file owner number, file owner group number, device identifier, and file size, use the file time atime, modify the file content time mtime, change the file Mode Time ctime, block size, and configure the number of blocks

Stat-f/dev/sda1

Stat File

File Format code

Format code for file systems (I .e. partitions)

Chattr lsattr command usage:

Chattr + attribute code file

Chattr = Property Code File

Chattr-attribute code file

Lsattr File

Available Property Code

Chattr.

Compare file differences

Diff and patch commands

Search for file content

Grep-q keyword file-q indicates that no information is generated during search.

Create temporary files

Mktemp command

Example

Case-insensitive file name Interchange

Conversion Encoding

In short, you should be familiar with the usage of these shell commands. Check more manuals and practice. Remember that it is unlikely ..

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.