Request for shell script for listing directories, subdirs containing specific files.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Request for shell script for listing directories, subdirs containing specific files.
# 1  
Old 10-11-2011
Question Request for shell script for listing directories, subdirs containing specific files.

I'm looking for a script which outputs the list of directories and sub directories from root level consisting of specific files. For instance I want shell script to list all the directories and subdirectories containing .txt files.Smilie
# 2  
Old 10-11-2011
Try using find
Code:
man find         # for detail in find
find . -type f -name "*.txt"

# 3  
Old 10-11-2011
posix,

Thanks for the providing the command. Want I really want is shell script outputing just the directories and subdirectories and not list the files.
Code:
$ find . -type f -name '*sas7b*'
./employee.sas7bdat
./employee.sas7bndx
./employee1.sas7bdat
./sasuser.v91/regstry.sas7bitm
./test/employee.sas7bdat
./test/new1.sas7bvew

I'm looking for list like following
Code:
.
./test

. is my home directory

Last edited by Franklin52; 10-12-2011 at 03:32 AM.. Reason: Please use code tags, thank you
# 4  
Old 10-11-2011
Code:
find . -type f -name '*.txt' | nawk -F/ 'NF-- && $1=$1' OFS=/ | sort -u

# 5  
Old 10-11-2011
No luck
Code:
$ find . -type f -name '*sas7b*' | nawk -F/ 'NF-- && $1=$1' OFS=/ | sort -u
./employee.sas7bdat
./employee.sas7bndx
./employee1.sas7bdat
./sasuser.v91/regstry.sas7bitm
./test/employee.sas7bdat
./test/new1.sas7bvew

I'm looking for list of directories and sub directories
here output I'm looking for is
Code:
.
./test
./sasuser.v91

---------- Post updated at 01:46 PM ---------- Previous update was at 12:05 PM ----------

Any other ideas?

---------- Post updated at 03:02 PM ---------- Previous update was at 01:46 PM ----------

Smilie
Quote:
Originally Posted by super210
No luck

$ find . -type f -name '*sas7b*' | nawk -F/ 'NF-- && $1=$1' OFS=/ | sort -u
./employee.sas7bdat
./employee.sas7bndx
./employee1.sas7bdat
./sasuser.v91/regstry.sas7bitm
./test/employee.sas7bdat
./test/new1.sas7bvew

I'm looking for list of directories and sub directories
here output I'm looking for is
.
./test
./sasuser.v91

---------- Post updated at 01:46 PM ---------- Previous update was at 12:05 PM ----------

Any other ideas?

Last edited by Franklin52; 10-12-2011 at 03:32 AM.. Reason: Please use code tags, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

2. Shell Programming and Scripting

Make directories containing subdirs using mkdir

Hello everybody, I wonder if there's a way to make a directory that contains multiple subdirectories. For example, if I want to make /home/student under the current working directory, how do I do it? Can I do it using a single mkdir command or do I have make home first, cd into it and then make... (1 Reply)
Discussion started by: Yongfeng
1 Replies

3. UNIX for Dummies Questions & Answers

Listing files without specific expression in the file

I am running Ubuntu 11.10 I have the following files. geo2503r05690585.html geo2503r06020612.html geo2503r06250641.html geo2503r06490658.html geo2503r06830686.html geo2503r05860601.html geo2503r06130624.html geo2503r06420648.html geo2503r06590682.html ... (4 Replies)
Discussion started by: kristinu
4 Replies

4. Shell Programming and Scripting

listing directories with more than x files

How can I find and print the directories on a server that have more than 5,000 files? There's some spam emails and I'm trying to find all directories that have a lot of spam The file count should just be the files directly under that directory, not like the total from all nested directories ... (1 Reply)
Discussion started by: vanessafan99
1 Replies

5. Shell Programming and Scripting

Need help in listing directories inside korn shell script

Hi All, I need to loop through each item in current path, if it is a direcotry do soemthing, if its a file jsut skip it and move to next item in loop. Tried if test ! -d $i then echo "The current item $i is not a directory" continue fi This doesnt seems to be working .... (8 Replies)
Discussion started by: justchill
8 Replies

6. Shell Programming and Scripting

Script for listing specific filename in 3 directory

I used to work in perl but I would like to try now bash. Here's my problem I wanted to search for specific filename (ls -ltrh) on 3 directories.. Example ls -ltrh | grep "string" /dir1 /dir1/dir2 /dir1/dir2/dir3 I wanted to get the result to be copied on a different directory. Sample... (2 Replies)
Discussion started by: lhareigh890
2 Replies

7. Shell Programming and Scripting

listing all code in all files in all directories

Hi all, can any one help me out in this::: basically i need to list all the contents in all files in all directories (starting from root and then onwards)...i will get the session saved in a file (just a secure CRT, etc) seems to be a simple one. if anyone can come forward, its really... (4 Replies)
Discussion started by: asadlone
4 Replies

8. Shell Programming and Scripting

Listing Deleted Files and Directories

Please provide me a shell script so that i can list which file or directory has been deleted, by which user and at what time. The script should take date as argument and should list out name of the file/directory, which user had deleted them and at what time since that particular date. Kindly post. (1 Reply)
Discussion started by: raviviolet13
1 Replies

9. UNIX for Dummies Questions & Answers

files and directories listing

Hello: I need to list some files into some directories ordered by size. i need help! BEst regards Alberto (1 Reply)
Discussion started by: bbolson
1 Replies
Login or Register to Ask a Question