The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Unix Find commands scooter17 UNIX for Dummies Questions & Answers 1 09-11-2006 03:55 PM
Omitting some filenames for commands to process milhan Shell Programming and Scripting 5 05-19-2006 07:49 PM
where i can find list of UNIX commands for daily operations ? mgoutham UNIX Desktop for Dummies Questions & Answers 1 03-02-2006 02:35 PM
Unix History Question: Why are filenames/dirnames case sentsitive in Unix? deckard UNIX for Dummies Questions & Answers 3 03-26-2005 01:59 PM
find lowercase filenames jpprial UNIX for Dummies Questions & Answers 4 01-28-2002 04:57 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 3.00 average. Display Modes
  #1 (permalink)  
Old 06-24-2008
deepakgang deepakgang is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 38
find filenames like unix commands

Hi,

I need to write a small script to search in some specific directories to check if any file is present with a unix command name...
Means if the directory contains any files like cat, vi, grep, find etc i need to list those files into a file.

Please help
Thanks,
D
  #2 (permalink)  
Old 06-24-2008
s123.radha s123.radha is offline
Registered User
  
 

Join Date: Apr 2008
Location: Bangalore
Posts: 18
u can have a shell script like "search.sh" which accepts a directory name as an argument..


search.sh may look like

#! /bin/sh
DIR_NAME =$1
# u have to search for all the unix files one by one like and write to serach.log file. Below command will do the same for you
#find DIR_NAME name nameoffile > search.log
find DIR_NAME name cat > search.log
find DIR_NAME name grep > search.log

I am also new to linux.. this solution will work but only thing is the script will be as long as set of unix commands u want to find out.

Cheers!!
  #3 (permalink)  
Old 06-24-2008
deepakgang deepakgang is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 38
is there any option in find command for the purpose like:


find . -name "cat" -print

will print only the files named like cat.. if we can add multiple patterns in the place of cat , thats what i need.
  #4 (permalink)  
Old 06-24-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
Code:
find . -type f | grep -E "cat|vi|grep"
Add further patterns by separating them with a pipe.
  #5 (permalink)  
Old 06-24-2008
spirtle spirtle is offline
Registered User
  
 

Join Date: Jun 2008
Location: Scotland
Posts: 150
If your version of find supports the -regexp flag, you can do
Code:
find dir -type f -regexp ".*\(cat\|vi\|grep\)"
Otherwise
Code:
find dir -type f -name cat -o -name vi -o -name grep
  #6 (permalink)  
Old 06-25-2008
deepakgang deepakgang is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 38
Thanks buddies

find . -type f | grep -E "cat|vi|grep"

will get any files matching the pattern. Therefore if there is a file like "catert"
or "vides" they will also match cat and vi pattern and I want the exact pattern. I tried grep -Ex but not working.

There fore

find dir -type f -name cat -o -name vi -o -name grep

is the one which can be used I believe though it will become lengthier
Closed Thread

Bookmarks

Tags
linux, linux commands, solaris, unix commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0