[Solved] Finding the Files In the Same Name Directories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] Finding the Files In the Same Name Directories
# 1  
Old 12-07-2011
[Solved] Finding the Files In the Same Name Directories

Hi,

In the Unix Box, I have a situation, where there is folder name called "Projects" and in that i have 20 Folders S1,S2,S3...S20. In each of the Folders S1,S2,S3,...S20 , there is a same name folder named "MP". So Now, I want to get all the files in all the "MP" Folders and write all those file names into a File. Can you guys Please help me out. Thanks in Advance.
# 2  
Old 12-08-2011
Simply:
Code:
ls Projects/S*/MP

(assuming there is only S1, S2, ... S20 in Projects)

If there are others, then:
Code:
ls Projects/S{{,1}{1,2,3,4,5,6,7,8,9},{1,2}0}/MP

(assuming bash or csh)
or even:
Code:
ls $(seq --format='Projects/S%g/MP' 1 20)

if you need to preserve order.
This User Gave Thanks to m.d.ludwig For This Post:
# 3  
Old 12-08-2011
MySQL Thanks a lot Ludwig

Thanks a lot ludwig.. It didn't work on my SunOS. But your answer made me think the possible solution.

Solution:
ls -lart Projects/*/MP
# 4  
Old 12-08-2011
Which turned out to be what?
# 5  
Old 12-08-2011
MySQL Even This is Working..

ls Projects/S[1,2,3,4,5]/MP
# 6  
Old 12-08-2011
Please mention your Operating System and version and your preferred Shell.

If you want the full path name to each file in each of the subdirectories called "MP", here is one method:

Code:
#!/bin/ksh
(
for DIR1 in S1 S2 S3 S4 S5 S6 S7 S8 S9 S10 \
               S11 S12 S13 S14 S15 S16 S17 S18 S19 S20
do
       find "/your_path/Projects/${DIR1}" -type d -name 'MP' -print | \
       while read DIR2
       do
                 find "${DIR2}" -type f -print
       done
done
) | sort  > /tmp/list_of_files.lst


Posts have crossed while I have been typing. The "find" approach is much quicker and safer for large numbers of files or filenames containing space characters.

Last edited by methyl; 12-08-2011 at 11:51 AM.. Reason: Added sort so the filenames come out in the same order as "ls" but quicker!
This User Gave Thanks to methyl For This Post:
# 7  
Old 12-08-2011
MySQL Thanks Methyl

As i am a Newbee..It took lot of time to understand do while, but thanks a lot..once a gain..it worked..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding files deep in directories

i need to find a portable way to go through multiple directories to find a file. I've trid something like this: find /opt/oracle/diag/*/alert_HH2.log -printordinarily, i can run the ls command and it will find it: /opt/oracle/diag/*/*/*/*/alert_HH2.log The problem with this approach is... (3 Replies)
Discussion started by: SkySmart
3 Replies

2. Shell Programming and Scripting

Finding non-existing words in a list of files in a directory and its sub-directories

Hi All, I have a list of words (these are actually a list of database table names separated by comma). Now, I want to find only the non-existing list of words in the *.java files of current directory and/or its sub-directories. Sample list of words:... (8 Replies)
Discussion started by: Bhanu Dhulipudi
8 Replies

3. Programming

Finding duplicate files in two base directories

Hello All, I have got some assignment to complete till this Monday and problem statement is as follow :- Problem :- Find duplicate files (especially .c and .cpp) from two project base directories with following requirement :- 1.Should be extendable to search in multiple base... (4 Replies)
Discussion started by: anand.shah
4 Replies

4. Shell Programming and Scripting

[Solved] Creation of directories

i am having trouble creating a directory with last months date as the folder name. what i am using is echo `date +%b%y` which gives Mar14 as the result but i want to get Feb14 as the result.:wall: (6 Replies)
Discussion started by: simkazw
6 Replies

5. Shell Programming and Scripting

finding matches between multiple files from different directories

Hi all... Can somebody pls help me with this... I have a directory (dir1) which has many subdirectories(vr001,vr002,vr003..) with each subdir containing similar text file(say ras.txt). I have another directory(dir2) which has again got some subdir(vr001c,vr002c,vr003c..) with each subdir... (0 Replies)
Discussion started by: bramya07
0 Replies

6. UNIX for Dummies Questions & Answers

Finding size of all directories

Alright so I've tried a couple different things that at first glance, looked like they worked. find . -maxdepth 5 -type d -daystart -mtime 1 | xargs du -h Which seems to ignore the previous commands such as depth and modified time. find .. -maxdepth 2 -type d -daystart -ctime 1 | xargs... (8 Replies)
Discussion started by: Aussiemick
8 Replies

7. Shell Programming and Scripting

Solved: finding diff in files

i want to compare 2 files and generate below 3 files: 1. new lines 2. updated lines 3. deleted lines are there any one liners for each one of them. Note the method to find duplicates is based on field 1, values are separated by '|' example: test1 (older file) 1|XXX 2|YYY... (3 Replies)
Discussion started by: manishma71
3 Replies

8. Shell Programming and Scripting

Script for parsing directories one level and finding directories older than n days

Hello all, Here's the deal...I have one directory with many subdirs and files. What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file. A script for... (5 Replies)
Discussion started by: ejianu
5 Replies

9. UNIX for Dummies Questions & Answers

finding largest files (not directories)?

hello all. i would like to be able to find the names of all files on a remote machine using ssh. i only want the names of files, not directories so far i'm stuck at "du -a | sort -n" also, is it possible to write them to a file on my machine? i know how to write it to a file on that... (2 Replies)
Discussion started by: user19190989
2 Replies

10. UNIX for Dummies Questions & Answers

Finding executable files in all directories

This is probably very easy but I would like to know a way to list all my files in all my directories that are readable and executable to everyone. I was told to use find or ls and I tried some stuff but couldnt get it to work. I understand that its dangerous to have files with these permissions for... (4 Replies)
Discussion started by: CSGUY
4 Replies
Login or Register to Ask a Question