0

I’m looking for the easiest way to get the list of media files ( by extensions like mp4,avi,mkv,...) recursively from a folder filtered to get only the ones with one hardlink.

My ls -lR output currently is composed by * Permissions * Nb of Hardlink * Owner * Group * Size * Date * Name

Like https://unix.stackexchange.com/questions/103114/what-do-the-fields-in-ls-al-output-mean#103118

I’m currently using a mix of ls and grep but it’s not working fine as it provides the full info and not just the filename.

Thanks for your help!

TheLazyFox
  • 113
  • 4

1 Answers1

1

Parsing ls is not recommended. In many similar cases find is the right tool. find in Debian should support -links test. man 1 find reads:

-links n
File has n links.

This test is perfect for you. The solution:

find . -type f \( -name "*.mp4" -o -name "*.avi" -o -name "*.mkv" \) -links 1

Add whatever extensions you want. Consider -iname instead of -name to perform case insensitive matching. Or if you want to test by content, not extension, then use this approach (although it will be much slower):

find . -type f -links 1 -exec sh -c 'file --mime-type "$1" | grep -q "video/"' sh {} \; -print