Show folder and only one subfolder using ls in command line
So I have many folders with many subfolders. All I want it to get the folder name and the first subfolder. I tried using ls -R but this give me more than I want it.
Let say I have: dir1/subdir1/sub_1_1/file.a dir1/subdir1/sub_1_1/file.a2 dir1/subdir1/sub_1_1/file.a3 dir1/subdir1/sub_1_1/file.a4 dir1/subdir1/sub_1_2/file.b dir1/subdir2/sub_2_1/file.c dir1/subdir3/sub_3_1/file.d dir1/subdir4/sub_4_1/file.e dir2/subdir1/sub_1_1/file.a dir2/subdir1/sub_1_2/file.b dir2/subdir2/sub_2_1/file.c dir2/subdir3/sub_3_1/file.d dir2/subdir4/sub_4_1/file.e dir3/subdir1/sub_1_1/file.a dir3/subdir1/sub_1_2/file.b dir3/subdir2/sub_2_1/file.c dir3/subdir3/sub_3_1/file.d dir3/subdir4/sub_4_1/file.e . . . All I want when I execute the command is to show me: dir1/subdir1 dir1/subdir1 dir1/subdir2 dir1/subdir3 dir1/subdir4 dir2/subdir1 dir2/subdir1 dir2/subdir2 dir2/subdir3 dir2/subdir4 dir3/subdir1 dir3/subdir1 dir3/subdir2 dir3/subdir3 dir3/subdir4 . . . |
I don't think you can do that with ls, but you can with find:
Code:
find . -type d -maxdepth 2 |
That was my first guess but maxdepth or the depth option dont work .....give me an argument error
|
How about showing us the exact command you used? It sounds like you have a syntax error somewhere.
This should work in simple cases, but will throw an error if there are no subdirectories to match. Code:
ls -d ./*/*/ Which leads me to the big question...what do you need this for? If you tell us what your true goal is, it may be that there's a better solution. |
Thanks that's what I wanted
|
All times are GMT -5. The time now is 06:15 PM. |