The following shell script will do the thing.

#!/bin.sh
echo "Moving from $1 to $2"
for dir in "$1"/*; do
  if [ -d "$dir" ]; then
    for file in "$dir"/*; do
      if [ -f "$file" ]; then
        echo "${file} -> $2/`basename "$dir"`_`basename "${file}"`"
        mv -v -- "$file" "$2/$(basename -- "$dir")_$(basename -- "$file")"
      fi
    done
  fi
done

type in the terminal
bash filename.sh source_directory destination_directory


On Oct 4, 11:53 am, Phani Bhushan Tholeti <[email protected]> wrote:
> On Mon, Oct 4, 2010 at 11:20, Abhishek Gupta
>
> <[email protected]> wrote:
> > I have a music directory, in which there are say 200 directories
> > corresponding to different movies. In each movie directory there are
> > some music files.
>
> > Now, say a file music_file.mp3 is in folder movie_folder.mp3 . I want
> > to make a shell script such that it renames the file to
> > movie_folder__music_file.mp3 and put it in some folder that I mention
> > to it. Basically, all the files in the subdirectories are to be
> > renamed and to be put in a new directory.
> > Any workaround for this?
>
> Use any Music player like Amarok ;)
>
> > P.S : This is not for managing my music files
>
> You must be cursing me now for the above. But what do you mean by a 
> workaround?
> Some options:
> use
> 1. ls, cut and mv or cp
> 2. (g/m)awk
> 3. Some language like C, python or Perl
>
> > but to have a better
> > insight into the shell scripting.
>
> So obviously I won't give you the code :D. But if you still want it,
> it's definitely on the net.
>
>
>
> > --
> > l...@iitd -http://tinyurl.com/ycueutm
>
> --
> Lots o' Luv,
> Phani Bhushan
>
> Let not your sense of morals prevent you from doing what is right -
> Isaac Asimov (Salvor Hardin in Foundation and Empire)
>
> Please avoid sending me Word or PowerPoint attachments.
> Seehttp://www.gnu.org/philosophy/no-word-attachments.html

-- 
l...@iitd - http://tinyurl.com/ycueutm

Reply via email to