Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ -z "$2" ]; then
  4. echo "Usage: copy_with_links one_or_more_source_files target_directory/"
  5. exit 1
  6. fi
  7.  
  8. set -e
  9.  
  10. f=("$@")
  11.  
  12. d=${f[${#f[@]}-1]}
  13. d=$(readlink -f "$d")
  14.  
  15. # remove the target directory from list of files
  16. unset f[${#f[@]}-1]
  17.  
  18. for a in "${f[@]}"; do.
  19. b=$(readlink -f "$a")
  20. dn=$(dirname "$b")
  21.  
  22. for q in $(find -L "$dn" -maxdepth 1 -mindepth 1 -samefile "$b"); do
  23. cp -ai "$q" "$d/"
  24. done
  25. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement