My case is that I have multiple .m3u8 and .ts files existing in their corresponding asset folder, e.g.,

/vod/CDN/ABC/index/.m3u8 and .ts 
/vod/CDN/DEF/index/.m3u8 and .ts
/vod/CDN/XXX/index/.m3u8 and .ts

I want to find all the /index/ directories and separately move their *.m3u8 and *.ts to the corresponding new-created directories. E.g., moving *.m3u8 to **/hls/index/** and moving *.ts to **/index/hls/**

The result shall be like:


Can some experts shed some lights on how to compose a bash script to do the above tasks?

  • Each /index contains many .m3u8 and many .ts files
    – S. Chen
    Sep 27, 2017 at 12:44
  • what is the purpose of hls and its order? Sep 27, 2017 at 12:54
  • Are these index directories always on the same level or could they be on different levels e.g. GHI/JKL/index ? Sep 27, 2017 at 13:09
  • The index directories are on the same level. Only ABC/index or GHI/index
    – S. Chen
    Sep 27, 2017 at 14:02

1 Answer 1


This is a low-level solution but you could create the directories if there aren't too many and then use mv `find / -name *.extension` /destinationPath
Just repeat for each file extension, changing the file extension and destination path. Depending on how scattered your files are, choose an appropriate search point (I choose the root / ). This would be optimal if you only have several different extensions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .