I'm trying to find a file, then create a hard link with the same name in a different directory. But this is not working, if I take the -exec and after off, it displays one result. I already have it working with cp, but I've decided to make a hard link instead.
find . -iname "*sample*" -exec link {} ~/{} \;
The problem comes from the fact that {} contains the path of the file found; hence ~/{} is not a path in ~ but in some nonexistent sub-directory.
I didn't find a way to get the {} basename using find neither xargs.
Here is one solution, which works but is unsafe:
find . -iname "*sample*" | while read f ; do link "$f" "$HOME/${f##*/}" ; done
You may add a filter between find and read to get rid of "dangerous" file names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With