Help with listing only subfolders


 
Thread Tools Search this Thread
Operating Systems AIX Help with listing only subfolders
# 1  
Old 05-14-2015
Help with listing only subfolders

Hi All,

I have a AIX file system with a folder structure like this

Code:
/1
/1/2
/1/2/3/5
/1/2/3/2
/2
/2/3/4
/2/5/6

I would like to list subdirectories
Code:
/1/2/3/5
/1/2/3/2
/2/3/4
/2/5/6

Can you please help me with this issue.

Thanks in advance.- Kavin

Last edited by Don Cragun; 05-14-2015 at 04:42 AM.. Reason: Add CODE tags.
# 2  
Old 05-14-2015
Hello Kavin,

Please do use code tags for commands/codes you are using in your posts as per forum rules, following may help you in same.

Code:
find -mindepth 2 -type d -printf '%P\n'

Above command will look for minimum 2nd level of directory structure and for maximum level of inner sub directories. But if you want to fix minimum and maximum directory levels you can do following for an example.
Code:
find -mindepth 2 -maxdepth 3 -type d -printf '%P\n'

Hope this helps.



Thanks,
R. Singh
# 3  
Old 05-14-2015
Try:
Code:
find . -type d -depth | awk '!($0 in A); { sub("[/][^/]*$",x); A[$0]}'



---
Note: -maxdepth and -printf options to the find command are extensions and GNU find only (so not available as standard on AIX).

Last edited by Scrutinizer; 05-14-2015 at 05:04 AM..
# 4  
Old 05-14-2015
you can use below command to get all the sub directories - It will not list you single directory under a parent directory.

Code:
find . -type d -print | awk -F "/" '{if(NF>"2"){print $0};}'

HTH!!
# 5  
Old 05-14-2015
A few years ago I posted this "smoking" solution
Code:
find . -depth -type d | awk -F/ 'NF>=prev {print} {prev=NF}'

This User Gave Thanks to MadeInGermany For This Post:
# 6  
Old 05-15-2015
Thanks

Thanks guys for the response. The command worked perfectly for me.
# 7  
Old 05-15-2015
Thanks for the feedback. Which command are you referring to? There are several in this thread...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] How to remove listing of current user cmd from ps -ef listing?

Hi All, Could you please help to resolve my following issues: Problem Description: Suppose my user name is "MI90". i.e. $USER = MI90 when i run below command, i get all the processes running on the system containing name MQ. ps -ef | grep MQ But sometimes it lists... (8 Replies)
Discussion started by: KDMishra
8 Replies

2. Shell Programming and Scripting

number of subfolders

Hello people i need your help, am still new at unix, How do you find the number of subfolders in a certain or current directory?? (4 Replies)
Discussion started by: donc123
4 Replies

3. 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

4. Shell Programming and Scripting

grep to search the subfolders

Hi everybody, I am trying to grep abcds in one folder and in all its subfolders! but it does not work! would you help please? thanks. (3 Replies)
Discussion started by: messi777
3 Replies

5. Shell Programming and Scripting

Search in folder and subfolders

How can this be done? I mean, I want to search for all *png *jpg *bmp files in my ~/Pictures/ folder....How can I list them? Thank you geeks :) :b: (2 Replies)
Discussion started by: hakermania
2 Replies

6. UNIX for Dummies Questions & Answers

Last Modified Date for subfolders

Sorry for the basic question, but I have a feeling that my developers are circumventing our change control process, and I want to be able to easily keep track of the last modified date of sub-folders of the production folder. Basically, we have this major folder PROD, and then each application... (1 Reply)
Discussion started by: saint01
1 Replies

7. 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

8. UNIX for Dummies Questions & Answers

subfolders help please important

hi all. I just only wanna show all files from a whole 'root-table'....to understand: "ls *.exe" ...for instance in the directory it only shows the files from the folder, but not form the subfolders !? how to solve this problem ? if you are on your home /root/users/.... I want to see all files... (10 Replies)
Discussion started by: svennie
10 Replies

9. UNIX for Dummies Questions & Answers

TAR (Extract with subfolders)

Hi! I've uploaded a .tar file (created with Windows) containing my homepage to my webserver. Now I'd like to extract the file on the server. I can do that with SSH. BUT:: If i enter this command: tar -xf homepage.tar only the files in the root directory of the file get extracted.... (2 Replies)
Discussion started by: roberthawke
2 Replies

10. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies
Login or Register to Ask a Question