Wednesday, April 27, 2011

Fun finding things

I found a neat way to use find today. If you want to do an inverse search (think grep -v, but in find), simply use '!'. For Example:


find . '!' -name '*.zip'


Find all files that don't end in .zip.

3 comments:

  1. Combining it with other parameters can make it even stronger:

    find . -type f -iname '*debian*' ! -iname '*.png'
    Finds all files with the text debian anywhere in the name and where the name does not end in .png.
    Also matches DeBiAn and .PNG which is sometimes nice.

    ReplyDelete
  2. I find -not easier to read and use. Like

    $ find . -type f -not -name "*.mp3"

    ReplyDelete
  3. It's funny you should mention that! I used find in a way I hadn't before today as well!

    find -executable -delete

    @anti-dotu: Apparently -not is non-POSIX-compliant, which '!' is.

    ReplyDelete