I am searching for a lightweight solution for helping users finding files on my server.
Running on commandline I can just use locate, if necessary piped with a grep command. However the users do not have access to the prompt and do not have the knowledge to use more complicated piped commands.
I have been experimenting with some search engines like solr and opensearch, however these are quite demanding on recourses for full hd's with lots of data, while most of the times a simple name search will suffice.
Does anyone know a web gui which can just make use of the existing locatedb?
Or an other approach, like a lightweight searchengine, with low setup effort and limited resource demands which uses a central search db and provide a gui to different platforms?
4 Answers
Update, January 22,2018:
I have stumbled upon mlocate-web on GitHub, which fits OP's requirements quite well, although lacks ability to open files. Can be ran manually or as daemon. According to the README.md, the package was developed on Ubuntu 16.04, so it's quite recent as of right now.
Mini-update, Feb 2
Added double quotes to gnome-open "$TOPEN", so that gnome-open gets full pathname of files that have space.
Update # 2,Jan 30 :
As requested in the comments , I've refined the script, and added the option to open files. Everything is implemented with zenity, locate, and gnome-open. Praise the Unix philosophy of piping commands into others !
I've annotated the script , so it should be clear where, what, and how. In the screenshots I'm opening the Hello World program for java. The script exits at any point if user clicks Cancel/Quit buttons.
Side note: The OP requested that the app should be cross-platform. As far as I know, zenity,gnome-open, and locate are not dependent on presence of GNOME shell. Besides, users will be connecting to his Ubuntu server, and all those apps work on Ubuntu regardless of GNOME shell's presence. In other words, they're going to be executing the script on his system, not theirs, to locate the files.
The refined script:
#!/bin/bash
# Author: Serg
# Description: GUI using zenity for locate utility
# Date: January 30, 2015
# This flag will make popup appear if nothing was found
FOUND=0
# Ask user for input, and store it in USRFILE variable
USRFILE=`zenity --entry --title="SEARCH" --entry-text="Text here" --text="Enter a filename or part of it"`
# if use clicked OK, proceed to this big if statement
if [ $(echo $?) = 0 ] then TOPEN=$( ( locate $USRFILE ) | ( zenity --height 450 --width=450\ --list --column "Please wait, I'll display paths to files, if I find any"\ --title "SEARCH RESULTS" --text "Select a file you want to open"\ --height=450 --width=450 --ok-label="Open a file " --cancel-label="Quit" ) ) # FIXME: if user clicks open a file without selecting one, program will crash # FIXME: selecting a file and hitting enter, brings up "Nothing found" dialog # If user clicked "Open a file" , gnome-open # will open it with whatever default # program is listed for that file-type if [ $(echo $?) = 0 ] then gnome-open "$TOPEN" fi # Set flag to true, do not display "Nothing found" if [ $(echo $?) = 0 ] then FOUND=1 fi # If we didn't find anything, display a message if [ $FOUND != 1 ] then zenity --info --text="Nothing found" fi
fiScreenshots of the refinements
Get user inputDisplay search results if any, might take a moment to load
Open the selected file
For a suggestion on how to make this script open with a short-cut (double-click), refer to my previous update below
Update #1,Jan 29 : Disregard my previous post. I've though about the way you worded the problem : "a gui front end to locate". In fact there exists a gui front end to scripts , zenity, and I've used it to make a rough draft of a script that might be useful. Feel free to alter it and add functionality, but at the most basic level it's locate with gui.
As for making a script "double-clickable" refer here
The script
#!/bin/bash
FOUND=0
USRFILE=`zenity --entry --entry-text="Text here" --text="Enter a filename or part of it"`
zenity --info --text " Please wait a little, I'll try to find it "
locate $USRFILE > results.txt && zenity --text-info --html --filename='results.txt'
if [ -e results.txt ] then FOUND=1 rm results.txt
fi
if [ $FOUND != 1 ] then zenity --info --text="Nothing found"
fiScreenshots
Old post
There is gnome-search-tool, which I've checked with ps and htop utilities and it doesn't take too many resources. You can install it with sudo apt-get install gnome-search-tool.
I have made my research about this , found out this versatile file searching tool called Catfish. Sounds promising, completely written in python and helpful to find and locate files. I also found a GUI
1I know this is pretty old but I just found myself asking the same question for some cold storage on a Raspberry Pi. I came up with a super simple solution with CGI but beware - security isn't its strength. Only use this for a personal system or private network because it's ripe for injection attacks. The good news is it's fast and easy to deploy if you already have Apache/NGinx installed.
search.html:
<HTML>
<TITLE>MLocate Web Form</TITLE>
<BODY>
<b>Simple Web Form</b><p>
<FORM ACTION="/cgi-bin/search.cgi" target="resultsframe">
<label for="search">Find</label>
<INPUT TYPE="TEXT" NAME="search" SIZE="50"><BR>
<label for="limit">Limit</label>
<INPUT TYPE="TEXT" NAME="limit" value="10" SIZE="4"><BR>
<INPUT TYPE="SUBMIT" NAME="Find" VALUE="Find">
</FORM>
<iframe name="resultsframe" height=600 width=800></iframe>
</BODY>
</HTML>Now you can just use CGI to dump the results from a bash script (/var/www/cgi-bin/search.cgi):
#!/bin/bash
echo -e 'Content-type: text/html\n\n'
echo '<html><body><table>'
eval $(echo $QUERY_STRING | sed 's/\&/\n/g')
while read -r l
do l=${l:8} echo "<tr><td><a href='[YOUR_HTTP_BASE]$l'>$l</td></tr>"
done <<< $(locate -l "$limit" -i "$search")
echo "</table></html>"Results are posted as links so filter and map your results to apache-permitted paths you want. If you have unicode or html-iffy characters, best to escape them. Also note that you can potentially inject nastiness into your search here so use at your own risk or sterilize the input.
I using zenity. Configured the search for text in the folder via Thunar
If someone will help this will only be happy
#!/bin/bash
# Author: Karavaev Viktor E. (Russia)
# Description: GUI using zenity for locate search file Thunar
# Using Thunar: ~/.config/Thunar/find_file_thunar.sh %f
# Using: ~/.config/Thunar/find_file_thunar.sh /home/user/dir/
# Date: June 05, 2020
# print debug strings
debug=0
# Find is dir
FINDSTR=$1
if [ $debug = 1 ]
then echo $FINDSTR
fi
# open window without exit
zenity_list()
{ TOPEN=$( zenity --height=400 --width=450 \ --list --column "Files" \ --title "Result" --text "Select the file you want to open" \ --ok-label="Open" --cancel-label="Close" --separator=";" $list ) if [ $(echo $?) = 0 ] then if [ "$debug" = 1 ] then echo "TOPEN: $TOPEN \n" fi # Open select file this program ( i like geany ;) ) geany "$TOPEN" zenity_list fi
}
# Find is dir exist
if [ -n "$FINDSTR" ]
then # This flag will make popup appear if nothing was found FOUND=0 cd $FINDSTR # Ask user for input, and store it in USRFILE variable USRFILE=`zenity --entry --title="Search" --entry-text="" --text="search text"` if [ "$debug" = 1 ] then # dir search command grep -rnwil "$USRFILE" fi # if use clicked OK, proceed to this big if statement if [ $(echo $?) = 0 ] then list=$( grep -rnwil "$USRFILE" ) if [ "$debug" = 1 ] then echo "list finds: $list \n" fi zenity_list # Set flag to true, do not display "Nothing found" if [ $(echo $?) = 0 ] then FOUND=1 fi fi # If we didn't find anything, display a message if [ "${#list[@]}" = 0 ] then if [ "$debug" = 1 ] then echo "Not found \n" fi zenity --height=100 --width=200 --info --text="Not found " fi
if [ "$debug" = 1 ]
then echo "flag FOUND result: $FOUND \n"
fi
else if [ "$debug" = 1 ] then echo "Parameters were not found. \n" fi zenity --height=100 --width=200 --info--text="Parameters were not found."
fi