On 2020-02-12 21:59, Yamaban wrote:
find $source_dir -type f -print0 | xargs -0 -n 1 ln -s -t $targed_dir
The "-n 1" restriction to 'xargs' is not necessary - actually that's the gain from "ln ... -t DIR" to accept more arguments. I'd also suggest to add proper quotes around the shell variables. Re. the use of 'ln': from my experience, I'm getting the best, i.e., least surprising result with the -n and -f options. Finally, a -v doesn't harm to see what 'ln' has done. $ find "$source_dir" -type f -print0 | xargs -0 ln -snvft "$targed_dir" Furthermore, the crucial thing here is to find out the relative path from "$targed_dir" to "$source_dir". The tool 'realpath' can help here. Example: # Source and destination directories are in different hierarchy levels. $ source_dir='src' $ target_dir='d1/d2/d3/dest' $ mkdir -pv "$source_dir" "$target_dir" $ ls -logd "$source_dir" "$target_dir" drwxr-xr-x 2 4096 Feb 20 00:36 d1/d2/d3/dest drwxr-xr-x 4 4096 Feb 20 00:31 src # Determine the relative path between src and dest. $ realpath -m "$source_dir" --relative-to "$target_dir" ../../../../src # Change directory to "$target_dir". $ cd "$target_dir" # Create 'flattened' symlinks of all files in the relative $source_dir in ".". $ find ../../../../src -type f -print0 | xargs -0 ln -nsvft . './2' -> '../../../../src/b/2' './4' -> '../../../../src/b/h/j/4' './5' -> '../../../../src/b/h/i/5' './1' -> '../../../../src/1' './2' -> '../../../../src/2' BTW: As you can see, the file "2" exists several times below $source_dir, and therefore the symlink gets overwritten. To work around that, one could use 'ln -i' to prompt for confirmation, but that only works when xargs opens the tty for the 'ln' child process with the new -o, --open-tty option (since findutils-4.7.0). Have fun, Berny -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org