CN110929500B - File comparison method and related device - Google Patents
File comparison method and related device Download PDFInfo
- Publication number
- CN110929500B CN110929500B CN201911089235.1A CN201911089235A CN110929500B CN 110929500 B CN110929500 B CN 110929500B CN 201911089235 A CN201911089235 A CN 201911089235A CN 110929500 B CN110929500 B CN 110929500B
- Authority
- CN
- China
- Prior art keywords
- file
- comparison
- information
- terminal
- content information
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The application provides a file comparison method and a related device, and belongs to the technical field of computers. The file comparison method may include: determining the file types of the first file and the second file; determining comparison information of the first file and the second file according to the file type; acquiring content information of the first file and the second file through a content information reading command corresponding to the comparison information; and comparing the content information of the first file and the second file to obtain a comparison result. The embodiment of the application effectively improves the type range and the comparison flexibility of file comparison.
Description
Technical Field
The present application relates to the field of computer technologies, and in particular, to a file comparison method and a related apparatus.
Background
The file comparison is to compare the file content information of the files to be compared so as to determine the content information difference between the two files. At present, when files are compared, the difference of adding, deleting and modifying between two text files can be compared by using a file comparison command, but the two text files can only be compared, the range of file comparison types is limited, the flexibility of file comparison is low, and the user experience is poor.
It is to be noted that the information disclosed in the above background section is only for enhancement of understanding of the background of the present disclosure, and thus may include information that does not constitute prior art known to those of ordinary skill in the art.
Disclosure of Invention
An object of the embodiments of the present invention is to provide a method and an apparatus for comparing files, which can effectively improve the type range and the comparison flexibility of file comparison.
According to one embodiment of the present application, a file comparison method may include: determining the file types of the first file and the second file; determining comparison information of the first file and the second file according to the file type; acquiring content information of the first file and the second file through a content information reading command corresponding to the comparison information; and comparing the content information of the first file and the second file to obtain a comparison result.
According to another embodiment of the present application, a file comparison apparatus may include: the first determining module is used for determining the file types of the first file and the second file; the second determining module is used for determining the comparison information of the first file and the second file according to the file type; an obtaining module, configured to obtain content information of the first file and the second file through a content information reading command corresponding to the comparison information; and the comparison module is used for comparing the content information of the first file and the second file to obtain a comparison result.
In some embodiments of the present application, the second determination module is further configured to: when the file type is a conventional file and the first file and the second file are text files, taking file contents as the comparison information; when the file type is a conventional file and the first file and the second file are not text files, taking first file description information as the comparison information; when the file type is a directory file, taking file list information as the comparison information; when the file type is any one of a block device file, a character device file, a named pipeline file and a socket file, using second file description information as the comparison information; and when the file type is a symbolic link file, determining the comparison information based on the target file pointed by the symbolic link.
In some embodiments of the present application, the second determination module is further configured to: the comparison information is determined based on the file type of the target file pointed to by the symbolic link.
In some embodiments of the present application, the acquisition module is further configured to: when the comparison information is file content, acquiring content information of the first file and the second file through a first command; when the comparison information is first file description information, acquiring content information of the first file and the second file through a second command; when the comparison information is file list information, acquiring content information of the first file and the second file through a third command; and when the comparison information is second file description information, acquiring the content information of the first file and the second file through a fourth command.
In some embodiments of the present application, further comprising a receiving module configured to: receiving a file comparison instruction, wherein the file comparison instruction comprises the identifier of the first file, the identifier of the second file and the address of a target terminal, and the second file is located on the target terminal.
In some embodiments of the present application, the first determination module is further configured to: determining a file type of the first file from a local; and according to the address of the target terminal, remotely determining the file type of the second file from the target terminal based on a secure network protocol.
In some embodiments of the present application, the acquisition module is further configured to: acquiring content information of the first file from local; and remotely acquiring the content information of the second file from the target terminal based on a secure network protocol according to the address of the target terminal.
In some embodiments of the present application, further comprising an association module configured to: and associating the port number, the user name and the password of the target terminal for the address of the target terminal.
In some embodiments of the present application, the comparison module is further configured to: and comparing the content information of the first file and the second file by using a text comparison command to obtain a comparison result.
In some embodiments of the present application, based on the foregoing scheme, the first file and the second file include: files in Linux or UNIX-like systems.
According to another embodiment of the present application, a file comparison terminal may include: a memory storing computer readable instructions; a processor reading computer readable instructions stored by the memory to perform the method as described above.
According to a fourth aspect of the present disclosure, a computer program medium is disclosed, having stored thereon computer readable instructions which, when executed by a processor of a computer, cause the computer to perform the method as described above.
According to the embodiment of the application, the file types of the files to be compared can be automatically identified, the difference of content information of different attribute comparison information is listed according to different file types, and the type range and flexibility of file comparison are effectively improved. In some embodiments, comparing across terminals differences in content information listing different attribute comparison information according to different file types based on secure network protocols may also be implemented.
Other features and advantages of the present application will be apparent from the following detailed description, taken in conjunction with the accompanying drawings, or may be learned by practice of the application.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application.
Drawings
FIG. 1 shows a schematic diagram of a system to which embodiments of the present application may be applied.
FIG. 2 shows a flow diagram of a file comparison method according to an embodiment of the present application.
FIG. 3 shows a flow diagram of a file comparison method according to yet another embodiment of the present application.
Fig. 4A to 4C are diagrams illustrating a terminal interface in an application scenario of file comparison in the related art according to an embodiment.
FIG. 5 shows a flowchart of file comparison in an application scenario, according to an embodiment of the present application.
Fig. 6A to 6E illustrate terminal interface diagrams in an application scenario of file comparison of the embodiment illustrated in fig. 5.
FIG. 7 is a block diagram illustrating a file comparison apparatus according to the embodiment shown in FIG. 5.
FIG. 8 shows a block diagram of a file comparison apparatus according to an embodiment of the present application.
FIG. 9 shows a block diagram of an electronic device according to an embodiment of the application.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art.
Furthermore, the described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of embodiments of the application. One skilled in the relevant art will recognize, however, that the subject matter of the present application can be practiced without one or more of the specific details, or with other methods, components, devices, steps, and so forth. In other instances, well-known methods, devices, implementations, or operations have not been shown or described in detail to avoid obscuring aspects of the application.
The block diagrams shown in the figures are functional entities only and do not necessarily correspond to physically separate entities. I.e. these functional entities may be implemented in the form of software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor means and/or microcontroller means.
The flow charts shown in the drawings are merely illustrative and do not necessarily include all of the contents and operations/steps, nor do they necessarily have to be performed in the order described. For example, some operations/steps may be decomposed, and some operations/steps may be combined or partially combined, so that the actual execution sequence may be changed according to the actual situation.
Fig. 1 shows a schematic diagram of a system 100 to which embodiments of the present application may be applied.
As shown in fig. 1, the system 100 may include a terminal device 101, a network 102, and a terminal device 103. Terminal apparatus 101 and terminal apparatus 103 can communicate via network 102. The network 102 may be a wired network, a wireless network, or the like.
It should be understood that the number of terminal devices, networks in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, as desired for implementation. For example, the terminal device 103 may be a server cluster composed of a plurality of servers, or a block chain network composed of a plurality of terminals.
The applicant can use the terminal device 101 to obtain the relevant information of the local file; the terminal device 101 may also be used to interact with the terminal device 103 via the network 102 (based on the secure network protocol SSH) to remotely obtain information about files on the terminal device 103. The terminal device 101 may be various devices having computing processing capabilities including, but not limited to, a personal computer, a cell phone, and the like.
In one embodiment of the present application, the terminal device 101 may determine the file types of the first file and the second file; determining comparison information of the first file and the second file according to the file type; acquiring content information of the first file and the second file through a content information reading command corresponding to the comparison information; and comparing the content information of the first file and the second file to obtain a comparison result.
In an embodiment of the present application, the terminal device 101 may further receive a file comparison instruction, where the file comparison instruction includes an identifier of the first file, an identifier of the second file, and an address of the target terminal, where the second file is located on the target terminal.
Alternatively, the operations performed by the server described above may also be performed by the terminal device.
FIG. 2 schematically shows a flow diagram of a file comparison method according to an embodiment of the present application. The execution subject of the file comparison method may be an electronic device having a calculation processing function, such as the terminal device 101 shown in fig. 1. As shown in fig. 2, the file comparison method may include steps S210 to S240.
Step S210, determining the file types of the first file and the second file;
step S220, determining the comparative information of the first file and the second file according to the file type;
step S230, obtaining the content information of the first file and the second file through the content information reading command corresponding to the comparison information;
step S240, comparing the content information of the first file and the second file to obtain a comparison result.
The following describes a specific process of each step performed when comparing documents.
In step S210, the file types of the first file and the second file are determined.
The first file and the second file may be any type of file, such as regular files (which may include plain text files and non-text files), directory files, block device files, character device files, named pipe files, socket files, and the like. The first file and the second file may be located on the same terminal, e.g. both the first file and the second file are located on the terminal device 101 as shown in fig. 1. The first file and the second file may also be located on different terminals, for example, the first file may be located on the terminal device 101 shown in fig. 1, and the second file may be located on the terminal device 103 shown in fig. 1.
When the first file and the second file are both located locally, the file types of the first file and the second file may be determined directly locally through a file type determination command. When a part of the first file and the second file is located locally and the other part is located at the other terminal, the file type determination command may be remotely executed at the other terminal through a secure network protocol (SSH) locally to determine the file type of the other part of the files. It will be appreciated that the first file and the second file may comprise a plurality of files, for example, the first file comprises 5 different files and the second file comprises 3 different files.
Determining the file type of the first file and the second file may be performed using a file type determination command. In one example, a linux command may be used: the ls-l command makes the determination. For example, when the FILE of the first FILE is identified as FILE1, the related information of FILE1 can be returned by using ls-l FILE1 command: -rw-r- -r- -1tt root 45 jun 3016: 00FILE 1. Then, the FILE type of FILE1 is determined to be "regular FILE" in conjunction with a FILE type determination table, for example, by the first initial character (FILE attribute) "of the first character string" -rw-r- ", in the related information:
the file type of the second file may be determined similarly.
In one embodiment, before determining the file types of the first file and the second file, the method may further include: it is determined whether the first file and the second file exist at the target location.
The target location may be local or a remote terminal connected to the local via a network. When the first file and the second file are both located locally, whether the first file and the second file exist can be directly determined locally through a file query command. When a part of the first file and the second file is located locally and the other part is located at a remote terminal connected to the local terminal through a network, a file query command can be remotely executed at the remote terminal through a secure network protocol (SSH) at the local terminal to determine whether the other part of the files exists in the remote terminal. It will be appreciated that the first file and the second file may comprise a plurality of files, for example, the first file comprises 5 different files and the second file comprises 3 different files.
The FILE query command may be an ls command, for example, when the FILE is identified as FILE1, the ls FILE1 command may be used to obtain the returned related information, if the related information is a positive result, it indicates that the FILE1 FILE is queried, and if the related information is a negative result (e.g., no subch FILE or direct) indicates that the FILE1 FILE is not queried.
In one example, if it is determined that one or both of the first file and the second file do not exist in the target location, an error is directly reported to exit the file comparison.
In one example, when the file types of the first file and the second file are different, an error is directly reported and the file comparison is exited; and when the file types of the first file and the second file are determined to be the same, executing the subsequent steps.
In step S220, comparison information of the first file and the second file is determined according to the file type.
The comparison information may be information of content information to be compared for files to be compared (for example, the first file and the second file) of different file types, and for example, when the content information is content information of text itself, the comparison information may be file content. The comparison information may be in the form of an information identifier, such as a character string or name. The file types correspond to the comparison information one by one, the comparison information of the first file and the second file can be determined according to the file types of the first file and the second file, and then the content information corresponding to the comparison information of the first file and the second file is obtained in the subsequent steps.
According to the file type, the comparison information between the first file and the second file is determined, which may be determined by a preset comparison information table, and the comparison information corresponding to the file type may be queried from the preset comparison information table, where the comparison information table, for example:
referring to fig. 3, in an embodiment, determining comparison information of the first file and the second file according to the file type includes:
step S310, when the file type is a conventional file and the first file and the second file are text files, taking the file content as the comparison information;
step S320, when the file type is a conventional file and the first file and the second file are not text files, using first file description information as the comparison information;
step S330, when the file type is a directory file, using file list information as the comparison information;
step S340, when the file type is any one of a block device file, a character device file, a named pipe file and a socket file, using second file description information as the comparison information;
in step S350, when the file type is a symbolic link file, the comparison information is determined based on the target file pointed by the symbolic link.
It should be noted that there is no fixed execution sequence from step S310 to step S350. The step corresponding to the corresponding file type may be executed according to the file type, for example, when the file type is determined to be a directory file, the step S330 may be directly executed to determine the comparison information of the first file and the second file.
Conventional files may include text files, binary files, xml files, db files, and the like. The file content indicates the content itself of the text file; when the file type is a normal file and the first file and the second file are text files, the file contents themselves of the text files may be used as the comparison information. The first file description information indicates the related description introduction information of a regular file (non-text); when the file type is a normal file and the first file and the second file are not text files, the first file description information may be used as the comparison information, wherein the first file description information may include information such as a creation date, a modification date, and a file size of the file.
The directory file is a recording file having a fixed length, and manages a file directory, and stores the file directory in an external storage space in the form of a file. The file list information indicates information of a file list included in the file in the directory. When the file type is a directory file, the file list information may be used as the comparison information.
The block device file, the character device file, the named pipe file, the socket file, and the like are files related to the device, and the second file description information may be used as the comparison information, and the second file description information indicates the description introduction information related to the device and the pipe file.
A symbolic link file contains only one text string that is interpreted by the operating system as a path to another file or directory. It is a stand-alone file whose existence is not dependent on the target file. If a symbolic link is deleted, the target file it points to is unaffected. If the target file is moved, renamed or deleted, any symbolic links to it still exist, but they will point to a file that does not exist anymore. The comparison information may be determined based on the actual target document to which the symbolic link of the symbolic link document points.
In one embodiment, determining the comparison information based on the target document pointed to by the symbolic link includes: the comparison information is determined based on the file type of the target file pointed to by the symbolic link.
The target file pointed by the symbolic link can be obtained through a readlink-f command. For example, when the identifier of the symbolic link FILE is FILE1, a "ready-fFILE 1" command may be used to obtain the target FILE pointed by the symbolic link of the symbolic link FILE1, then determine the FILE type of the target FILE based on the method in step 201, and determine the comparison information of the symbolic link FILE based on the steps shown in fig. 3 according to the FILE type of the target FILE.
In step S230, the content information of the first file and the second file is acquired by a content information read command corresponding to the comparison information.
The content information is specific content information for comparison in the files to be compared indicated by the comparison information, for example, when the text comparison information is file content, the obtained content information of the first file and the second file is the content information of the first file and the second file.
The content information reading command corresponds to the comparison information one by one. The content information of the first file and the second file may be read by using a content information read command. For example, when the first file and the second file are named pipe file1, file description information (e.g., information such as a device number) of the named pipe file1 may be obtained by a "stat file 1" command.
The content information reading command corresponding to the comparison information may be determined by a preset command table, where the preset command table, for example:
content information read command | Comparing information |
cat | Document content |
ls-l | First file description information |
ls-l | File list information |
stat | Second file description information |
In one embodiment, the acquiring the content information of the first file and the second file by a content information reading command corresponding to the comparison information includes:
when the comparison information is file content, acquiring content information of the first file and the second file through a first command;
when the comparison information is first file description information, acquiring content information of the first file and the second file through a second command;
when the comparison information is file list information, acquiring content information of the first file and the second file through a third command;
and when the comparison information is second file description information, acquiring the content information of the first file and the second file through a fourth command.
The first command may be a cat command, the second command may be an ls-l command, the third command may be an ls-l command, and the fourth command may be a stat command.
For example, when the first file is identified as file1 and the comparison information is file content, the content information of the first file1 indicated by the file content may be obtained through the cat file1 command. When the first file is identified as file2 and the first file description information is compared, the content information of the first file2 indicated by the first file description information may be acquired through the ls-l file2 command. When the first file identification is file3 and the comparison information is file list information, the content information of the first file3 indicated by the file list information may be acquired by the ls-l file3 command. When the first file identifier is file4 and the comparison information is the second file description information, the content information of the first file4 of the second file description information may be acquired by a stat file4 command.
In step S240, the content information of the first file and the second file are compared to obtain a comparison result.
The content information of the first file and the second file are both acquired locally (for example, the terminal device 101 shown in fig. 1) in a text form, and then the two pieces of information can be stored into a text file, and the text files corresponding to the content information of the first file and the second file are compared, so that the content information of the first file and the second file is compared, and a comparison result is obtained.
In one embodiment, comparing the content information of the first file and the second file to obtain a comparison result includes:
and comparing the content information of the first file and the second file by using a text comparison command to obtain a comparison result.
The text compare command diff is used to compare the contents of files, in particular two versions of different files, to find where changes are made. The text comparison command diff can accurately compare the text files corresponding to the content information of the first file and the second file, and find out the difference result of the first file and the second file.
It is understood that when the first file or/and the second file are plural, pairwise comparison may be performed in sequence using the file comparison command diff.
In one embodiment, before determining the file types of the first file and the second file, the method further comprises:
and receiving a file comparison instruction, wherein the file comparison instruction comprises the identifier of the first file, the identifier of the second file and the address of the target terminal, and the second file is positioned on the target terminal.
The file comparison instruction is used for triggering and starting a comparison process of the file content information. The file comparison instruction includes file identifiers (identifiers of the first file and the second file) of files to be compared, and an address of a remote terminal (target terminal) when a certain file is located on the remote terminal (target terminal) connected to the local through a network. A file identification of an unspecified address, by default indicating a local file (e.g. identification of the first file). This may trigger a comparison of the file content information across terminals.
For example, a file comparison instruction is provided: rdiff FILE1 IP FILE2, at which point FILE1 defaults to a local FILE and the address IP corresponds to FILE 2. Wherein FILE1 is a FILE name representing any existence of the native machine, and can be any FILE type of linux; the IP stands for a target terminal which specifies that the file is to be compared with the terminal which can be communicated with each other on which network, namely the comparison is carried out; FILE2 represents any FILE name of the target terminal that exists, indicating which FILE of the target terminal to compare with, and may be any FILE type of linux.
It will be appreciated that the instructions may be compared by the file: rdiff a B C that triggers comparison of content information of the plurality of local files A, B, C; the instructions may be compared by the file: rdiff ip 1D ip 2E ip 3F, triggering the comparison of the content information of a plurality of files D, E, F on the destination terminals corresponding to the addresses ip1, ip2 and ip 3; through the file comparison instruction: rdiff ip 1M N ip 2G triggers a comparison of the content information of files M and N on the terminal corresponding to address ip1 with the content information of file G on the terminal corresponding to address ip 2.
In one embodiment, determining the file types of the first file and the second file comprises:
determining a file type of the first file from a local;
and remotely determining the file type of the second file from the target terminal based on the secure network protocol according to the address of the target terminal.
When the first file is located locally, the file type of the first file can be determined directly locally using the file type determination command.
When the second file is located at a target terminal connected to the local network, the file type of the second file may be determined by remotely executing a file type determination command at the target terminal based on a secure network protocol SSH according to an address of the target terminal.
SSH is an abbreviation for Secure Shell, made by the IETF Network Group (Network Working Group); SSH is a security protocol built on an application layer basis. SSH is currently a relatively reliable protocol that provides security for telnet sessions and other web services. By SSH, all transmitted data can be encrypted and DNS spoofing and IP spoofing can also be prevented. An additional benefit is that the data to be transmitted is compressed, thereby increasing the speed of transmission.
In one embodiment, the acquiring the content information of the first file and the second file by the content information reading command corresponding to the comparison information includes:
acquiring content information of a first file from local;
and remotely acquiring the content information of the second file from the target terminal based on a secure network protocol according to the address of the target terminal.
When the first file is located locally, the content information of the first file can be directly obtained locally using the content information reading command.
When the second file is located at a target terminal connected to the local network, the content information of the second file may be obtained by remotely executing a content information reading command at the target terminal based on a secure network protocol SSH according to an address of the target terminal.
In one embodiment, before determining the file types of the first file and the second file, the method further comprises:
and associating the port number, the user name and the password of the target terminal for the address of the target terminal.
The port number, the user name and the password of the target terminal are associated with the address of the target terminal, when the operation is carried out on the address IP, the port number, the user name and the password of the target terminal, which are needed by the ssh remote execution command, aiming at the IP address of a certain target terminal, the port number, the user name and the password of the certain target terminal can be recorded locally, the port number and the user name are automatically used according to the IP, the password is automatically filled in an expect mode, and the purpose that only the necessary parameter of the IP is input and the command is remotely executed through the ssh can be achieved.
In one embodiment, based on the foregoing scheme, the first file and the second file include:
files in Linux or UNIX-like systems.
In the Linux or UNIX-like system, all system contents can be regarded as files, so that the acquisition and comparison of file content information can be realized on any file in the Linux or UNIX-like system according to the scheme.
In an embodiment of the present example, the Linux system may be deployed on a first terminal, where the first terminal is a block node device in a block chain; the UNIX-like system may be deployed on a second terminal, where the second terminal is a block node device in the block chain. I.e. the first terminal is a node in the block chain; the second terminal is also a node in the block chain, and the acquisition and comparison of the file contents on different terminals are realized through the block chain.
Specifically, each node in the block chain has a node identifier corresponding thereto, and each node may store node identifiers of other nodes in the block chain, and may broadcast the file content of the node to the other nodes in the block chain according to the node identifiers (e.g., node IP addresses) of the other nodes. When a FILE comparison command (rdifffile 1 IP2 FILE2, where IP2 is the node identifier of the second terminal) is received at the first terminal, the FILE content of the target FILE (the FILE content of the FILE2 FILE) may be requested from the second terminal according to the node identifier of the second terminal in the FILE comparison command, and after receiving the request, the second terminal may acquire the FILE content and share the FILE content to the first terminal, so that the comparison of the FILE content may be completed at the first terminal. In this example, the second terminal may receive a FILE comparison instruction, and then request the FILE content from the first terminal for comparison, or a FILE comparison terminal preset in the block chain may receive the FILE comparison instruction (rdiff IP1 FILE1 IP2 FILE2, where IP1 is a node identifier of the first terminal and IP2 is a node identifier of the second terminal). It is understood that the blockchain may be composed of a plurality of blocknode devices, for example, 5 terminals of Linux system and 3 terminals of UNIX-like system, and the file content comparison may be implemented on the files on the plurality of terminals in the blockchain according to the requirement.
Due to the characteristics of decentralized and non-falsifiable security and the like of the block chain, the comparison of the file contents on a plurality of terminals is realized through the block chain, and the security of the cross-terminal file content comparison can be improved.
According to the embodiment of the application, the file types of the files to be compared can be automatically identified, the difference of content information of different attribute comparison information is listed according to different file types, and the type range and flexibility of file comparison are effectively improved. In some embodiments, comparing across terminals differences in content information listing different attribute comparison information according to different file types based on secure network protocols may also be implemented. Furthermore, the user experience is effectively improved.
In the related art, only two text files can be compared through a diff command on linux, and effective comparison information cannot be provided for other types of files. And only two text files on the same terminal can be compared through the diff command, so that the difference between the addition and the deletion of the two text files can be obtained.
Fig. 4A to 4C are diagrams illustrating a terminal interface in an application scenario of file comparison in the related art according to an embodiment.
As shown in fig. 4A, the contents of the text file1 are shown.
As shown in fig. 4B, the contents of the text file2 are shown.
As shown in fig. 4C, the result of comparing the contents of text file1 and text file2 using the diff 1.txt 2.txt command is shown.
Wherein diff 1.txt 2.txt can be compared with the addition of a parameter, e.g. -y in the command line parameter indicates that the same part between the file contents is also displayed as described in fig. 4C-W50 indicates the column width.
In the related technology, when the files are compared, only the files of the local machine can be compared by using a diff command, the files cannot be compared across machines, only the information of the text files can be compared, the range of the file comparison types is limited, the file comparison flexibility is low, and the user experience is poor.
FIG. 5 shows a flowchart of file comparison in an application scenario, according to an embodiment of the present application.
Fig. 6A to 6E show terminal interface diagrams in an application scenario of file comparison of the embodiment shown in fig. 5.
FIG. 7 is a block diagram illustrating a file comparison apparatus according to the embodiment shown in FIG. 5.
As shown in conjunction with figures 5 and 6A through 6E and 7,
to begin, the FILE comparison (the first FILE1 and the second FILE2) can be triggered to start locally (the terminal corresponding to the address IP1 shown in fig. 7) by a FILE comparison command rdiff FILE1 IP2 FILE2, wherein the second FILE2 is scheduled to be located at the target terminal (the terminal corresponding to the address IP2 shown in fig. 7).
(1) Judging whether the first FILE1 exists locally, using ls FILE1 command to judge, if the display is as shown in fig. 6A: if no, the FILE or direct indicates that FILE1 does not exist, the error is reported directly and the process is finished. Otherwise, FILE1 is present.
(2) Judging the FILE type of FILE1, and locally determining by using linux command ls-l FILE1 (as shown in fig. 7 performed in a type recognition device in the corresponding terminal of IP 1), obtaining the result shown in fig. 6B, and determining as a regular FILE according to the FILE type determination table by using the first character "-" of the first character string "-rw-r- -.
(3) Obtaining information of FILE1, wherein FILE1 is a conventional FILE, then further obtaining the content type of the FILE through a FILE1 command, if the result returned by the FILE command contains a text word, as shown in fig. 6C, it indicates a text FILE, and the information result of FILE1 is obtained by using cat FILE1 command to obtain the FILE content itself of FILE1 (as shown in fig. 7, IP1 is performed in the type 1 (conventional and text FILE type) information obtaining device in the corresponding terminal); otherwise, only the text description of the information such as the creation date, the modification date, the file size and the like of the file is acquired. If FILE1 is a device FILE, the information of FILE1 can be obtained by using the stat FILE1 command, as shown in FIG. 6D.
(4) Whether the second FILE2 exists or not is determined, and the existence of the second FILE2 in the terminal corresponding to the IP2 can be determined by performing the ls FILE2 command in the IP2 corresponding terminal remotely through the SSH IP2 by a remote connection device connecting the IP1 and the terminal corresponding to the IP2 as shown in fig. 7 based on the secure network protocol (SSH) according to the address IP2 of the target terminal in the FILE comparison command. Otherwise, the error is reported and the file comparison is ended if the error does not exist.
(5) The type of the FILE2 is remotely determined, based on the secure network protocol (SSH), by the remote connection device connecting the IP1 and the corresponding IP2 as shown in fig. 7, and by remotely executing the linux command ls-l FILE2 in the corresponding IP2 through the SSH IP2 (in the type recognition device in the corresponding IP2 as shown in fig. 7), according to the address IP2 of the target terminal in the FILE comparison command, so as to obtain the result as shown in fig. 6E, and the result can be determined as a regular FILE according to the FILE type determination table by the first character "-" of the first character string "-rw-r- -".
(6) And judging whether the types of the FILE1 and the FILE2 are the same, if so, carrying out the next step, and if not, reporting an error and finishing.
(7) The FILE2 information is remotely obtained, the linux command can be remotely executed in the IP2 corresponding terminal through the SSH IP2 by using the cat FILE2 command to acquire the FILE content itself of the FILE1 (as performed in the type 1 (normal FILE and type of text FILE) information acquisition device in the IP2 corresponding terminal shown in fig. 7) through the remote connection device connecting the IP1 and the IP2 corresponding terminal shown in fig. 7 based on the secure network protocol (SSH) according to the address IP2 of the target terminal in the FILE comparison command.
(8) Comparing the information of the FILE1 and the FILE2 can acquire the information of the FILE1 and the FILE2 locally, and acquire the information locally in the form of text, that is, two pieces of information can be stored as text FILEs a and B, and then the information of the FILE1 and the information of the FILE2 are compared by using a diff a B command (in an information comparison device in a corresponding terminal of the local IP1 shown in fig. 7), so as to obtain difference information.
(9) The difference is shown (difference information showing means in the local IP1 counterpart terminal as shown in fig. 7).
(10) And finishing the file comparison.
By applying the embodiment of the application, the file comparison with another terminal can be realized locally, the types of the objects to be compared are automatically identified, and the differences of different attributes are listed according to different file types.
FIG. 8 shows a block diagram of a file comparison apparatus according to an embodiment of the present application.
As shown in fig. 8, the file comparison apparatus 400 may include a first determination module 410, a second determination module 420, an acquisition module 430, and a comparison module 440.
The first determining module 410 may be configured to determine file types of the first file and the second file; the second determining module 410 may be configured to determine comparison information of the first file and the second file according to the file type; the obtaining module 410 may be configured to obtain content information of the first file and the second file through a content information reading command corresponding to the comparison information; the comparison module 410 may be configured to compare the content information of the first file and the second file to obtain a comparison result.
In some embodiments of the present application, the second determination module is further configured to: when the file type is a conventional file and the first file and the second file are text files, taking file contents as the comparison information; when the file type is a conventional file and the first file and the second file are not text files, taking first file description information as the comparison information; when the file type is a directory file, taking file list information as the comparison information; when the file type is any one of a block device file, a character device file, a named pipeline file and a socket file, using second file description information as the comparison information; and when the file type is a symbolic link file, determining the comparison information based on the target file pointed by the symbolic link.
In some embodiments of the present application, the second determination module is further configured to: the comparison information is determined based on the file type of the target file pointed to by the symbolic link.
In some embodiments of the present application, the acquisition module is further configured to: when the comparison information is file content, acquiring content information of the first file and the second file through a first command; when the comparison information is first file description information, acquiring content information of the first file and the second file through a second command; when the comparison information is file list information, acquiring content information of the first file and the second file through a third command; and when the comparison information is second file description information, acquiring the content information of the first file and the second file through a fourth command.
In some embodiments of the present application, further comprising a receiving module configured to: receiving a file comparison instruction, wherein the file comparison instruction comprises an identifier of the first file, an identifier of the second file and an address of a target terminal, and the second file is located on the target terminal.
In some embodiments of the present application, the first determination module is further configured to: locally determining a file type of the first file; and according to the address of the target terminal, remotely determining the file type of the second file from the target terminal based on a secure network protocol.
In some embodiments of the present application, the acquisition module is further configured to: acquiring content information of the first file from local; and remotely acquiring the content information of the second file from the target terminal based on a secure network protocol according to the address of the target terminal.
In some embodiments of the present application, further comprising an association module configured to: and associating the port number, the user name and the password of the target terminal for the address of the target terminal.
In some embodiments of the present application, the comparison module is further configured to: and comparing the content information of the first file and the second file by using a text comparison command to obtain a comparison result.
In some embodiments of the present application, based on the foregoing scheme, the first file and the second file include: files in Linux or UNIX-like systems.
It should be noted that although in the above detailed description several modules or units of the device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functionality of two or more modules or units described above may be embodied in one module or unit, according to embodiments of the application. Conversely, the features and functions of one module or unit described above may be further divided into embodiments by a plurality of modules or units.
FIG. 9 schematically shows a block diagram of an electronic device according to an embodiment of the application.
It should be noted that the electronic device 500 shown in fig. 9 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 9, the electronic apparatus 500 includes a Central Processing Unit (CPU)501 that can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for system operation are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN (local area network) card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
In particular, according to embodiments of the present application, the processes described below with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present application include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The computer program executes various functions defined in the system of the present application when executed by a Central Processing Unit (CPU) 501.
It should be noted that the computer readable medium shown in the present application may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this application, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF (radio frequency), etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present application may be implemented by software, or may be implemented by hardware, and the described units may also be disposed in a processor. Wherein the names of the elements do not in some way constitute a limitation on the elements themselves.
As another aspect, the present application also provides a computer-readable medium, which may be contained in the electronic device described in the above embodiments; or may exist separately without being assembled into the electronic device. The computer readable medium carries one or more programs, which when executed by one of the electronic devices, cause the electronic device to implement the method described in the above embodiments.
It should be noted that although in the above detailed description several modules or units of the device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functionality of two or more modules or units described above may be embodied in one module or unit, according to embodiments of the application. Conversely, the features and functions of one module or unit described above may be further divided into embodiments by a plurality of modules or units.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiments of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the embodiments of the present application.
Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the embodiments disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains.
It will be understood that the present application is not limited to the embodiments that have been described above and illustrated in the accompanying drawings, but that various modifications and changes can be made without departing from the scope thereof.
Claims (11)
1. A file comparison method is applied to a file comparison terminal preset in a block chain, and comprises the following steps:
when a file comparison instruction is received, requesting the first terminal to determine the file type of a first file according to the node identifier of the first terminal in the file comparison instruction, and requesting the second terminal to determine the file type of a second file according to the node identifier of the second terminal in the file comparison instruction, wherein the first terminal is a block node device with a Linux system deployed in a block chain, and the second terminal is a block node device with a UNIX-like system deployed in the block chain;
when the file types of the first file and the second file are different, directly reporting an error and exiting the comparison of the files;
when the file types of the first file and the second file are both conventional files and the first file and the second file are not text files, using first file description information as comparison information, wherein the first file description information comprises one or more of the creation date, the modification date and the file size of the conventional files;
when the file type of the first file and the second file is any one of a block device file, a character device file, a named pipeline file and a socket file, using second file description information as comparison information, wherein the second file description information is used for indicating relevant description introduction information of a device and a pipeline file;
when the file types of the first file and the second file are symbolic link files, determining comparison information based on the file types of the target files pointed by the symbolic links;
acquiring content information of the first file from the first terminal and acquiring content information of the second file from the second terminal through a content information reading command corresponding to the comparison information, wherein the content information is specific content information for comparison in the files to be compared indicated by the comparison information;
and comparing the content information of the first file and the second file to obtain a comparison result.
2. The method of claim 1, further comprising:
when the file type is a conventional file and the first file and the second file are text files, taking file contents as the comparison information;
and when the file type is a directory file, taking the file list information as the comparison information.
3. The method according to claim 2, wherein the obtaining the content information of the first file from the first terminal and the content information of the second file from the second terminal by a content information read command corresponding to the comparison information comprises:
when the comparison information is the file content, acquiring the content information of the first file from the first terminal through a first command, and acquiring the content information of the second file from the second terminal through the first command;
when the comparison information is first file description information, acquiring content information of the first file from the first terminal through a second command, and acquiring content information of the second file from the second terminal through the second command;
when the comparison information is file list information, acquiring content information of the first file from the first terminal through a third command, and acquiring content information of the second file from the second terminal through the third command;
and when the comparison information is second file description information, acquiring the content information of the first file from the first terminal through a fourth command, and acquiring the content information of the second file from the second terminal through the fourth command.
4. The method according to claim 1, wherein the file comparison instruction includes an identifier of the first file and an identifier of the second file, the first file is located on the first terminal, and the second file is located on the second terminal.
5. The method of claim 4, wherein requesting the first terminal to determine a file type of the first file comprises:
according to the node identification of the first terminal, remotely determining the file type of the first file from the first terminal based on a secure network protocol;
and according to the node identification of the second terminal, remotely determining the file type of the second file from the second terminal based on a secure network protocol.
6. The method of claim 4, further comprising, prior to remotely determining the file type of the first file from the first terminal based on a secure network protocol based on the node identification of the first terminal:
associating the port number, the user name and the password of the first terminal for the address corresponding to the node identifier of the first terminal;
and associating the port number, the user name and the password of the second terminal for the address corresponding to the node identifier of the second terminal.
7. The method of claim 1, wherein comparing the content information of the first file and the second file to obtain a comparison result comprises:
and comparing the content information of the first file and the second file by using a text comparison command to obtain a comparison result.
8. The method according to any of claims 1-7, wherein the first file is a file in a Linux system and the second file is a file in a UNIX-like system.
9. A document comparison apparatus, comprising:
the file comparison method comprises a first determination module, a second determination module and a third determination module, wherein the first determination module is used for requesting the first terminal to determine the file type of a first file according to a node identifier of the first terminal in a file comparison instruction when the file comparison instruction is received, and requesting the second terminal to determine the file type of a second file according to a node identifier of the second terminal in the file comparison instruction, the first terminal is block node equipment with a Linux system deployed in a block chain, and the second terminal is block node equipment with a UNIX-like system deployed in the block chain;
a second determination module to:
when the file types of the first file and the second file are different, directly reporting an error and quitting the file comparison;
when the file types of the first file and the second file are both conventional files and the first file and the second file are not text files, using first file description information as comparison information, wherein the first file description information comprises one or more of the creation date, the modification date and the file size of the conventional files;
when the file type of the first file and the second file is any one of a block device file, a character device file, a named pipeline file and a socket file, using second file description information as comparison information, wherein the second file description information is used for indicating related description introduction information of a device and a pipeline file;
when the file types of the first file and the second file are symbol link files, determining comparison information based on the file types of the target files pointed by the symbol links;
an obtaining module, configured to obtain, by a content information reading command corresponding to the comparison information, content information of the first file from the first terminal, and obtain content information of the second file from the second terminal, where the content information is specific content information for comparison in a file to be compared, where the content information is indicated by the comparison information;
and the comparison module is used for comparing the content information of the first file and the second file to obtain a comparison result.
10. A file comparison terminal, comprising:
a memory storing computer readable instructions;
a processor that reads computer readable instructions stored by the memory to perform the method of any of claims 1-8.
11. A computer program medium having computer readable instructions stored thereon which, when executed by a processor of a computer, cause the computer to perform the method of any one of claims 1 to 8.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911089235.1A CN110929500B (en) | 2019-11-08 | 2019-11-08 | File comparison method and related device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911089235.1A CN110929500B (en) | 2019-11-08 | 2019-11-08 | File comparison method and related device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN110929500A CN110929500A (en) | 2020-03-27 |
CN110929500B true CN110929500B (en) | 2022-07-08 |
Family
ID=69852573
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201911089235.1A Active CN110929500B (en) | 2019-11-08 | 2019-11-08 | File comparison method and related device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110929500B (en) |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104021181A (en) * | 2014-06-10 | 2014-09-03 | 浪潮电子信息产业股份有限公司 | Rapid file comparing method under cluster storage system |
WO2017114193A1 (en) * | 2015-12-30 | 2017-07-06 | 阿里巴巴集团控股有限公司 | Text resource file comparison method and device |
CN110069455A (en) * | 2017-09-21 | 2019-07-30 | 北京华为数字技术有限公司 | A kind of file mergences method and device |
CN110162509A (en) * | 2019-04-26 | 2019-08-23 | 平安普惠企业管理有限公司 | File comparison method, device, computer equipment and storage medium |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
TWI546727B (en) * | 2014-12-18 | 2016-08-21 | 群暉科技股份有限公司 | Computer accessible storage medium and method for cross-platform synchronizing attributes of files |
-
2019
- 2019-11-08 CN CN201911089235.1A patent/CN110929500B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104021181A (en) * | 2014-06-10 | 2014-09-03 | 浪潮电子信息产业股份有限公司 | Rapid file comparing method under cluster storage system |
WO2017114193A1 (en) * | 2015-12-30 | 2017-07-06 | 阿里巴巴集团控股有限公司 | Text resource file comparison method and device |
CN110069455A (en) * | 2017-09-21 | 2019-07-30 | 北京华为数字技术有限公司 | A kind of file mergences method and device |
CN110162509A (en) * | 2019-04-26 | 2019-08-23 | 平安普惠企业管理有限公司 | File comparison method, device, computer equipment and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN110929500A (en) | 2020-03-27 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108845816B (en) | Application program updating method, system, computer device and storage medium | |
US10212563B2 (en) | Updating web resources | |
CN102819461B (en) | Desktop synchronous method, device, equipment and system | |
CN113691486B (en) | Method, device, equipment and storage medium for modifying message | |
CN112799688B (en) | Method and device for installing software package in container application, computer equipment and medium | |
CN109391673A (en) | A kind of method, system and the terminal device of management update file | |
CN104182294A (en) | Method and device for backing up and recovering file | |
CN114785685A (en) | Software differential upgrading method and device, electronic equipment and readable storage medium | |
CN112887451A (en) | Domain name resolution method and device and computer equipment | |
CN104079623A (en) | Method and system for controlling multilevel cloud storage synchrony | |
CN111414339B (en) | File processing method, system, device, equipment and medium | |
CN110798358B (en) | Distributed service identification method and device, computer readable medium and electronic equipment | |
CN110929500B (en) | File comparison method and related device | |
CN110990360A (en) | File synchronization method based on network storage device and related components | |
CN112948138A (en) | Method and device for processing message | |
CN103220327B (en) | user information storage method and device | |
US20240106889A1 (en) | Data resource storage method and apparatus, data resource query method and apparatus, and electronic device | |
CN113434190B (en) | Data processing method and device, storage medium and electronic equipment | |
CN112559546B (en) | Database synchronization method, database synchronization device, computer equipment and readable storage medium | |
CN113900991A (en) | Data interaction method, device, equipment and storage medium | |
CN109688204B (en) | File downloading method, node and terminal based on NDN (named data networking) | |
CN110474954B (en) | Block chain-based file sharing method and device, computer equipment and readable storage medium | |
CN109086210B (en) | Navigation information method and device for testing navigation application | |
CN113111042A (en) | Archive file management method and system and electronic equipment | |
CN114625402A (en) | Application updating method and device, electronic equipment and computer readable storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
REG | Reference to a national code |
Ref country code: HK Ref legal event code: DE Ref document number: 40022964 Country of ref document: HK |
|
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |