LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-07-2010, 06:02 PM   #1
cyrilic
LQ Newbie
 
Registered: Jan 2010
Posts: 2

Rep: Reputation: 0
Requesting shell script that only outputs directories that contain subdirectories


Hi.

I'm a linux noob, but I'm learning.

I have a directory that has about 5,000+ folders in it and I'd like to run a script that outputs any directory that contains a subdirectory. This folder is in constant flux so it would help me out.

Thanks!
 
Old 01-07-2010, 06:26 PM   #2
bartonski
Member
 
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 438
Blog Entries: 1

Rep: Reputation: 47
If you are trying to see the sub directories of /home/me/big_directory,

Code:
( cd /home/me/big_directory; find . -type d )

Last edited by bartonski; 01-07-2010 at 06:55 PM. Reason: added code tags.
 
Old 01-07-2010, 07:17 PM   #3
whizje
Member
 
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 213

Rep: Reputation: 56
find . -mindepth 2 -and -maxdepth 2 -and -type d -printf %h'\n' | uniq

. find all files in currrent directory
-mindepth 2 minimal 2 subdirectories
-maxdepth 2 maximal 2 subdirectories
-type d found file must be a directory
-printf %h print leading subdirectory
'\n' carriage return
| uniq pipe to uniq to print the directories with subdirectories ones

this doesn't work with directories with spaces in the name.
 
Old 01-07-2010, 08:49 PM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Location: Philippines
Distribution: Gentoo, Slackware, LFS
Posts: 1,526
Blog Entries: 5

Rep: Reputation: 98
Do you need it to be a script? I bet there are already lots of threads that has discussed this. Did already tried to search the LQ site,.. the web?
 
Old 01-08-2010, 09:26 AM   #5
cyrilic
LQ Newbie
 
Registered: Jan 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by whizje View Post
find . -mindepth 2 -and -maxdepth 2 -and -type d -printf %h'\n' | uniq
Thanks whizje! That's exactly what I needed.

Quote:
Originally Posted by konsolebox View Post
Do you need it to be a script? I bet there are already lots of threads that has discussed this. Did already tried to search the LQ site,.. the web?
I thought it was too complicated for a command. Of course I searched first.
 
  


Reply

Tags
subdirectories


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script to move through directories and run various commands. The_Seraphim Programming 1 10-15-2009 02:13 PM
Shell Script for making directories from a file name vikki Linux - Server 7 06-24-2009 07:18 AM
How to copy one file and to multiple directories using shell script? cebuy Programming 8 03-31-2009 07:04 PM
changing directories in a shell script stocky021 Programming 9 11-04-2007 11:36 AM
Very simple shell script - move files to different directories beley Programming 7 11-02-2006 05:24 AM


All times are GMT -5. The time now is 05:14 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
Open Source Consulting | Domain Registration