Linux Command File Processing Command diff

Source: Internet
Author: User

The following describes the 60 required Linux commands that must be mastered by new users. If you have mastered these commands, your technology will be greatly improved, we hope that the technology will be greatly improved after reading this article.

Diff
1. Role
The diff command is used to compare two files and indicate the differences between the two. The permission is granted to all users.
2. Format
Diff [options] target file of the source file
3. [options] Main Parameters
-A: process all files as text files.
-B: Ignore spaces.
-B: Ignore empty rows.
-C: Use the outline output format.
-H: Use the test method to accelerate search for large files.
-I: Ignore case sensitivity changes.
-N -- rcs: the format of the output RCS.
Cmp
1. Role
The cmp "compare" command is used to briefly identify whether there are differences between the two files. Its permission is granted to all users.
2. Format
Cmp [options] File Name
3. [options] Main Parameters
-L: outputs bytes in decimal format, and outputs different octal values in two files.
Cat
1. Role
The cat "concatenate" command is used to connect to and display information about one or more specified files. Its permission is granted to all users.
2. Format
Cat [options] File 1 file 2 ......
3. [options] Main Parameters
-N: Number of all output rows starting from the first line.
-B: similar to-n, except that the blank row is not numbered.
-S: When there are two or more consecutive blank rows, it is replaced by a blank row.
4. Application Example
1) The simplest use of the cat command is to display the content of a text file. For example, you can run the following command to view the content of the README file:
$ Cat README
2)
Sometimes several files need to be processed into one file, and the processing result is saved to a separate output file. The cat command accepts one or more files on the input and prints them as a separate file to its output. For example, add the content of the README and INSTALL files to the blank row of the row number without adding), and then append the content to a new text file File1:
$ Cat readme install File1
3) Another important function of cat is to number rows, as shown in figure 2. This function is convenient for the compilation of program documents and legal and scientific documents. printing the row number on the left makes it easy to compile a part of the reference document, these are important in programming, scientific research, business reports, and even legislation.
Figure 2 use the cat command/etc/named. -B can only number non-blank rows) and-n can number all rows) two parameters:
$ Cat-B/etc/named. conf
Ln
1. Role
The ln command is used to create links between files. Its permission is for all users.
2. Format
Ln [options] source file [Link name]
3. Parameters
-F: when the link is completed, the source file is deleted first.
-D: allows system administrators to hard link their directories.
-S: Symbolic Link ).
-B: Back up the files that will be overwritten or deleted during the link.
There are two types of links: Hard Link and Symbolic Link ). By default, the ln command generates a hard link.
Hard connection refers to the connection through the index node. In a Linux File System, a file stored in a disk partition is assigned with an index node number (InodeIndex) No matter what type it is ). In Linux, multiple file names direct to the same index node. Generally, this type of connection is hard connection. A hard connection allows a file to have multiple valid path names. In this way, you can create a hard connection to an important file to prevent "accidental deletion. The reason is as described above, because there is more than one connection to the index node of the directory. Deleting only one connection does not affect the connection between the index node and other nodes. Only when the last connection is deleted will the connection of the data block and directory of the file be released. That is to say, the object will be deleted. In contrast to hard connection, there is another connection in the Lnux system, called symbolic connection Symbilc Link), also called soft connection. Soft-link files are similar to Windows shortcuts. It is actually a type of special file. In a symbolic connection, a file is actually a text file containing the location information of another file. In the hands-on exercises, we have introduced the Linux File Processing commands. The following describes several examples. You can start to practice the commands you just mentioned.
1. Use symbolic links to quickly access key Directories
Character
Id link is a very useful function. It is assumed that some directories or files need to be frequently used, but these files or directories are in deep subdirectories due to Linux Files and directory structures.
For example, Apache
The Web server documentation is located in the system's/usr/local/httpd/htdocs, and does not want to enter such a long path from the main directory every time (in fact, this path is also hard to remember ). To solve this problem, you can create a symbolic link in the main directory, So that you only need to enter this link when you need to enter this directory. To conveniently enter the directory of the Web server (/usr/local/httpd/htdocs) document, run the following command in the main directory:
$ Ln-s/usr/local/httpd/htdocs gg so that you can access the Web server documentation every time you enter the gg directory. If you no longer access the Web server documentation, delete the gg file, the real Web server documentation is not deleted.
2. Run the dd command to import the root. ram content in init. rd format to the memory.
Dd if =/dev/fd0 of = floppy. fd
Dd if = root. ram of =/dev/ram0 #
3. grep Command System Call
Grep is one of the most widely used commands in Linux/Unix. It can be called in many Linux systems.
(1) to query the directories in the directory list, use the following method:
$ Ls-l | grep 'cmdd'
(2) If you query all files in a directory that does not contain the directory, the method is as follows:
$ Ls-l | grep 'partition [partition d]'
(3) Use the find command to call grep, such as "Chinput" in all C source code. The method is as follows:
$ Find/ZhXwin-name *. c-exec grep-q-s Chinput {}\;-print

We hope the above Linux commands will help you.

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.