Search with find and exclude files (by their extension) from the results

As many of you know I use KDE, however, although I love the convenience and comfort that KDE offers me (because it is extremely complete), I do not remotely use all the options it brings, even some basic ones.

When any of you want to search in X folder for all the .jpg files or simply those that contain "wedding" in their name, use the system search engine, because I don't 🙂

It is not that I am more geek, nerdy or freaky than others, I simply use find (in obvious terminal) because I find it incredibly more productive, it is simpler for me to search with find in a terminal that has open (using Yakuake) you have to open the system browser.

Well, not long ago I wanted to find all the files whose name contains «collection«But I did NOT want to see the .gif files, how to achieve something like that? … How to tell find not to show me the .gif even if its name contains "Collection"?

The first thing that occurred to me is something as simple as:

find $HOME -iname *collection* | grep -v .gif

 This would find with find all files that have "collection" in their name, but using grep I made sure that the terminal only shows me what is DIFFERENT from «.gif» and ... yes, it works wonders 😀

But you don't really need to use two commands (find + grep) to achieve this, with find is enough for us:

find $HOME -iname *collection* -not \( -iname "*\.gif" \)

And that's it ... but the post doesn't end here 🙂

What if we want to delete those files that were shown?

For this we only have to add the parameter -delete on the line, that is:

find $HOME -iname *collection* -not \( -iname "*\.gif" \) -delete

What if we just want to change the permissions to 755?

For this we will use the -Exec from find:

find $HOME -iname *collection* -not \( -iname "*\.gif" \) -exec chmod 755 {} \;

And voila 🙂
Nothing, which I hope you find of interest ...


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   FIXOCONN said

    I don't see the desktop environment

    1.    KZKG ^ Gaara said

      There is no support for Cinnamon yet, basically because I don't have the Cinnamon icon… just for that 🙂
      Here you can read a little more about it: https://blog.desdelinux.net/desdelinux-tambien-te-muestra-el-entorno-de-escritorio-que-usas-en-tus-comentarios/

  2.   FIXOCONN said

    is there any icon for cinammon

  3.   KZKG ^ Gaara said

    Testing new Desktop Environment recognition functionality.
    Test No.1

    1.    KZKG ^ Gaara said

      DPM works… great 🙂

      1.    elav said

        And what is it supposed to put in the User Agent?

        1.    KZKG ^ Gaara said

          Now I make an article explaining this 🙂
          However ... if you put "KDE" in the UserAgent you will get the KDE logo, if you put "Xfce" well the obvious, etc.

          Now, if someone comments from Chakra, Kubuntu, or using Konqueror or Rekonq ... the blog will automatically put the KDE icon.

          As if they comment on Xubuntu, it will put the one on Xfce.

          1.    elav said

            😛Nice

          2.    dhunter said

            Wasn't there a cooler icon for kde?

  4.   dhunter said

    Testing user agent ...

    1.    KZKG ^ Gaara said

      The truth is that the KDE one is not exactly the best ... but, at that time, there was no better one at hand.

      By the way ... you do not need to configure your UserAgent, as you mentioned from Kubuntu I programmed this function so that if it is Kubuntu it automatically puts the KDE icon 🙂

    2.    truko22 said

      ^ ___ ^ testing

  5.   rots87 said

    What kind of witchcraft is this!!!!! hahaha lies waiting for the user agent article ... by the way I don't know if it's me or this article I feel like it was already seen or they are my illusions

  6.   Rayonant said

    Well, interesting, although I'm still not used to using find and regular expressions, mine is limited to using locate xD.

    1.    KZKG ^ Gaara said

      The negative aspect of locate is that it does not work in real time, that is, if I have just copied something to the computer, locate still does not index those new files, also ... find allows more things like using the -exec 🙂

      1.    davidlg said

        With the command -exec that I was going to comment, it is very useful to reorganize music / series for example.
        I use it to move the torrent series, since it creates several folders and within the downloaded files

      2.    anonymous said

        Nothing that a simple # updatedb can not solve ... it is still easier and faster to use l # updatedb && locate

        regards

        1.    KZKG ^ Gaara said

          In other words, would I have to run updatedb to update the indexes, wait for it to finish and then do the search? ...
          I'm not saying it's the wrong way by any means, but before going down that path I personally prefer to just use find and voila.

  7.   Daniel G. said

    testing the new toy 🙂

  8.   giskard said

    Testing…

    1.    giskard said

      Hi, until I change the UserAgent or pending. But once I changed it and the Chomium went crazy. In any case, I use LinuxMint with XFCE.

      1.    KZKG ^ Gaara said

        There is nothing wrong with changing the UserAgent ... I change it to my Firefox all the time 😀

  9.   Lolo said

    It is good to know the parameters of find but with grep you have to write less, right?

    1.    KZKG ^ Gaara said

      Yes indeed 🙂
      Actually the important thing is to have multiple ways to achieve the desired result, knowledge does not take up space 😀

  10.   I Mendieta said

    Find is our friend 🙂

    1.    KZKG ^ Gaara said

      +1

  11.   Carlos said

    try to see what comes out

  12.   cost said

    I'll take a look at it, thanks.