3

Is there a way to find things faster than find . I am/was doing :-

$sudo find / -perm +4000

But it takes ages to find the required info. and I know that most of the files which would that specific permission bit set would be static/not dynamic.

I tried

[$] sudo locate --all / -perm +4000                                                                                               
locate: invalid option -- 'p'

but as can be seen failed. Any ideas how could I use locate to do the same thing.

Just to share /usr/bin/locate is sym-linked to /etc/alternatives/locate which in-turn is sym-linked to /usr/bin/mlocate

  • 1
    You need to wait for some time to produce the desired output. If you only have to find files with specific pattern then locate is good. – SHW Nov 5 '15 at 7:31
  • 1
    If you only want to search the root filesystem rather than every possible filesystem mounted (nfs, /proc etc etc) add -xdev. e.g. find / -xdev -perm +4000 – steve Nov 5 '15 at 7:37
1

Unfortunately, mlocate does not index file permissions, so you'll have to resort to scanning your filesystems with find, unless you find a locate implementation that features this functionality (or extend mlocate yourself).

1

As mentioned by @shirish, mlocate does not index file permissions. But stil I have some suggestions for you:

Firstly, from find manual, -perm +mode is deprecated, so you should use -perm /mode instead.

-perm +mode

Deprecated, old way of searching for files with any of the permission bits in mode set. You should use -perm /mode instead. Trying to use the '+' syntax with symbolic modes will yield surprising results. For example, '+u+x' is a valid symbolic mode (equivalent to +u,+x, i.e. 0111) and will therefore not be evaluated as -perm +mode but instead as the exact mode specifier -perm mode and so it matches files with exact permissions 0111 instead of files with any execute bit set. If you found this paragraph confusing, you're not alone - just use -perm /mode. This form of the -perm test is deprecated because the POSIX specification requires the interpretation of a leading '+' as being part of a symbolic mode, and so we switched to using '/' instead.

-perm /mode

Any of the permission bits mode are set for the file. Symbolic modes are accepted in this form. You must specify 'u', 'g' or 'o' if you use a symbolic mode. See the EXAMPLES section for some illustrative examples. If no permission bits in mode are set, this test matches any file (the idea here is to be consistent with the behaviour of -perm -000).

Secondly, you can try to speed up find: to do so, you need to be as specific, as it possible. For example:

find /some/path ...

will reduce search time, because you specified path where to search (/some/path), instead of searching whole root directory (/)

And lastly, you can exclude system folders, which you don't want to scan during search. For example:

 find /some/path -not \( -path /excluded/path -prune \) -name *.js
  • from which manual did you get the above ? I tried both the manuals of locate and mlocate but didn't find it there. Am using mlocate as seen from [$] sudo update-alternatives --get-selections | grep locate [3:08:05] locate manual /usr/bin/mlocate – shirish Nov 9 '15 at 21:38
  • OR [$] sudo update-alternatives --config locate There are 2 choices for the alternative locate (providing /usr/bin/locate). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/bin/mlocate 80 auto mode 1 /usr/bin/locate.findutils 20 manual mode * 2 /usr/bin/mlocate 80 manual mode Press <enter> to keep the current choice[*], or type selection number: – shirish Nov 9 '15 at 21:43
  • @shirish as I sad, it is "from find manual", like man find, it is not about any locate – Maxim Mazurok Nov 10 '15 at 11:28
  • I tried again but came up cropper, using the same generic method from before. [$] sudo find / -not \(-prune \) -perm/mode 4000 [sudo] password for shirish: find: paths must precede expression: (-prune Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression] confused :( – shirish Nov 16 '15 at 19:44
  • @shirish well, first: you should specify excluded path, rather than just write prune: find / -not \( -path /path/to/excluded/folder -prune \). Secondly, you are using wrong synax for -perm, so your full command should look like this: find / -not \( -path /path/to/excluded/folder -prune \) -perm /4000 – Maxim Mazurok Nov 17 '15 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.