LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-20-2008, 08:43 AM   #1
mksc
LQ Newbie
 
Registered: May 2008
Posts: 10

Rep: Reputation: 0
Exclamation find command


hi all

I want to find out all .sh files in a directory and store result in a file. I am doing it like this

"find "$dir" *.sh | grep "$dir" | grep .sh >> /root/shFiles"

but result includes those file which contains "sh" in their file name.
But i want only .sh files.

How can I solve this.

Thanks
MKSC
 
Old 06-20-2008, 08:55 AM   #2
clvic
Member
 
Registered: Feb 2008
Location: Rome, Italy
Distribution: OpenSuSE 11.x, vectorlinux, slax, Sabayon
Posts: 206
Blog Entries: 2

Rep: Reputation: 45
find "$dir" -name "*.sh" > /root/shFiles
should be what you are looking for
 
Old 06-20-2008, 09:45 AM   #3
mrrangerman
Member
 
Registered: Oct 2007
Location: MI
Distribution: Debian Slackware
Posts: 528

Rep: Reputation: 50
Quote:
clvic
find "$dir" -name "*.sh" > /root/shFiles
should be what you are looking for
It should be added, if he has other data in the file and doesn't want to overwrite it use >> to apend to file.
 
Old 06-20-2008, 10:45 AM   #4
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
Quote:
Originally Posted by clvic View Post
find "$dir" -name "*.sh" > /root/shFiles
should be what you are looking for
find "$dir" -name '*.sh' > /root/shFiles

This one will work better.
Note the quotes around *.sh
If you put "*.sh", bash will replace with *.sh in current directory and find may try to find myscript.sh and only myscript.sh. With simple quotes, find correctly try to find anything that terminates whith sh.
 
  


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
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 06:30 PM
find command mdyer772 Linux - General 3 10-15-2006 01:18 AM
What is the FIND command Mic Q SUSE / openSUSE 1 04-07-2005 10:08 AM
Help with FIND command please C-Royd Linux - Newbie 3 06-17-2004 04:43 PM
not find mt command imsajjadali Red Hat 2 02-07-2004 07:27 AM


All times are GMT -5. The time now is 12:26 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration