LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find command (https://www.linuxquestions.org/questions/linux-newbie-8/find-command-650505/)

mksc 06-20-2008 07:43 AM

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

clvic 06-20-2008 07:55 AM

find "$dir" -name "*.sh" > /root/shFiles
should be what you are looking for

mrrangerman 06-20-2008 08:45 AM

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.

Agrouf 06-20-2008 09:45 AM

Quote:

Originally Posted by clvic (Post 3190168)
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.


All times are GMT -5. The time now is 02:44 AM.