LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 07-13-2011, 04:26 PM   #1
Drigo
Member
 
Registered: May 2009
Posts: 103

Rep: Reputation: 15
Angry 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
.
.
.
 
Old 07-13-2011, 05:47 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
I don't think you can do that with ls, but you can with find:
Code:
find . -type d -maxdepth 2
--- rod.
 
Old 07-13-2011, 11:19 PM   #3
Drigo
Member
 
Registered: May 2009
Posts: 103

Original Poster
Rep: Reputation: 15
That was my first guess but maxdepth or the depth option dont work .....give me an argument error
 
Old 07-14-2011, 12:03 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
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 ./*/*/
Note though that it's not advisable to parse ls for a script.

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.
 
Old 07-14-2011, 12:56 PM   #5
Drigo
Member
 
Registered: May 2009
Posts: 103

Original Poster
Rep: Reputation: 15
Thanks that's what I wanted

Last edited by Drigo; 07-14-2011 at 02:58 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to show bit-rate on mp3 files from the command line? bgoodr Linux - Software 18 09-26-2009 09:58 AM
Which command line command for updating a folder craig_panama Linux - Software 6 06-28-2009 08:11 PM
ps doesn't show the full command line OlRoy *BSD 2 01-29-2007 09:34 PM
how to run a script on subfolder file in a folder saggi_sam Linux - Newbie 5 07-13-2005 05:04 AM
GRUB show me command line after rebooted darkranger Linux - General 10 09-08-2004 04:13 AM


All times are GMT -5. The time now is 08:46 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration