How can I find all video files on my system?
Solution 1:
Alternative: search on file:
sudo find . -type f -exec file -N -i -- {} + | grep video
or if you only want the filenames ...
sudo find . -type f -exec file -N -i -- {} + | sed -n 's!: video/[^:]*$!!p'
-N, --no-pad
: Don't pad filenames
-i, --mime
: Causes the file command to output mime type strings rather than the more traditional human readable ones. Thus it may say 'text/plain; charset=us-ascii' rather than 'ASCII text'. In order for this option to work, file changes the way it handles files recognized by the command itself (such as many of the text file types, directories etc), and makes use of an alternative 'magic' file. (See the FILES section, below).
The FILES section points to:
Files
/usr/share/misc/magic.mgc
Default compiled list of magic.
/usr/share/misc/magic
Directory containing default magic files.
file
is slowwwwwwwwwwwwwwwww though (it will open all the files find finds) but has the advantage you do not need to add all those extentions.
Using locate:
locate *.mkv *.webm *.flv *.vob *.ogg *.ogv *.drc *gifv *.mng *.avi$ *.mov *.qt *.wmv *.yuv *.rm *.rmvb *.asf *.amv *.mp4$ *.m4v *.mp *.m?v *.svi *.3gp *.flv *.f4v
Solution 2:
I imagine this could be done as a 1-liner but it seemed a bit cumbersome so I created a script for ease of launching and editing and called it findvids.sh
This is what worked for me.
Note: I may not have covered ALL the video file types, but I'm sure I have most of them. One notable exception is .mkv as that is the target format for the project and I don''t need to find the files that have already been processed. It should be very simple to add additional formats (extensions) to the script to suit your needs by examining the pattern and adjusting accordingly while maintaining the quotes at the beginning and end of the expression. Note that files you don't have permission to read will not be found.
#!/bin/bash
#This script is intended to find virtually all video file formats.
find /. -type f | grep -E "\.webm$|\.flv$|\.vob$|\.ogg$|\.ogv$|\.drc$|\.gifv$|\.mng$|\.avi$|\.mov$|\.qt$|\.wmv$|\.yuv$|\.rm$|\.rmvb$|/.asf$|\.amv$|\.mp4$|\.m4v$|\.mp*$|\.m?v$|\.svi$|\.3gp$|\.flv$|\.f4v$"
Edit based on comment: The $
at the end of the extension signifies that the search term must be found at end of line. if we wanted to match the beginning of the line instead we'd use ^
before the term we intend to match. You can find these anchors explained in more detail here.
I did a speed comparison to using locate and the results were:
time locate *.mkv *.webm *.flv *.vob *.ogg *.ogv *.drc *gifv *.mng *.avi *.mov *.qt *.wmv *.yuv *.rm *.rmvb *.asf *.amv *.mp4$ *.m4v *.mp *.m?v *.svi *.3gp *.flv *.f4v
real 0m8.887s
user 0m5.814s
sys 0m0.052s
vs.
time find /. -type f | grep -E "\.webm$|\.flv$|\.vob$|\.ogg$|\.ogv$|\.drc$|\.gifv$|\.mng$|\.avi$|\.mov$|\.qt$|\.wmv$|\.yuv$|\.rm$|\.rmvb$|/.asf$|\.amv$|\.mp4$|\.m4v$|\.mp4$|\.m?v$|\.svi$|\.3gp$|\.flv$|\.f4v$"
real 0m2.795s
user 0m0.657s
sys 0m1.115s
Unexpectedly find is faster. I'll be using this approach.
Edit: further testing indicates that locate was faster on a different machine. I think my initial speed test results were bunk due to caching.
Sources:
man find
man grep
https://stackoverflow.com/questions/7190565/unix-find-multiple-file-types
Solution 3:
In the find
command in Elder Geek's answer, case sensitivity caught me out. My devices seem to have used capitals quite often when taking videos etc. Just need to add -i
option to grep to fix this:
find /. -type f | grep -iE "\.webm$|\.flv$|\.vob$|\.ogg$|\.ogv$|\.drc$|\.gifv$|\.mng$|\.avi$|\.mov$|\.qt$|\.wmv$|\.yuv$|\.rm$|\.rmvb$|/.asf$|\.amv$|\.mp4$|\.m4v$|\.mp*$|\.m?v$|\.svi$|\.3gp$|\.flv$|\.f4v$"