-1

I am not very familiar with bash scripting, so I need a small help from you guys.

I have a directory on my Gentoo server with several hundred videos and every video has a date in its name (09092015.mp4, 10092015.mp4 etc.). I need a while loop that will copy all those files on new location with qt-faststart and keep their original name.

EDIT:

I have tried this code.

filename=${*.mp4}

while true;

qt-faststart $filename /backup/$filename
fi
done
DroidX
  • 59
  • 1
  • 10
  • 3
    Please show what you have done so far, StackOverflow is not a free code writing service. People will gladly help you with specific problems you might encounter, but you need to show some effort on your own first. – plamut Nov 23 '15 at 13:45
  • That's certainly an attempt in the right direction. Have a look around this site (and the general internet) for how to operate over a set of files with a loop. This isn't quite it. – Etan Reisner Nov 23 '15 at 14:18
  • I am trying to find a solution. If this is needed to be done in PHP or Java it wouldn't be a problem. But, as I said before, it needs to be in BASH. I'll keep trying. – DroidX Nov 23 '15 at 14:23
  • if you want a version that will work in all cases, search for `[bash] find -print0 while `. If you're certain the filenames will always be as described, search for `[bash] for done` Good luck. – shellter Nov 23 '15 at 14:33
  • See [How to iterate over files in directory with bash?](http://stackoverflow.com/questions/20796200/how-to-iterate-over-files-in-directory-with-bash) – agold Nov 23 '15 at 14:35

1 Answers1

2

You can iterate over the files and run qt-faststart:

for filename in *.mp4; do
  qt-faststart $filename /backup/$filename
done

If you want to include files in sub directories you can use find:

for filename in $(find . -name '*.mp4'); do
  qt-faststart $filename /backup/$filename
done
Community
  • 1
  • 1
agold
  • 6,140
  • 9
  • 38
  • 54