0

The aim of my script:

  1. look at all the files in a directory ($Home/Music/TEST) and its sub-directories (they are music files)
  2. find out what music genre each file belongs to
  3. if the genre is Heavy, then move the file to another directory ($Home/Music/Output)

This is what I have:

#!/bin/bash
cd Music/TEST
for files in *
do
  if [ -f "$files" ];then
    # use mminfo to get the track info
    genre=`mminfo "$files"|grep genre|awk -F: '{print $2}'|sed 's/^ *//g'|sed 's/[^a-zA-Z0-9\ \-\_]//g'`
    if [ $genre = Heavy ] ;then
      mv "$files" "~/Music/Output/$files"
    fi
  fi
done

Please tell me how to write the mv command. Everything I have tried has failed. I get errors like this:

mv: cannot move ‘3rd Eye Landslide.mp3’ to ‘/Music/Output/3rd Eye Landslide.mp3’: No such file or directory

Please don't think I wrote that mminfo line - that's just copied from good old Google search. It's way beyond me.

Blorgbeard
  • 93,378
  • 43
  • 217
  • 263
user3167628
  • 1
  • 1
  • 2

3 Answers3

4

Your second argument to mv appears to be "~/Music/Output/$files"

If the ~ is meant to signify your home directory, you should use $HOME instead, like:

mv "$files" "$HOME/Music/Output/$files"

~ does not expand to $HOME when quoted.

David T. Pierson
  • 633
  • 4
  • 10
  • +0 The answer is fine, but it's a little odd that `~` doesn't appear in the error message, since `mv` should have received it as part of the second argument. I think this combined with ensuring that `~/Music/Output` exists is the full correct answer. – chepner Jan 07 '14 at 15:47
0

By the look of it the problem occurs when you move the file to its destination.Please check that /Music/Output/ exits from your current directory.Alternatively use the absolute path to make it safe. Also it's a good idea not use space in the file-name.Hope this will helps.:)

kta
  • 17,024
  • 7
  • 58
  • 43
-1

Put this command before mv command should fix your problem.

mkdir -p ~/Music/Output
BMW
  • 34,279
  • 9
  • 81
  • 95