3

How can I loop through each directory recursively and whenever it finds a folder called VIDEO_TS, let Genisoimage convert that folder's content to an dvd-video iso image, the name of the iso would be the parent folder's name.

The command that I use for a single directory:

genisoimage -o movie_1.iso -dvd-video /shares/media/movies/Movie 1

And this is the script I got:

#!/bin/bash
parent_path=""
full_path=""

for file in $(find /shares/media/ -type d -name 'VIDEO_TS')
do

parent_path="$(dirname -- "$file")"
full_path="$file"

done

So I got the parent path and the full path to the VIDEO_TS directory.

parent_path="/shares/media/Movie One/"
full_path="/shares/media/Movie One/VIDEO_TS/"

How can I get only the Movie One from parent_path? And when I use sprintf to echo both variables, either spaces get removed or replaced with a line break. Is it safe to use those variables with the command?

migrated from serverfault.com Nov 28 '13 at 20:29

This question came from our site for system and network administrators.

  • 1
    Don't use for with the output of find. Either do find ... | while read -r file ... or while read -r file ... done < <(find ...) – Dennis Williamson Nov 28 '13 at 20:58
4

The command you are looking for is basename:

[root@localhost ~] # basename "/shares/media/Movie One/"
Movie One
[root@localhost ~] #

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.