#!/bin/bash # # by: Sebastian "gonX" Jensen # # fixes file encoding based on file size: # fixfile.sh file* # # e.g fixfile.sh 03.\ Needs\ M* # # okay so this is pretty simple # basically it compares filesizes between $1 and $2 # it works best with glob selection in your shell # # it's a filename encoding fixer basically # that fixes files being read incorrectly as the wrong file name # for example in a torrent client if [ $# != 2 ]; then echo "usage: fixfile.sh file1 file2" echo " the script will automagically find the correct file" echo " tip: use shell wildcards, e.g fixfile.sh 03.*" exit fi export FILEWITHCONTENT export FILEINCORRECTNAME if [ -s "$1" ]; then FILEWITHCONTENT=$1 else FILEINCORRECTNAME=$1 fi if [ -s "$2" ]; then if [ -s "$1" ]; then echo "Incorrect argument - both files have content!" exit else FILEWITHCONTENT=$2 fi else if [ ! -s "$1" ]; then echo "Incorrect argument - both files are empty!" exit else FILEINCORRECTNAME=$2 fi fi [ "$FILEWITHCONTENT" == "" ] && [ "$FILEINCORRECTNAME" == "" ] && echo "Something went wrong" && exit echo "File that has content: $FILEWITHCONTENT" echo "File that has incorrect name: $FILEINCORRECTNAME" rm "$FILEINCORRECTNAME" && mv "$FILEWITHCONTENT" "$FILEINCORRECTNAME" && echo "done" && exit exit 1