Exclude a directory when searching on Linux

find, searches

I have already commented on how to locate files on your Linux distro in an easy and fast way at other times. But the searches They are an important topic, something that is usually done almost daily and that sometimes requires greater precision to quickly find what you want.

On occasions, when running accommand for searchWhat happens is that it will try to locate what you are trying to do while the program executed sweeps all the directories and files in the area where you are doing the searches. The problem comes when it comes to a large partition or directory, which delays the result quite a bit ...

To avoid that, you can do a few things, like exclude some directory of searches so that it does not interfere with time. And for that, we are also going to use the find command, as in the other tutorial that I left a long time ago in LxA and that I cited in the link in the first paragraph.

Well, to exclude a directory from searches and save time, what you can do is use the -prune option by find. For example, imagine you want to locate a file called lxa with any extension in the current directory, but you want to search everywhere except the named directory experiment, since you know that it will not be there. So, you should run the following:

find . -path './prueba' -prune -o -name 'lxa.*'

That is, in this case you are asking find to locate in the current directory (.), The files called lxa with any extension but, in this case, the directory is excluded ./proof.

As you see, find is quite a powerful command to locate, but it presents some difficulty given the large number of options and parameters that it can accept to filter searches ...


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

Be the first to comment

Leave a Comment

Your email address will not be published.

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  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.