How to search for video files on Ubuntu

file search

I had downloaded a video a few months back. I'm not very well remembering the name by which it is saved. Is there any command or any method that will output only video files so that I can search for my video there? From man pages, I couldn't find any option of find doing that work.

The video file I downloaded may have any extension (like webm etc) and also it may be possible that I had that time changed the name to anything like 'abcde' which I don't remember now. So the search can't be based on file name!

(Just mentioning one similarity: In perl there are commands to check whether a file is text file or binary , etc. Similarly there may be a way to check if its video file or multimedia file)

Best Answer

The basic idea is to use the file utility to determine the type of each file, and filter on video files.

find /some/directory -type f -exec file -N -i -- {} + |
sed -n 's!: video/[^:]*$!!p'

This prints the names of all files in /some/directory and its subdirectories recursively whose MIME type is a video type.

The file command needs to open every file, which can be slow. To speed things up:

  • Restrict the command to the directory trees where it's likely to be, such as /tmp, /var/tmp and your home directory.
  • Restrict the search to files whose size is in the right ballpark, say at least 10MB.
  • Restrict the search to files whose modification time is in the right ballpark. Note that downloading the file may have set its modification time to the time of download or preserved the time, depending on what program you used to download (and with what settings). You may also filter on the inode change time (ctime), which is the time the file was last modified or moved around (created, renamed, etc.) in any way.

Here's an example which constrains the modification time to be at least 60 days ago and the ctime to be no more than 100 days ago.

find /tmp /var/tmp ~ -type f -size +10M \
     -mtime +60 -ctime -100 \
     -exec file -N -i -- {} + |
sed -n 's!: video/[^:]*$!!p'
Related Question