Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-27-2004, 08:06 AM   #1
LQ Newbie
Registered: May 2004
Distribution: Red Hat Linux 9
Posts: 4

Rep: Reputation: 0
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 !

Old 05-27-2004, 10:29 AM   #2
Senior Member
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36

I think that find command can do all that things...
man find
for more precisions

Old 05-27-2004, 10:51 AM   #3
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111

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

Last edited by Hko; 05-27-2004 at 11:22 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Split function (bash script) NiM Programming 11 03-10-2012 06:53 AM
Does anyone know of a bash script can search & replace txt in a file. jimwelc Linux - Newbie 6 09-15-2008 12:13 AM
Bash Script Passing variable to Function nutthick Programming 2 02-02-2005 05:15 AM
C built-in function for a Bash script Linh Programming 3 04-23-2004 09:23 AM
New search function jeremy LQ Suggestions & Feedback 1 12-11-2002 01:37 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:57 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration