So dumb impatient me used the following script on my 19.04 server in an attempt to move a bunch of video files into folders with prefixes :
dirs=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
shopt -s nocasematch
for file in *
do
for dir in "${dirs[@]}"
do
if [ -d "$file" ]; then
echo 'this is a dir, skipping'
break
else
if [[ $file =~ ^[$dir] ]]; then
echo "----> $file moves into -> $dir <----"
mv "$file" "$dir"
break
fi
fi
done
done
No clue where it went wrong, but instead of moving the files to folders it went to a singular output.. so :
----> a1.ts moves into -> A <----
----> a2.ts moves into -> A <----
----> a3.ts moves into -> A <----
----> a4.ts moves into -> A <----
----> a5.ts moves into -> A <----
----> c1.ts moves into -> C <----
----> c2.ts moves into -> C <----
----> c3.ts moves into -> C <----
----> c4.ts moves into -> C <----
----> c5.ts moves into -> C <----
I luckily stopped the process (CTRL+C) as soon as I noticed it wasn't going as intended and didn't go through the whole folder.
So now I've got those files A
and C
, which are less than a Gb, and by the looks of it are a SINGLE video.
There are 50Gb unaccounted for in the total disk use of the folder itself, but the overall disk space of the computer has remained the same. Making me think the files aren't deleted ?
Any help appreciated, thanks :)
Edit : the files are actually gone, only the last file to be written remains, all it took was some time for the disk use info to update.. moral of the story, run your scripts on mock files before !
A
,B
and so on existed before running the script? If not you just renamed the files. All files which names started witha
orA
has been renamed toA
, so only the last renamed file survived, the others are overwritten. To call a variabledir
does not create a directory! – mook765 Sep 14 '19 at 8:12mv "$file" "$dir/"
, with a trailing/
; then if$dir
doesn't exist,mv
will error instead of rename$file
to$dir
. Also considermv -i
andmv -n
. And always do amkdir -p
before moving, for good measure. – marcelm Sep 14 '19 at 19:27