How can I search for files that have a specific permission. For example, I have 10000 files and I want to find the ones that have the READ ONLY flag. In another case I want to search for another that has a particular owner. Or in another to see the files that are READ ONLY and EXECUTABLE.
Ubuntu – How to search for files with a specific permission
12.04search
Related Solutions
I found the unity-place-python sample code and used that to create a lens to search your filesystem. It's currently kinda unstable, but you can search for files and you usually get results.
Unity FileSearch Lens
You can access the lens in the Unity Launcher. You can see it here where I'm searching for "lecture".
The magnifying glass in the bottom left corner is the FileSearch Lens. (The icon changes based on your icon theme.) The lens shows files and folders in two separate sections.
You can add it to your main dash (Ubuntu button) by setting ShowGlobal=true
in /usr/share/unity/places/filesearch.place
. Unfortunately, Unity doesn't currently have a way to customize what lenses are in the Dash.
The files and folders sections are combined in the dash under the heading "File Search".
Config
When filesearch-lens first runs, it will create a config file ~/.filesearch.cfg
. You can customize the directories to search, how deep to search, and what folders to ignore.
For example, here's my config:
[search]
#dirs = a comma separated list of folders to search
dirs = ~/data
#depth = how deep from / to search
depth = 5
[ignore]
#pattern = python-style regex for directories to ignore
pattern = ^\.|^bin$|^lib$|^apps$|^settings$|^eclipse$
I want it to search ~/data and two directories below it and to ignore all dotfiles and some other specific folders. (Note: No, it's not smart enough to not search the same folders if you give it nested folders like ~/,~/code
, so don't do that.)
If you change the config file, you need to restart the daemon to reload it:
killall unity-filesearch-daemon
Install
I packaged it so you can download it from my ppa.
sudo add-apt-repository ppa:pydave/unity-lenses
sudo apt-get update
sudo apt-get install unity-place-filesearch
Then you need to reset unity before the lens will be noticed:
setsid unity
Experimental Features
If you give it a path, it usually shows the path as one of the results (so you can open folders like you could in gnome-do).
One of the features I'm still trying to get working properly is the ability to type a path, a space, and then a search word to search in the path. Most of the time it works, but sometimes it fails to find anything (probably because the search is taking forever).
When you use Nautilus
, just click search from the top level of your home folder (i.e. where you can see all your folders laid out) and in the search box only enter .pdf
(or whatever extension like .txt
that you want to find). That's what I do and it just returned me all the pdfs in my home folder. You don't need to use a wildcard or put quotes around the search term in Nautilus search, unlike when you use search programs on the command line.
The gnome-search-tool
can be used to search within files- select the home folder or the directory to be searched and then click select more options
, and input your search term where it says 'contains the text.
' It can be quite slow as it works without an index, but I have used it several times and it has been useful for basic searches.
Best Answer
It's probably easiest to use the
find
command, which allows you to recursively search through the directory tree. For example, if you particularly wanted to find files that were read-only, you could typeFor files belonging to a particular user you could use
For files executable (for all) you could use
For those that are executable and read-only for all you would use 555 in place of 777 in the example above. You can also search for files that belong to a group by substituting
-user mike
for-group mike
.To negate the search terms and so search for the exact opposite, you can use an exclamation mark like this:
Note: Specifying a dash before the permissions (e.g.
-perm -444
) means that all files that have a read only flag will be found and not just those that are 444; to search for 444 exactly and only that, simply remove the dash (e.g.-perm 444
).Note2: Combinations of permissions can be sought as well using
-a
for and and-o
for or; for example to find exactly these permissions, type:Directories can be searched for with
-type d
.See
man find
for the other available permutations.