3

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.

pomsky
  • 68,507
jdc
  • 141
  • Could you please expand your question and explain what's going wrong? Which steps did you perform, what was the outcome, and what was the expected result? – pomsky Dec 23 '18 at 19:19
  • I don't know quite how to expand it. I type a phrase which is part of the name of a file I know is within the file system via one of the two search methods, and nothing is returned. The expected result is something I can click to go to my file or the containing folder. The actual result is nothing.

    The other answers seem to involve installing different utilities on the system. It is possible I have searched poorly. I have ignored this problem for a few days and do not remember what I did then, but I would like to be able to use the native system utilities, assuming they can be made useful.

    – jdc Dec 23 '18 at 19:34
  • 2
    Ubuntu 17.10 abandoned Unity in favour of GNOME 3, so the file browser in Bionic Beaver (Ubuntu 18.04) is indeed Nautilus. – Tsundoku Dec 23 '18 at 19:34
  • 2
    @Chris To be clear, it's been Nautilus for a long time. – wjandrea Dec 23 '18 at 21:13
  • Not sure I understood your issue completely, but it sounds to me like you're missing tracker pacakge's functionality. It is not shipped with Bionic by default (see known issues) as it may cause performance issues, especially in systems with low specs. – pomsky Dec 24 '18 at 07:30
  • @pomsky, thanks! It says it's already the newest version when I try to install it, though. – jdc Dec 24 '18 at 07:50

2 Answers2

3

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.024s

I 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.020s

Notice 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:

glocate 1.png

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:

glocate 2.png

Bash Script

Here is the bash script you can create using:

sudo -H gedit /usr/local/bin/glocate

Then 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: https://askubuntu.com/questions/1104069/search-is-useless-how-can-i-force-it-to-index-my-hard-drive-2018/1104112#1104112

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

}

Main

Save the file and exit gedit.

Mark the script as executable using:

sudo chmod a+x /usr/local/bin/glocate

If 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.

  • 2
    +1; I think it is a good idea to add a GUI to locate (unless you think that recoll is good enough for GUI users). – sudodus Dec 24 '18 at 06:01
  • Is Dropbox included in the sudo updatedb? I do this and it is done almost instantly, but I can search for strings included in filenames in Dropbox and get no result. – jdc Dec 24 '18 at 06:25
  • @jdc Sorry I don't know the inner workings of Dropbox. – WinEunuuchs2Unix Dec 24 '18 at 13:06
  • @sudodus I shall begin developing a zenity based script called glocate. I'll ping you when done for your valuable critiquing :). – WinEunuuchs2Unix Dec 24 '18 at 13:10
  • @WinEunuuchs2Unix, Good luck :-) – sudodus Dec 24 '18 at 13:52
  • @sudodus It's done. I wish I would have done it in yad instead of zenity, but zenity is the default installation. – WinEunuuchs2Unix Dec 24 '18 at 21:36
  • glocate works well for me :-) If I understand correctly, you cannot update the database from glocate. 1. Maybe that would be a good alternative (in a sub-menu with a warning, that it is probably updated automatically once a day or at boot, and that it can take some time); 2. Please add that it is possible to enter locate options in search boxes, for example -b in box 1 and \autostart in box 2 in order to find only files with the name autostart and not drown in all files and paths that match *autostart*. Maybe you can invite to this with a box for options. – sudodus Dec 25 '18 at 05:48
  • @jdc, How do you mount Dropbox? Check that it is not pruned in /etc/updatedb.conf (there is a new paragraph about updatedb in my answer). Dropbox may also use a file system, that does not work with locate and its database. – sudodus Dec 25 '18 at 06:47
2

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 recoll or a tutorial via the internet to learn more about it.

    • Typically the recoll command 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.

    • Link: Recoll is a desktop full-text search tool

  • glocate is a brand new GUI for locate made 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.

  • find is a very powerful tool to find files. Examples:

    find / -iname "*autostart*"  # to search everywhere
    
    find ~ -iname "*autostart*"  # to search in your home directory
    

    Use elevated permissions, sudo find ... if there are directories, that you are not allowed to search as a regular user. See man find or a tutorial via the internet to learn more about it.

  • grep is a very powerful tool to find text strings in files (search for file content). Examples

    grep 'alias' ~/.bashrc
    

    See man grep or a tutorial via the internet to learn more about it.

  • locate is a fast tool to find files when it has an updated database. See man locate or a tutorial via the internet to learn more about it.

    • Update the data-base for locate with

      sudo updatedb
      

      and 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
      
sudodus
  • 46,324
  • 5
  • 88
  • 152
  • Thank you! I've been using find. I seem to remember not needing to use the option iname in the past, bu tseem to need to now; has this changed? Perhaps I should just install Recoll, but do you know if there is any way to force the GUI tools that come with the system, available at the touch of a button, to index my directories so that I can use them? – jdc Dec 24 '18 at 06:20
  • 1
  • You can still use -name, it makes a difference between upper case and lower case. -iname will search for both, for example "find -iname "*.jpg" will find jpg files and JPG files; 2. I suggest that you install recoll. I don't know if there is a 'default' indexing like in Windows, unless we can consider that locate and its database have that role.
  • – sudodus Dec 24 '18 at 06:36
  • OK, I've installed recoll; is there any way to integrate it with the system so I can find files by hitting META and typing like I'm used to? – jdc Dec 24 '18 at 07:51
  • @jdc, Probably, you can do almost everything with linux, but I don't know how to integrate it completely. You could make a desktop icon or try to get it into the dock at the left side. Other people are better at manipulating the desktop environment. You have a better chance to get help, if you create a separate question for that problem: "How to integrate recoll into the desktop environment to get a quick access to it". – sudodus Dec 24 '18 at 11:53