Posts

Showing posts from December 9, 2018

What is a good command for moving a directory containing relative symbolic links to files outside the directory?

Image
Clash Royale CLAN TAG #URR8PPP up vote 0 down vote favorite I like to use relative symlinks when possible because they stay valid even when my filesystem is mounted in a non-root location, for example if I am accessing it remotely. However, if I move a directory which contains relative symlinks, in general those links become invalid. I am looking for a command that I can use to move a whole directory (tree), rewriting only those relative symlinks that point outside the directory so that they still point to the same files. There is a related question on Stack Overflow, How do I move a relative symbolic link?. Also, here on Unix & Linux, find all symbolic links in a directory tree pointing outside that tree, and (referring to a much harder problem) is there some kind of symbolic links that support moving or renaming the target file?. For example, a command called mv-rel which behaves as follows (the other commands being their GNU coreutils versions): $ mkdir foo $ touch

Best practice to continue mv

Image
Clash Royale CLAN TAG #URR8PPP up vote 13 down vote favorite 2 I used the terminal to copy files from one drive to another. sudo mv -vi /location/to/drive1/ /location/to/drive2/ However that suddenly stopped, while some hours into it, and without an error, after creating a directory. My own solution to that is often a mix of hashing and comparing which is mostly a time consuming mess as I now have to recover from an intermediate copy without really knowing which files are missing (written as very long one-liner for zsh — note that this script doesn't work in bash as written): source_directory="/path/to/source_directory/"; target_directory="/path/to/target_directory/"; while read hash_and_file; do sed "s/$source_directory/$target_directory/g" ; done <<<$( comm -23 <( find $source_directory -type f -exec sha256sum "" ; | sed "s: $source_directory: :g" | sort; ) <( find $target_directory -type f -exec sha