LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 01-07-2011, 04:24 PM   #16
anhedonia
LQ Newbie
 
Registered: Jan 2011
Posts: 8

Original Poster
Rep: Reputation: 0

Thanks for your help thus far. I am trying a different approach and I trying to get a list of all the sub-directories within my parent directory.

I have this:

DIR=`(find -maxdepth 1 -type d)`
#
echo $DIR

and that gives me an output of

./book1
./book2

Is there a way to get the results without the path, i.e.

book1
book2

thanks again
 
Old 01-07-2011, 05:20 PM   #17
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Code:
DIR=`find -maxdepth 1 -type d -printf "%f\n"`
See man find for the available formats. Another approach might be:
Code:
DIR=`ls -d */`
the slash after the wildcard matches only the directories and the -d option prevent the listing of the directories themselves.
 
1 members found this post helpful.
Old 01-07-2011, 05:24 PM   #18
anhedonia
LQ Newbie
 
Registered: Jan 2011
Posts: 8

Original Poster
Rep: Reputation: 0
find -maxdepth 1 -type d -name '*' ! -name '.*' -printf '%f\n

got me what I need.

thanks again
 
Old 01-07-2011, 05:26 PM   #19
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You're welcome!
 
  


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
find -exec command to recursively delete files and folders in folders with X name Joan Murt Linux - Newbie 2 07-08-2009 05:35 PM
how to run tar wtihout re-create folders canadatom Linux - Newbie 3 06-26-2009 02:47 PM
How to enter graphical mode (run level 5) command line (run lenel 3) edmondgyampoh Linux - Newbie 3 05-15-2009 07:33 PM
command to delete folders on /tmp ceantuco Linux - Newbie 7 01-08-2009 09:10 AM
Is there a command that gives you ownership of a folder and all it's sub-folders royeo Linux - Newbie 3 06-01-2007 02:55 PM


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

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration