rcmaehl

Move Here

Jul 12th, 2011
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.46 KB | None | 0 0
  1. #!/bin/bash
  2. #Revision 0x1
  3. shopt -s extglob
  4.  
  5. confirm() {
  6.   read -p "$1 [Y/n] "
  7.   [[ -z $REPLY || $REPLY = [Yy]?([Ee][Ss]) ]]
  8. }
  9.  
  10. while IFS= read -rd '' f <&3; do
  11.   new=./${f##*/} n=$new i=0
  12.   while [[ -e $n ]]; do
  13.     n=$new.$((++i))
  14.   done
  15.   if ((!i)) || confirm "file '$new' exists, mv to '$n'?"; then
  16.     mv "$f" "$n"
  17.   fi
  18. done 3< <(find . -mindepth 2 -type f -print0)
  19.  
  20. if confirm 'delete dir structure?'; then
  21.   find . -depth -type d -empty -delete
  22. fi
Advertisement
Add Comment
Please, Sign In to add comment