My media player marks video files as having been watched by creating a new file with the exact same name but with an added ".t" extension (in the same folder). For example, after I've watched "SeinfeldS07E02.mp4" it will produce a file named "SeinfeldS07E02.mp4.t"

I want to have all watched video files automatically moved to another folder, and was thinking that perhaps the best way would be via a shell script that will find the *.t file, and then find the original file from which its name was based, and have THAT file moved to another folder. I already have a very simple script that can find and move the *.t file, but I have no idea how to narrow it down further. Is this even doable?

2 Answers 2


To avoid surprises from filenames containing spaces or worse it might be worthwhile to run everything directly from find:

find /PATH/TO/SOURCE -name '*.mp4' \
    -exec sh -c '[ -e "$1.t" ]
                 && mv -- "$1" /PATH/TO/TARGET
                 && rm -- "$1.t"' _ {} \;
  • @Jim Make sure there is no whitespace character after the \ in the first line (it must be the last character on the line). Or leave the \ away and put the second line at the end of the first.
    – nohillside
    Jan 2, 2018 at 10:13
  • This worked fine when I directly entered it into the command line, but when I tried to run it as a shell script, I got the following: (line break) : unknown primary or operator (line break) /mnt/HDD/1.sh: -exec: not found
    – Jim
    Jan 2, 2018 at 10:22
  • @Jim Please read my comment above, you have a typo in your script.
    – nohillside
    Jan 2, 2018 at 10:24
  • Problem solved - I changed the script heading from "#!/bin/sh" to "#!/bin/bash". Thanks to all!
    – Jim
    Jan 2, 2018 at 10:33

for i in $(find /path -type f -name "*.mp4.t") ; do mv $(echo $i | sed "s/.mp4.t/.mp4/") /path/to/otherfolder/ ; done

may be suffisant I guess

simulate it :

[root@h2g2w ~]# mkdir {toto,titi}
[root@h2g2w ~]# touch toto/{a,b,a.t,b.t,c}
[root@h2g2w ~]# for i in $(find toto/ -type f -name "*.t") ; do mv $(echo $i | sed "s/\.t//") titi/ ; done
[root@h2g2w ~]# ls -l titi
total 0
-rw-r--r--. 1 root root 0  1 janv. 15:13 a
-rw-r--r--. 1 root root 0  1 janv. 15:13 b
[root@h2g2w ~]# rm -rf toto titi
[root@h2g2w ~]# #OK only a & b have moved
  • 1
    You should remove the marker file as well,probably
    – nohillside
    Jan 1, 2018 at 14:20
  • Several BashPitfalls here (applicable to other Bourne-like shells - not just bash) Jan 1, 2018 at 14:53

You must log in to answer this question.

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