我正在寻找一个轻量级的解决方案来帮助用户在我的服务器上查找文件。
在命令行上运行我可以只使用 locate,如有必要,使用 grep 命令进行管道传输。然而,用户无权访问提示,也不知道使用更复杂的管道命令。
我一直在尝试使用一些搜索引擎,如 solr 和 opensearch,但是这些对具有大量数据的全高清资源的要求很高,而大多数情况下,简单的名称搜索就足够了。
有谁知道可以使用现有的定位的 web gui 吗?
或者另一种方法,如轻量级搜索引擎,设置工作量低,资源需求有限,使用中央搜索数据库并为不同平台提供 gui?
2018 年 1 月 22 日更新:
我在 GitHub 上偶然发现了mlocate-web,它非常符合 OP 的要求,但缺乏打开文件的能力。可以手动运行或作为守护进程运行。根据 README.md,该软件包是在 Ubuntu 16.04 上开发的,所以它现在是最近的。
小更新,2 月 2 日
将双引号添加到gnome-open "$TOPEN",以便 gnome-open 获取有空间的文件的完整路径名。
更新 #2,1 月 30 日:
根据评论中的要求,我改进了脚本,并添加了打开文件的选项。一切都是通过 zenity、locate 和 gnome-open 实现的。赞美 Unix 哲学将命令传递给其他人!
我已经对脚本进行了注释,所以应该很清楚在哪里、什么以及如何。在屏幕截图中,我打开了 Java 的 Hello World 程序。如果用户单击取消/退出按钮,脚本将随时退出。
旁注:OP 要求应用程序应该是跨平台的。据我所知,zenity、gnome-open 和 locate 不依赖于 GNOME shell 的存在。此外,用户将连接到他的 Ubuntu 服务器,无论 GNOME shell 是否存在,所有这些应用程序都可以在 Ubuntu 上运行。换句话说,他们将在他的系统上执行脚本,而不是他们的系统,以定位文件。
#!/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
fi
Run Code Online (Sandbox Code Playgroud)
获取用户输入
显示搜索结果(如果有),加载可能需要一些时间
打开选定的文件

有关如何使用快捷方式(双击)打开此脚本的建议,请参阅下面我之前的更新
更新 #1,1 月 29 日:无视我之前的帖子。我已经考虑过您对问题的措辞方式:“要定位的 gui 前端”。事实上,脚本 , 存在一个 gui 前端zenity,我已经用它来制作一个可能有用的脚本的粗略草稿。随意改变它并添加功能,但在最基本的层面上它是用 gui 定位的。
至于使脚本“可双击”,请参阅此处
#!/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"
fi
Run Code Online (Sandbox Code Playgroud)

有gnome-search-tool,我已经检查过ps和htop实用程序,它不会占用太多资源。您可以使用sudo apt-get install gnome-search-tool.

| 归档时间: |
|
| 查看次数: |
1666 次 |
| 最近记录: |