find files on first level folder


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers find files on first level folder
# 1  
Old 07-28-2010
find files on first level folder

Hi:

I have:

Code:
folderA
   |----folderB
              |----folder1
              |----folder2
              |----folder3
                       |----folder3.1

Question:

How can I find *.txt ONLY from /folderA/folderB/ and not the others folder1,2,3??

I tried:
Code:
 find /folderA/folderB/ -name *.txt

but it didn't work.

thanks
Israel.
# 2  
Old 07-28-2010
Use :


Code:
find /folderA/folderB/ -name *.txt -prune

or

Code:
find /folderA/folderB/ -name *.txt -maxdepth 1

# 3  
Old 07-28-2010
Hi,

Code:
 find /folderA/folderB/ -name -maxdepth 1 *.txt

does this. BTW: this will not work correct, if you have any files with .txt in the directory where you call the find command. The better way:

Code:
 find /folderA/folderB/ -name -maxdepth 1 '*.txt'

This will prevent the shell from expanding the wildcard.

best regards
Andreas
# 4  
Old 07-28-2010
Hi dennis and danimath,

Sorry, I forgot to say I'm on AIX, and -maxdepth is not a valid option. And using prune didn't work either... :-(

thanks to both

regards
Israel.
# 5  
Old 07-28-2010
Code:
for f in /home/amitsahr/
do
   [ -f "$f" ]   | ls *txt
done

# 6  
Old 07-28-2010
Why not to try ls ?

Code:
ls -1 /folderA/folderB/*.txt

# 7  
Old 07-28-2010
And if you need file under folderA also

Code:
for f in folderA/*txt folderA/folderB/*txt; do [ -f $f ] && echo $f; done

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find common lines between all of the files in one folder

Could it be possible to find common lines between all of the files in one folder? Just like comm -12 . So all of the files two at a time. I would like all of the outcomes to be written to a different files, and the file names could be simply numbers - 1 , 2 , 3 etc. All of the file names contain... (19 Replies)
Discussion started by: Eve
19 Replies

2. Shell Programming and Scripting

Find and Move Files up One Level

Hi All, So I have another question. I'm trying to search for files with a certain extension and then move all of them up one level in the folder hierarchy. So something like this: original: /path/to/file/test.txt after: /path/to/test.txt I had some great help recently with another... (4 Replies)
Discussion started by: ideal2545
4 Replies

3. Shell Programming and Scripting

Folder level size monitoring

Hi All, I have a requirement to monitor the sub-directories under /home in a way that if the the folder size increases by 30 GB in a span of like an hour then it needs to send email alerts listing what as the actual size was and what's the current size which the subject listing the sub-directory... (25 Replies)
Discussion started by: Shailesh6
25 Replies

4. Red Hat

Find a word from multiple level files on Linux

To find a word from multiple level files: "find . -type f -exec grep {} +" is working on UNIX machines but not working on Linux machine. What is the equivalent command on Linux to find the word from multiple level files? Input is appreciated. (3 Replies)
Discussion started by: ywu081006
3 Replies

5. Cybersecurity

Ubuntu folder level security

I have installed ubuntu. And I have create users ans groups. Suppose if the user enter into through Putty SSH. He should have access only to home folder and cannot move to other than $HOME. User should not able to root files and /$ files. Kindly provide solution. Regards Vasanth kumar (3 Replies)
Discussion started by: vasanthrj
3 Replies

6. Shell Programming and Scripting

Find all text files in folder and then copy to a new folder

Hi all, *I use Uwin and Cygwin emulator. I´m trying to search for all text files in the current folder (C/Files) and its sub folders using find -depth -name "*.txt" The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Discussion started by: cgkmal
4 Replies

7. UNIX for Dummies Questions & Answers

To find files with specific dates and cp another folder.

Hi all, We have an existing script: find /u03/oraprod/perpcomn/admin/out -type f -ctime +7 \ -exec cp {} "/u08/oraprod/backup/cout" \; Which is to find all files more than 7 days and copy to another folder. However I would like to only list files with Sep 29, and cp to another folder. ... (2 Replies)
Discussion started by: *Jess*
2 Replies

8. Shell Programming and Scripting

operation on a folder level

hi, need help in writing a script in perl. requirement : 1. Search for the files in a particular folder 2. search for a string in the file names 3. Delete the file which matches the string. Ex: if the folder is C:\TEST and the folder has 5 files like 2009ABCG.txt 2009MNO.txt... (2 Replies)
Discussion started by: adityamahi
2 Replies

9. Shell Programming and Scripting

find how many files are in use in a folder

How can i find how many files are in use in a folder or its sub folders in unix i tried with fuser .. but i coulnt getting ... (3 Replies)
Discussion started by: smongam
3 Replies

10. Shell Programming and Scripting

How to find files in current folder only?

How do I find files in current folder only? We are on AIX 5.3, so maxdepth is not supported. I tried to do this find /dir1/dir2/dir3/dir4 -prune -type f to display all files in /dir1/dir2/dir3/dir4 only but it does not show any files. Somehow the -prune option works for dir3 level... (7 Replies)
Discussion started by: Hangman2
7 Replies
Login or Register to Ask a Question