LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 05-27-2004, 08:06 AM   #1
LYK
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 !

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

Rep: Reputation: 36
Hello,

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

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

Rep: Reputation: 111Reputation: 111
Code:
#!/bin/bash

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.
 
  


Reply


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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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