By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,666 Members | 1,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,666 IT Pros & Developers. It's quick & easy.

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

P: 1
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.
Mar 27 '08 #1
Share this Question
Share on Google+
3 Replies

micmast
100+
P: 144
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
Mar 27 '08 #2

Expert 100+
P: 849
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.
Mar 28 '08 #3

prn
Expert 100+
P: 254
prn
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
Apr 9 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.