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
how to stop to current directory using find james_falco UNIX for Dummies Questions & Answers 1 07-17-2007 09:43 PM
how do i exclude the current directory when using find? mjays Shell Programming and Scripting 7 04-24-2007 09:13 AM
Question about Restricting Search path of FIND to current directory super_duper_guy UNIX for Dummies Questions & Answers 2 10-17-2005 10:10 AM
find directory not including current dangral UNIX for Dummies Questions & Answers 2 01-26-2005 03:02 PM
using find command only in current directory jliebling UNIX for Dummies Questions & Answers 5 02-22-2001 10:00 PM

Reply
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 Rate Thread Display Modes
  #1 (permalink)  
Old 10-31-2008
gio001 gio001 is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 70
Find files ONLY in current directory

Hello all,
I am having a hard type in figuring out how to only gather certain files in the current directory without exploring its subdirectories.
I tried:
find . -name "*.ksh" -prune
this also returns ksh files from lower subdirectories.
I also tried
find . -ls -name "*.ksh"
This also returned files in lower subdirs.
Can you help me, please.
Thanks.
  #2 (permalink)  
Old 10-31-2008
SFNYC SFNYC is offline
Registered User
  
 

Join Date: Jun 2008
Location: New York City
Posts: 95
Quote:
Originally Posted by gio001 View Post
Hello all,
I am having a hard type in figuring out how to only gather certain files in the current directory without exploring its subdirectories.
I tried:
find . -name "*.ksh" -prune
this also returns ksh files from lower subdirectories.
I also tried
find . -ls -name "*.ksh"
This also returned files in lower subdirs.
Can you help me, please.
Thanks.
I don't understand what you are trying to accomplish here. If you only want to get all the "*.ksh" files in the current directory, just use the 'ls' command on its own:
Code:
ls *.ksh
  #3 (permalink)  
Old 10-31-2008
gio001 gio001 is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 70
My question is all driven by this:

I am interested in files in my current directory, such files have either a ksh extension or no extension at all.

I want to gather these files through a one line command and follow this with a grep to go through this list and produce a second list of the ones which have a particular string in them

Final result I found my search string in either ksh files or no extension files.

Can you help?
Thanks.
  #4 (permalink)  
Old 10-31-2008
wempy's Avatar
wempy wempy is offline
Registered User
  
 

Join Date: Jun 2006
Location: Harpenden, UK
Posts: 208
Code:
grep -l searchstring *
  #5 (permalink)  
Old 10-31-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,428
man find
Code:
find . -maxdepth 1 -type f
  #6 (permalink)  
Old 10-31-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink Perhaps this points you in the correct direction

to find files with a particular extension
Code:
> ls | egrep -e ".txt|.sh"
file10.txt
sort22.sh*
to execute a command on the results, in a loop
here I wanted to print the first two lines of any matching files - and it did!
Code:
> for file in `ls | egrep -e ".txt|.sh"`; do head -2 $file; done
test,mno,mno, +asc
mno,lok,msyu,tts 
#! /usr/bin/bash

>
  #7 (permalink)  
Old 10-31-2008
wempy's Avatar
wempy wempy is offline
Registered User
  
 

Join Date: Jun 2006
Location: Harpenden, UK
Posts: 208
further to my earlier suggestion, I have realised that he only wants to search in .ksh files and files without an extension, all other files left alone, so
Code:
grep searchstring `ls |egrep  "^[a-zA-Z0-9]*$|^.*\.ksh$"`
Reply

Bookmarks

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 12:00 AM.


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