I’m trying to move media and other files which are in a specified directory to another directory and create another one if it does not exits (where the files will go), and create a directory the remaining files with different extensions will go. My first problem is that my script is not making a new directory and it is not moving the files to other directories and what code can I use to move files with different extensions to one directory?
This is what i have had so far, correct me where I’m wrong and help modify my script:
#!/bin/bash
From=/home/katy/doc
To=/home/katy/mo #directory where the media files will go
WA=/home/katy/do # directory where the other files will go
if [ ! -d "$To" ]; then
mkdir -p "$To"
fi
cd $From
find path -type f -name"*.mp4" -exec mv {} $To \;
I’d solve it somewhat like this:
Notes:
mkdir -pwill not complain if the directory already exists, so there’s no need to check for that.findinto awhileloop, you also avoid getting bitten by spaces, becausereadwill read until a newline.\.(mp3|mp4|wma|ogg)$.$(...)will run the given command and stick its output back in the place of the$(...)(called command substitution). It is almost the same as`...`but slightly better (details).echoin front ofmv. (Note that quotes will disappear in the output.)