Connecting Tech Pros Worldwide Forums | Help | Site Map

New Kid on the blog and Linux too---need help

Newbie
 
Join Date: Mar 2008
Posts: 1
#1: Mar 27 '08
Can somebody help me with a sript to print the parent directory and sub directory name for a given directory. It should not print the file names inside the directories. I want only the directories name.

micmast's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Belgium
Posts: 136
#2: Mar 27 '08

re: New Kid on the blog and Linux too---need help


you might be able to solve this with simple command line tools

all the subdirs
$> ls -lR | grep ^d

parent folder:
$>pwd
then do some cutting
Expert
 
Join Date: Sep 2007
Posts: 856
#3: Mar 28 '08

re: New Kid on the blog and Linux too---need help


To avoid the cutting, you could cd .. before using pwd, as that would give you the exact directory. You'd need to hold the previous directory in a variable so that you could cd back to it, but it would still probably be simpler.
prn's Avatar
prn prn is offline
Expert
 
Join Date: Apr 2007
Location: Muncie, IN
Posts: 237
#4: Apr 9 '08

re: New Kid on the blog and Linux too---need help


Quote:

Originally Posted by Good gal

Can somebody help me with a sript to print the parent directory and sub directory name for a given directory. It should not print the file names inside the directories. I want only the directories name.

I'm a bit suspicious of the phrase "given directory". How is it "given"? My guess (and this may be entirely wrong) is simply that it means you know the name of a specific directory, e.g. /var/log/mail and you want to parse that into its own name "mail" and its parent's path name "/var/log" Is that what this is about?

If so, then check the commands "basename" and "dirname" as in:
Expand|Select|Wrap|Line Numbers
  1. [prn@deimos ~]$ basename /var/log/mail
  2. mail
  3. [prn@deimos ~]$ dirname /var/log/mail
  4. /var/log
If this is not what you're trying to do, please clarify your question.

Best Regards,
Paul
Reply