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:


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

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


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?

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

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.