In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use the diff of Linux file processing commands, which is very detailed and has a certain reference value. Friends who are interested must finish reading it!
Diff
1. Action
The diff command is used to compare two files and points out that the difference between the two is that it has permissions for all users.
two。 Format
Diff [options] Source file target file
3. [options] main parameters
-a: treat all files as text files.
-b: the difference caused by ignoring spaces.
-B: the difference caused by ignoring blank lines.
-c: use the outline output format.
-H: use heuristics to speed up the search for large files.
-I: ignore case changes.
-n-- rcs: output RCS format.
Cmp
1. Action
The cmp (abbreviation for "compare") command is used to briefly indicate whether there is a difference between the two files, and its permission is for all users.
two。 Format
Cmp [options] file name
3. [options] main parameters
-l: output bytes in decimal mode, and facilitate the output of different files in octal mode.
Cat
1. Action
The cat (abbreviation for "concatenate") command is used to connect and display information about one or more specified files, and its permissions are for all users.
two。 Format
Cat [options] File 1 File 2...
3. [options] main parameters
-n: number the number of lines of all output starting with the * line.
-b: similar to-n, except that blank lines are not numbered.
-s: when you encounter blank lines with more than two consecutive lines, replace them with blank lines on one line.
4. Application example
(1) one of the simplest uses of the cat command is to display the contents of a text file. For example, if we want to see the contents of the README file on the command line, we can use the command:
$cat README
(2)
Sometimes you need to process several files into a single file and save the results of this processing to a separate output file. The cat command accepts one or more files on its input and prints them to its output as a separate file. For example, after numbering the contents of README and INSTALL files (no blank lines), append the contents to a new text file, File1:
$cat README INSTALL File1
(3) another important function of cat is the ability to number rows, as shown in figure 2. This function is convenient for the preparation of program documentation, as well as legal and scientific documentation, and the line number printed on the left makes it easy to reference a part of the document. these are very important in programming, scientific research, business reports and even legislative work.
Figure 2 numbering lines using the cat command / etc/named.conf file has two parameters:-b (only non-blank lines can be numbered) and-n (all lines can be numbered):
$cat-b / etc/named.conf
Ln
1. Action
The ln command is used to create links between files, and its permissions are for all users.
two。 Format
Ln [options] Source file [link name]
3. Parameters.
-f: delete the source file when linking.
-d: allows system administrators to hard-link their own directories.
-s: soft link (Symbolic Link).
-b: back up files that will be overwritten or deleted when linked.
There are two kinds of links, one is called Hard Link, the other is called symbolic link (Symbolic Link). By default, the ln command produces hard links.
A hard connection is a connection made through an index node. In Linux's file system, files saved in disk partitions, regardless of type, are assigned a number called index node number (InodeIndex). In Linux, it is possible to have multiple file names pointing to the same Inode. Generally speaking, this kind of connection is a hard connection. The purpose of a hard connection is to allow a file to have multiple valid pathnames, so that users can establish a hard connection to important files to prevent "accidental deletion". The reason is as mentioned above, because there is more than one connection to the index node of the directory. Deleting only one connection does not affect the Inode itself and other connections. Only when a connection is deleted will the connection of the file's data block and directory be released. In other words, the file will really be deleted. Corresponding to the hard connection, there is another kind of connection in the Lnux system, which is called symbolic connection (Symbilc Link), also called soft connection. Soft-link files are a bit like Windows shortcuts. It is actually a kind of special file. In symbolic links, a file is actually a text file that contains information about the location of another file. Hands-on exercise above we introduced the Linux file processing commands, the following introduce a few examples, you can practice the commands just mentioned.
1. Use symbolic links to quickly access key directories
Symbol
The number link is a very practical function. Suppose there are some directories or files that need to be used frequently, but because of the file and directory structure of Linux, this file or directory is in a very deep subdirectory.
For example, Apache
The Web server document is in the / usr/local/httpd/htdocs of the system, and you don't want to enter such a long path from the home directory every time (in fact, this path is also very difficult to remember). To solve this problem, you can create a symbolic link in the home directory so that when you need to enter that directory, you only need to go to that link. To easily access the directory where the Web server (/ usr/local/httpd/htdocs) documents are located, you can use the following command in the home directory:
$ln-s / usr/local/httpd/htdocs gg so that every time you enter the gg directory, you can access the documents of the Web server. If you no longer access the documents of the Web server, you can delete the gg, but the documents of the real Web server are not deleted.
two。 Use the dd command to import root.ram content in init.rd format into 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 and can be called internally by many Linux systems.
(1) if you want to query the directories in the directory list, the method is as follows:
$ls-l | grep '∧ d'
(2) if you query all files that do not contain a directory in a directory, the method is as follows:
$ls-l | grep '∧ [∧ d]'
(3) call grep with the find command, such as "Chinput" in all C source code, as follows:
$find / ZhXwin-name * .c-exec grep-Q-s Chinput {}\;-print
The above is all the contents of the article "how to use the diff of Linux file processing commands". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 297
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.