Find files ONLY in current directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find files ONLY in current directory
# 1  
Old 10-31-2008
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  
Old 10-31-2008
Quote:
Originally Posted by gio001
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  
Old 10-31-2008
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  
Old 10-31-2008
Code:
grep -l searchstring *

# 5  
Old 10-31-2008
man find
Code:
find . -maxdepth 1 -type f

# 6  
Old 10-31-2008
Hammer & Screwdriver 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  
Old 10-31-2008
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$"`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

2. Shell Programming and Scripting

Find specific files only in current directory...not sub directories AIX

Hi, I have to find specific files only in the current directory...not in the sub directories. But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help.. I am using the below command. And i am... (2 Replies)
Discussion started by: aakishore
2 Replies

3. Shell Programming and Scripting

Find files only in current directory...not subdirectories

Hi, I have to find files only in the current directory...not in the sub directories. But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help..I tried to use maxdepth..but it is not working in AIX. (2 Replies)
Discussion started by: vsachan
2 Replies

4. UNIX for Dummies Questions & Answers

find command to look for current directory only

i have this find command on my script as: for i in `find $vdir -name "$vfile" -mtime +$pday` the problem with this code is that the sub-directories are included on the search. how do i restrict the search to confine only on the current directory and ignore the sub-directories. please advise.... (7 Replies)
Discussion started by: wtolentino
7 Replies

5. Shell Programming and Scripting

How to find particular string in multiple files with in the current directory.

Hello friends, Plz suggest the find command, How to search a string in a paticular string in miltiple files with current dirctory.:) Thanks in advance. Siva Ranganath Ch (2 Replies)
Discussion started by: sivaranga001
2 Replies

6. Shell Programming and Scripting

Finding files in current directory when 100,000's files in current directory

Hi All I was wondering what is the most efficient way to find files in the current directory(that may contain 100,000's files), that meets a certain specified file type and of a certain age. I have experimented with the find command in unix but it also searches all sub directories. I have... (2 Replies)
Discussion started by: kewong007
2 Replies

7. UNIX for Dummies Questions & Answers

how to stop to current directory using find

Hello, I just want to ask the following use of find command: 1. how can I find files only to the current directory? 2. how can I find files to directories and all subdiretories (are this include soft links?) but will not go to other mountpoints that is under that mountpoint. Im combining... (1 Reply)
Discussion started by: james_falco
1 Replies

8. Shell Programming and Scripting

how do i exclude the current directory when using find?

i want to compile a list of files in all sub directories but exclude the current directory. the closest i could get was to search 'only' the current directory, which is the opposite of what i wanted. find . ! -name . -prune (7 Replies)
Discussion started by: mjays
7 Replies

9. UNIX for Dummies Questions & Answers

find directory not including current

Using Solaris 8, I've forgotten how to exclude the current directory in the find results. find . -type d ! -name "*.CAP" I want every directory that does not match the *.CAP pattern, except the current directory. (2 Replies)
Discussion started by: dangral
2 Replies

10. UNIX for Dummies Questions & Answers

using find command only in current directory

I am trying to use the find command to find files in the current directory that meet a certain date criteria. find . -type -f -mtime +2 However, the above also checks the directories below. I tried -prune, but that seems to ignore this directory completely. I read about using -path w/... (5 Replies)
Discussion started by: jliebling
5 Replies
Login or Register to Ask a Question