![]() So, if you liked the techniques show here, here’s my advice to you: next time you are confronted with a task similar to the one we just studied, take a look at all of the coreutils documentation and try using them. We saw that we can use nothing but command line tools from the coreutils package to compare the contents of two directories: the technique we used was working exactly the same way several decades ago, and will probably continue to work for a long time. Shasum: WARNING: 1 of 5 computed checksums did NOT matchĪnd we’re done: from the differences of the manifests we know which file are missing or were added, and from the list of checksums we know which files differ. Now we can transfer the a.shasum file to costello: $ scp a.shasum we can use shasum again with the -check option: it will read each line, parsing the file name and expected checksum, then compute the actual checksum for the given file and check if it matches the expected value: $ cd b This gives us a list of lines, so we use xargs (also in coreutils) to convert them into a list of command line arguments 5, and finally write the result in a a.shasum file: find. again but with the -type f option to select only the files and ignore the directories. Here we need to call shasum with the whole list of files, so we call find. We can call shasum with a list of files as arguments, like this: shasum file1.txt file2.txt It will generate the same output if the contents are the same, and if two files are different, there’s almost zero chance their checksum will be equal. Shasum can be used to compute a checksum of the contents of a given file. Well, we can use another coreutils tools called shasum. What about contents of the files themselves ? ![]() That takes care of the contents of the directories. So, we use diff on the manifest files themselves: diff ~/manifest-* Scp manifest-a we have two text files on costello, both containing a list of all the files. Then we use scp to transfer the A manifest to costello: # On abbot Finally, we use an angle bracket ( >) to write the output of sort to a file in the home directory: ( ~/manifest-a): we must not write the manifest-a file inside the a directory, otherwise the manifest may contain itself!.( sort is also part of the coreutils package). The order of the files returned by find are not deterministic and can change form one file system to another, so we use a pipe ( |) to take the output of find and pass it to the sort command.lists all the files and directories inside the current working directory. Here’s we can do.įirst, we log in to abbot: ssh we go inside the a directory: cd a We can, however, transfer small files between the two servers. Now let’s assume A and B are on two different remote servers: let’s call them abbot and costello respectively.Īlso, let’s assume A and B contains lots of big files, so we cannot copy the A directory from abbot to costello and use the previous technique. Even when it is not installed, an other package (like busybox) is usually here to provide similar functionality.Īnyway, there is a coreutils command named diff we can use for the task at hand:īy the way, if git is installed on the remote server, we can also use it, with nice options like -stat or -word-diff 3: $ git diff -stat a bģ files changed, 2 insertions(+), 2 deletions(-) ![]() It contains a collection of useful, small command line programs. Now let’s assume A and B are both on a remote server running Linux 1 and we can’t open a remote graphical session there.Ĭoreutils is a package which is both very old and present in almost any Linux operating system. On the bottom panes, since a.txt is selected, we can see the differences in the contents.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |