I use Synology as storage for films from CCTV cameras. After copying a file from the CCTV system to Synology, I convert it to the AVI format. So my files have names like this:


I want to rename it recursively from the names like above for names like this:


Please notice that each filename consist always the same part [M][@0][0].dav.avi

But the problem is that there is no rename command in Synology shell (it sh NOT bash)

I tried to use find command in many different syntaxes but without success. Can You help me to find out solution?

4 Answers 4


You could do:

find . -name '*\[M]\[@0]\[0].dav.avi' -type f -exec sh -c '
  for file do
    echo mv "$file" "${file%"[M][@0][0].dav.avi"}.avi"
  done' sh {} +

(remove echo if that looks all right).

Or if you want to rename all the .dav.avi to .avi, but also remove a [M][@0][0] if there:

find . -name '*.dav.avi' -type f -exec sh -c '
  for file do
    echo mv "$file" "$new"
  done' sh +

Those are POSIX syntax and also work with busybox utilities so should work on synology.

A few notes (based on observations of your own and other answers):


Here is a quick solution using sed to rename the files:

echo "10.01.07-10.01.48[M][@0][0].dav.avi" | sed 's/\[.*dav//'

I know nothing about the Synology shell though, but I hope that sed is available!

Use (for example) in a loop:


for file in *avi; do
    newName=$(echo "$file" | sed 's/\[.*dav//')
    mv -v "$file" "$newName" 



Running the script:

”09.01.07-13.11.48[M][@0][0].dav.avi” -> ”09.01.07-13.11.48.avi”
”110.01.07-13.11.48[M][@0][0].dav.avi” -> ”110.01.07-13.11.48.avi”
”12.01.07-13.11.48[M][@0][0].dav.avi” -> ”12.01.07-13.11.48.avi”


09.01.07-13.11.48.avi   12.01.07-13.11.48.avi

Edit: If you want to use find one way to implement is like in this oneliner:

find . -name "*.avi" | while read fileName; do newName=$(echo "$fileName" | sed 's/\[.*dav//'); mv -v "$fileName" "$newName"; done
”./01.01.07-13.11.38[M][@0][0].dav.avi” -> ”./01.01.07-13.11.38.avi”
”./01.01.07-13.11.39[M][@0][0].dav.avi” -> ”./01.01.07-13.11.39.avi”

sed --version
sed (GNU sed) 4.2.2

find --version
find (GNU findutils) 4.4.2

For recursive files renaming you should use below command.

find . -name "*dav.avi" | while read fileName; do newName=$(echo "$fileName" | sed 's/\[.*dav//'); mv -v "$fileName" "$newName"; done

Change from the above script

(I could not add the comment above so adding answer here with small change in the script that maulinglawns has already mentioned)

  • Use to search for *dav.avi as you will have many recursive files in your Synology storage, so once this files are renamed it should be done again.
  • It is the very small change but will effect if your actual system is ~GBs of data files.

Finally I found out solution. Renaming is done in two steps. It is because it is possible that other CCTV recorders will transmit files with different names but always in DAV format. So simply adding additional line similar to second one, will allow cooperation with other types of recorders:

find $katalog -type f -name *.dav.avi | sed -e "p;s/.dav.avi/\.avi/" | xargs -n2 mv 2>/dev/null
find $katalog -type f -name *.avi | sed -e "p;s/\[M\]\[@0\]\[0\].avi/\.avi/" | xargs -n2 mv 2>/dev/null

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.