hackbyte

stuffrenamer.sh

Feb 22nd, 2020
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.41 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # usage:
  4. #
  5. # for LALA in list of directories and such ; do thisscript.sh "$LALA" ; done
  6. # or
  7. # find . -type d -exec thisscript.sh "{}" \;
  8. #
  9.  
  10. DIRNAME="$1"
  11.  
  12. pushd "$DIRNAME" &>/dev/null
  13.  
  14. if [ $(ls|wc -l) -eq 1 ]; then
  15.     OUR_FILE=$(echo -n *)
  16.     mv -iv "${OUR_FILE}" "../${DIRNAME}.${OUR_FILE##*.}"
  17.     popd &>/dev/null
  18.     rmdir -v "${DIRNAME}"
  19. else
  20.     echo "FAIL!"
  21.     exit 1
  22. fi
  23. exit 0
Advertisement
Add Comment
Please, Sign In to add comment