-   Programming (
-   -   search function (bash script) (

LYK 05-27-2004 09:06 AM

search function (bash script)
Here are some questions for all bash scripting experts out there

1. How do I implement a recursive search function in a bash script ? For example, If I type the name of a directory, it would then start searching that specified directory. What does it search for, you ask ? well, how about : the longest named file ?

2. Here's another one, but instead of searching directories, it searches for files. If I type several filenames, it would then perform a search. The final result would then display the newest file from the list.

Hope to hear a reply soon. And Thank you in advance !


Oliv' 05-27-2004 11:29 AM


I think that find command can do all that things...

man find
for more precisions :)


Hko 05-27-2004 11:51 AM



echo -n "Enter directory: "
read DIR
cd $DIR >/dev/null

echo "Longest file name in $DIR is:"
ls | while read L ; do
        test -f $L && echo "${#L} $L"
done | sort -nr | head -1 | cut -d' ' -f2
exit 0

All times are GMT -5. The time now is 08:50 AM.