Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>
Recently, when testing a process, the running process reported an error, so check the script, modify and retest. The script has been changed, but when running a certain step in shell
, it encountered an error such as the title
$ mv MP_genus_network_files/ tax_network
mv: cannot move `MP_genus_network_files/' to `tax_network/MP_genus_network_files': Directory not empty
This error is as follows: MV
if something moved by the command already exists in the target path (not empty), it cannot be moved. This is a protection mechanism of MV
to prevent error coverage
But this is not friendly when it happens in the process. For various reasons, analysts may report an error when they run to the intermediate step, but the process file has been generated. If they modify the script and run it again, they will not be able to cover it. As a result, the process will be forced to report an error and exit again. This is not what we want. How to set this factor in the automation process?It’s long and smelly to judge the conditions, and there are so many file directories that we can’t judge one by one. It is better to use Rsync
instead of MV
command here
rsync -a MP_genus_network_files/ tax_network/MP_genus_network_files
Note that if the directory file should be used as a subdirectory of the target directory, the name of the subdirectory should also be added to the target directory, otherwise only the files contained in the subdirectory will be added
Do not forget to delete the original directory file after copying:
rm -rf MP_genus_network_files/
Obviously, using CP - R
is the same. What’s the difference between using Rsync
and CP
to back up files?Because this is not the focus of this article, it is just a simple list:
Rsync
is equivalent to copying files from the source to the destination, and parameters can be set to maintain the properties of many files and folders. For the backup of copying files, Rsync
is better than CP
in general, because Rsync
only copies those changed contents. But this is not absolute. For example, CP - U
can achieve the same effect
Ref: https://askubuntu.com/questions/269775/mv-directory-not-empty Ref: https://www.crifan.com/linux_ command_ rsync_ vs_ cp/