Find for files within a list of subfolders


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Find for files within a list of subfolders
# 1  
Old 07-25-2018
Find for files within a list of subfolders

Helo
Is there a better way to search within a list of subfolders :
Code:
A_START_PATH="/data_1/data_2"
#
# dir2, dir3, dir6,  ..... dir59 exists
#

A_LIST="$A_START_PATH/dir1 $A_START_PATH/dir4 $A_START_PATH/dir5"
 find "$A_LIST" -type f -name"*.txt"

Now searching for all files in any subdirs named 'src' within dir1, dir4, dir5
Code:
find ..................

# 2  
Old 07-25-2018
It's okay.
If all of you directories start with $A_START_PATH
then you can perhaps cd to it and use shorter names (relative to the current directory).
Code:
cd "$A_START_PATH" || exit
A_LIST="dir1 dir4 dir5"
find $A_LIST -type f -name"*.txt"

$A_LIST must not be in qutoes, otherwise the shell won't split it into words.
These 2 Users Gave Thanks to MadeInGermany For This Post:
# 3  
Old 07-25-2018
[CLOSED] Find for files within a list of subfolders

Quote:
Originally Posted by MadeInGermany
It's okay.
If all of you directories start with $A_START_PATH
then you can perhaps cd to it and use shorter names (relative to the current directory).
Code:
cd "$A_START_PATH" || exit
A_LIST="dir1 dir4 dir5"
find $A_LIST -type f -name"*.txt"

$A_LIST must not be in qutoes, otherwise the shell won't split it into words.
Thank you very much
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting a folder containing different files into subfolders

I have a folder with 4000 (*3) files like gr_q4_gb-1.anc gr_q4_gb-1.anc_cdr_st.txt gr_q4_gb-1.anc_cdr_tr.txt gr_q4_gb-2.anc gr_q4_gb-2.anc_cdr_st.txt gr_q4_gb-2.anc_cdr_tr.txt gr_q4_gb-3.anc gr_q4_gb-3.anc_cdr_st.txt gr_q4_gb-3.anc_cdr_tr.txt . . gr_q4_gb-4000.anc... (6 Replies)
Discussion started by: sammy777888
6 Replies

2. Shell Programming and Scripting

Find command to find a word from list of files

I need to find a word '% Retail by State' in the folder /usr/sas/reports/RetailSalesTaxallocation. When I tried like below, -bash-4.1$ cd /usr/sas/reports/RetailSalesTaxallocation -bash-4.1$ find ./ -name % Retail by State find: paths must precede expression: Retail Usage: find ... (10 Replies)
Discussion started by: Ram Kumar_BE
10 Replies

3. Shell Programming and Scripting

List all the files in the present path and Folders and subfolders files also

Hi, I need a script/command to list out all the files in current path and also the files in folder and subfolders. Ex: My files are like below $ ls -lrt total 8 -rw-r--r-- 1 abc users 419 May 25 10:27 abcd.xml drwxr-xr-x 3 abc users 4096 May 25 10:28 TEST $ Under TEST, there are... (2 Replies)
Discussion started by: divya bandipotu
2 Replies

4. UNIX for Dummies Questions & Answers

Need help in checking for files in subfolders

Hi, I am trying to print a listing of files from the top level directory, check to see if any files have the same name as the top level directory name and if so, cd to that file and list the files under it. Don't know how to check for the file in the next level. What I have so far: ... (6 Replies)
Discussion started by: tes218
6 Replies

5. Shell Programming and Scripting

find list of files from a list and copy to a directory

I will be very grateful if someone can help me with bash shell script that does the following: I have a list of filenames: A01_155716 A05_155780 A07_155812 A09_155844 A11_155876 that are kept in different sub directories within my current directory. I want to find these files and copy... (3 Replies)
Discussion started by: manishabh
3 Replies

6. Shell Programming and Scripting

I need a script to find socials in files and output a list of those files

I am trying to find socail security numbers in files in (and under) a specific directory and output a list of the files where they are found... the format would be with no dashes just 9 numeric characters in a row. I have tried this: find /DirToLookIn -exec grep '\{9\}' /dev/null {} \; >>... (1 Reply)
Discussion started by: NewSolarisAdmin
1 Replies

7. UNIX for Dummies Questions & Answers

find, mv and create unknown parent & subfolders

I searched the forum rather thoroughly but still could not find the answer. Hopefully the solution is right under my nose. Here what I need to do, move older data to a Archive folder that is 18 months old and older. I would like to use the following command, find departmentx/* -mtime 530... (5 Replies)
Discussion started by: cheeba
5 Replies

8. UNIX for Advanced & Expert Users

find size of folders and its subfolders with the Owner details

HI, I have the following command that shows me the total size of folders and subfolders : du -hs *| sort -n result: 1.0M sandeep 1.4G sandy 1.4M important 1.6M files but I will need to know the size of folders and its subfolders( not size of individual files though)... (5 Replies)
Discussion started by: bsandeep_80
5 Replies

9. UNIX for Dummies Questions & Answers

Basic Q: getting list of all files of type within folder & subfolders

A painfully rudimentary UNIX question for somebody. I've been puzzling over this for the last hour but can't find the right command. I'm simply trying to get a list of all files - and their full paths - within a folder & subfolders which have extension .php and .js. That's it! No amount of... (1 Reply)
Discussion started by: AtomicPenguin
1 Replies

10. UNIX for Dummies Questions & Answers

rename files in subfolders

Hello i have this script : foreach f ($1/*.cpp ) mv $f $f:r.c end that renames me files in dir , how can i change it so it will rename me also in subdirectorys? thanks (0 Replies)
Discussion started by: umen
0 Replies
Login or Register to Ask a Question