I am trying to create a bash script that moves/renames (and / or creates a symbolic link) to all video files that are shorter than 3 min.

So far I have this Find command:

find "$findpath" -maxdepth "2" -type f -name '*.mp4' -print -exec avprobe -v error -show_format_entry duration {} \;

and then

if [ $duration -ge $DUR_MIN -a $dur -le $DUR_MAX ]
cd "$path2"
ln -sFfhv "$path1$file" "$file2"

1 Answer 1


Does this do what you want?

dur_max=3600 # or whatever you want the max to be

# find the appropriate files and deal with them one at a time
find "$findpath" -maxdepth 2 -type f -iname '*.mp4' -print |
    while read file ; do
        # read duration
        duration="$(ffprobe -v quiet -print_format compact=print_section=0:nokey=1:escape=csv -show_entries format=duration "$file")"
        # trim off the decimals; bash doesn't do floats
        if [[ $duration -gt $dur_min ]] && [[ $duration -lt $dur_max ]] ; then
            echo "$file is $duration seconds long (rounded down)"
            # do whatever you want, mv, ln, etc.

Note I used iname rather than name to make it case insensitive (*.MP4, etc.)

Also, I'm using ffprobe not avprobe (which I don't have), but you have ffmpeg tagged, so I guess that's OK?

  • Thanks, works like a charm :-)
    – Malcolm
    Mar 25, 2022 at 22:52
  • I tried to get "avprobe" to work, when I heard it was supposed to be faster than "ffmpeg", and I have a 30K files to go through. That's also why I tried to separate the short video files already in the "find" process. But it works, and speed is not really a big issue.
    – Malcolm
    Mar 25, 2022 at 23:01

You must log in to answer this question.

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