Como um iniciante no script Bash, eu estava procurando exatamente isso, e com base na resposta aceita acima, eu escrevi o seguinte script Nautilus, que eu chamei de " Search Text in Directory ... " . Como isso será útil para mim de tempos em tempos, eu pensei que também poderia ser útil para os outros.
#!/bin/bash
# Nautilus Script to search text in selected folder
# Determine the path
if [ -e -n $1 ]; then
obj="$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"
else
base="'echo $NAUTILUS_SCRIPT_CURRENT_URI | cut -d'/' -f3- | sed 's/%20/ /g''"
obj="$base/${1##*/}"
fi
# Determine the type and go
if [ -f "$obj" ]; then
/usr/bin/canberra-gtk-play --id="dialog-error" &
zenity --error --title="Search Directory" --text "Sorry, selected item is not a folder."
elif [ -d "$obj" ]; then
cd "$obj"
# Get text to search
SearchText=$(zenity --entry --title="Search Directory" --text="For Text:" --width=250)
if [ -z "$SearchText" ]; then
notify-send "Search Directory" "Nothing entered; exiting..." -i gtk-dialog-info -t 500 -u normal &
exit
else
if [ -f "/tmp/Search-Directory-Results.txt" ]; then
rm "/tmp/Search-Directory-Results.txt"
fi
grep_menu()
{
im="zenity --list --radiolist --title=\"Search Directory\" --text=\"Please select one of the search options below:\""
im=$im" --column=\"☉\" --column \"Option\" --column \"Description\" "
im=$im"TRUE \"case-sensitive\" \"Match only: Text\" "
im=$im"FALSE \"case-insensitive\" \"Match: TEXT, text, Text...\" "
}
grep_option()
{
choice='echo $im | sh -'
if echo $choice | grep -iE "case-sensitive|case-insensitive" > /dev/null
then
if echo $choice | grep "case-sensitive" > /dev/null
then
grep -- "$SearchText" *.* > "/tmp/Search-Directory-Results.txt"
fi
if echo $choice | grep "case-insensitive" > /dev/null
then
grep -i -- "$SearchText" *.* > "/tmp/Search-Directory-Results.txt"
fi
fi
}
grep_menu
grep_option
fi
zenity --class=LIST --text-info \
--editable \
--title="Search Directory" \
--filename="/tmp/Search-Directory-Results.txt"
fi
exit 0