Search is useless. How can I force it to index my hard drive (2018)
I am running Bionic Beaver and am unable to find any of my files in the standard (is it still called Unity?) GUI. If I go to a folder, it seems to be able to find those files afterward, but this is useless for files I don't already know the location of. These are actually separate problems for searching from the dock using META and searching using Ctrl+F from the file browser (is this still called Nautilus?)
I believe there are earlier versions of this question but I haven't found anything that seems to apply to my set-up yet.
62 Answers
Files are indexed for the locate command but normally it is updated every day so any new file you created today won't show up until tomorrow. I've circumvented this shortfall by putting sudo updatedb as a cron job that runs every 15 minutes (it only takes a few seconds to run).
The locate command behaves as if wildcards are used:
$ time locate etc/profile
/etc/profile
/etc/profile.d
/etc/profile.d/appmenu-qt5.sh
/etc/profile.d/apps-bin-path.sh
/etc/profile.d/bash_completion.sh
/etc/profile.d/cedilla-portuguese.sh
/etc/profile.d/jdk.csh
/etc/profile.d/jdk.sh
/etc/profile.d/vte-2.91.sh
real 0m0.696s
user 0m0.671s
sys 0m0.024sI prefixed the locate command with the time command so you can see how blindingly fast it is doing lookups on indexed filenames and directory names with implied wildcards.
The locate output is rather sparse so I created an alias llocate to format the output nicely (How to make locate output look like `ll` or `ls -la` but nicer?):
$ time llocate etc/profile
ACCESS OWNER GROUP SIZE MODIFIED NAME (updatdb last ran: 2018-07-01 11:30:05)
-rw-r--r-- root root 575 Nov 12 2017 /etc/profile
drwxr-xr-x root root 4096 Jun 4 17:19 /etc/profile.d
-rw-r--r-- root root 40 Feb 16 2017 /etc/profile.d/appmenu-qt5.sh
-rw-r--r-- root root 580 Oct 18 2017 /etc/profile.d/apps-bin-path.sh
-rw-r--r-- root root 663 May 18 2016 /etc/profile.d/bash_completion.sh
-rw-r--r-- root root 1003 Dec 29 2015 /etc/profile.d/cedilla-portuguese.sh
-rwxr-xr-x root root 301 Feb 20 2013 /etc/profile.d/jdk.csh
-rwxr-xr-x root root 299 Feb 20 2013 /etc/profile.d/jdk.sh
-rw-r--r-- root root 1941 Mar 16 2016 /etc/profile.d/vte-2.91.sh
real 0m0.760s
user 0m0.754s
sys 0m0.020sNotice how the heading tells you the last time files were indexed. If you can't find the file you are looking for and, was created before that time, simply run sudo updatedb.
The time command is used again so you can see that using llocate is marginally slower than locate unless a huge number of results are returned.
locate GUI front-end glocate
Although locate is a CLI command I've created a GUI front for it using zenity. This is an initial "no frills" front-end that could be improved using yad instead.
Enter up to 10 search file names / directory names
This screen appears when you start glocate:
You can enter directory names and filenames in whole or in part.
Results returned in scroll box
glocate takes about a second to display the results in most cases:
Bash Script
Here is the bash script you can create using:
sudo -H gedit /usr/local/bin/glocateThen copy and paste the following line:
#!/bin/bash
# NAME: glocate
# PATH: /usr/local/bin
# DESC: Provide zenity GUI front end to locate command
# DATE: Dec 24, 2018.
# NOTE: Written for:
Init () { # Get date `sudo updatedb` was last run LastRun=$(stat --printf=%y /var/lib/mlocate/mlocate.db | sed 's/\.[^\n]*//') SearchMax=10 # Search for up to 10 filenames or directories at once
}
GetSearchNames () { SearchNames=$(zenity \ --title "glocate - updatedb last run: $LastRun" \ --text '<span foreground="blue" font="14">Enter up to 10 search names</span>' \ --forms --width=800 --height=480 \ --add-entry="Search 1" --add-entry="Search 2" --add-entry="Search 3" \ --add-entry="Search 4" --add-entry="Search 5" --add-entry="Search 6" \ --add-entry="Search 7" --add-entry="Search 8" --add-entry="Search 9" \ --add-entry="Search 10" 2>/dev/null) Action="$?" # Glitch: When ESC pressed or Cancel clicked result is 0? # echo "Action: $Action" # Remove leading # to debug # Zenity not returning array like yad would. Build array manually SearchArr=() # Reset array for (( i=1; i<=$SearchMax; ++i)) ; do Field="$(echo "$SearchNames"| cut -d '|' -f $i)" [[ $Field != "" ]] && SearchArr+=("$Field") done # Click OK without search names? CharacterCount=$(wc -c <<< "${SearchNames[@]}") # echo "CharacterCount: $CharacterCount" # Remove leading # to debug # if [[ "$Action" == 0 && "$CharacterCount" == "$SearchMax" ]] ; then if [[ "$CharacterCount" -le "$SearchMax" ]] ; then zenity --error --title="glocate" \ --text="No search names entered. Program will end." \ 2>/dev/null Action=99 fi return "$Action" # 0 = Proceed with search, anything else = quit.
}
DisplaySearch () { Result=$(locate "${SearchArr[@]}" ) zenity \ --title "locate search results" \ --text '<span foreground="blue" font="14">Scroll to see more results</span>' \ --list --separator="$IFS" --width=800 --height=480 \ --hide-header --column "Directory and filenames" \ "${Result[@]}" 2>/dev/null
}
Main () { Init while GetSearchNames ; do DisplaySearch ; done
}
MainSave the file and exit gedit.
Mark the script as executable using:
sudo chmod a+x /usr/local/bin/glocateIf you want to create a desktop shortcut see: An easy way to create a desktop shortcut?
To call the script from the terminal simply use: glocate.
GUI tools
In a graphical desktop environment you can try Recoll, which is a powerful tool that can search for file names as well as file content.
When installed, see
man recollor a tutorial via the internet to learn more about it.Typically the
recollcommand will start the graphical user interface for querying the Recoll database.On the first run, recoll will create the user configuration which can be customized before starting the first indexation.
glocateis a brand new GUI forlocatemade by @WinEunuuchs2Unix and described in another answer here. It is very basic and also easy to use.
Command line tools
In a text screen or terminal window you can use command lines with find and grep.
findis a very powerful tool to find files. Examples:find / -iname "*autostart*" # to search everywhere find ~ -iname "*autostart*" # to search in your home directoryUse elevated permissions,
sudo find ...if there are directories, that you are not allowed to search as a regular user. Seeman findor a tutorial via the internet to learn more about it.grepis a very powerful tool to find text strings in files (search for file content). Examplesgrep 'alias' ~/.bashrcSee
man grepor a tutorial via the internet to learn more about it.locateis a fast tool to find files when it has an updated database. Seeman locateor a tutorial via the internet to learn more about it.Update the data-base for
locatewithsudo updatedband if it does not include a secondary file system, that is mounted in
/media, you can edit the configuration file to make it include it (or move the mountpoint to/mnt, but that may cause problems with hardcoded paths),cd /etc sudo cp -p updatedb.conf updatedb.conf.bak sudo nano updatedb.conf