在Windows下有一个智能软件“Everything”,它监听NTFS的变化,使其能够立即按名称搜索文件 - 仅需一秒钟或更短的时间。
Ubuntu是否有类似的功能?
Ubuntu是否有类似的功能?
locate
可以在命令行中使用。
locate会读取由updatedb(8)准备的一个或多个数据库,并将与至少一个PATTERN匹配的文件名写入标准输出,每行一个。
updatedb用于创建或更新locate(1)使用的数据库。如果数据库已经存在,则会重用其数据以避免重新读取未更改的目录。通常情况下,updatedb会被cron(8)每天运行一次,以更新默认数据库。
示例...
locate *.txt
结果为
/boot/grub/gfxblacklist.txt
/discworld/.Trash-1000/files/Breaking Bad S04E10 Nl subs DutchReleaseTeam/DutchReleaseTeam NFO.txt
/discworld/.Trash-1000/files/Breaking Bad S04E10 Nl subs DutchReleaseTeam/Torrent downloaded from Demonoid.me.txt
/discworld/.Trash-1000/files/True Blood S04E12 HDTV.XviD (NL subs) DutchReleaseTeam/Dutch Release Team NFO Read Before Playing.txt
/discworld/.Trash-1000/files/True Blood S04E12 HDTV.XviD (NL subs) DutchReleaseTeam/Torrent_downloaded_from_Demonoid.me.txt
/etc/X11/rgb.txt
locate
能够索引任何文件系统上的文件,并且速度非常快。如果您想查找个人文档或启动程序,那么像gnome-do
或kupfer
这样的启动器软件更适合这个任务。 #!/bin/bash
t=$(mktemp)
locate "$1" | awk '{ printf "%4d\t\"%s\"\n", NR, $0 }' > $t
[[ -s $t ]] || { echo "No results found"; exit; }
rows=$(wc -l "$t" | cut -d' ' -f1)
if [[ $rows == 1 ]]; then
file=$(sed 's/^.*\t"\(.*\)"$/\1/' $t)
xdg-open "$file" &
else
response=$(dialog --stdout --menu 'Choose a File:' 20 70 15 --file $t)
if [[ -n "$response" ]]; then
file=$(sed -n "/^\s*$response\t/{s/^.*\t\"\(.*\)\"$/\1/;p}" $t)
if [[ -n $file ]]; then
echo "You chose $file"
xdg-open "$file" &
fi
fi
fi