Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

How to use find with boolean operators AND, OR, NOT

Date: 2011-02-14 00:00:00 -0400

Introduction

In these days when disk are everyday bigger and bigger as well as cheaper, you will find yourself storing everything, we almost never delete a file anymore, we just store it. But, I do not know about yourself, but sometimes it happens to me, that I can’t just remember where a given file, picture, or song was archived.

So, I know I have it, somewhere in my disk, but not know where. You you might think I am not too organized, and you will be right with that statement, :).

What I do, is to use find to locate those missed files, find is extremely powerful, and I’ve written about it in the past, for example:

Today, I just want to give you a small tip about it, and it is how to combine searches using boolean operators like:

  • AND
  • OR
  • NOT

Find and boolean operators

Let’s do this by examples, and to start let’s suppose I want to find the files with .png and .jpg extensions.

find /path/ -name '*.png' -or -name '*.jpg'

This way, files with .jpg or .png in other words image files.

Now, let’s imagine we need to find movies that are bigger than a certain size.

find /path/ -name '*.mpeg' -and -size +300000k

So, we will find only files ending in .mpeg and bigger than 300 Mega bytes of size.

I’m sure you will find other applications.

If you liked this article please share it.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.