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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Good gal
    New Member
    • Mar 2008
    • 1

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

    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
    New Member
    • Mar 2008
    • 144

    #2
    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

    Comment

    • Laharl
      Recognized Expert Contributor
      • Sep 2007
      • 849

      #3
      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.

      Comment

      • prn
        Recognized Expert Contributor
        • Apr 2007
        • 254

        #4
        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:
        Code:
        [prn@deimos ~]$ basename /var/log/mail
        mail
        [prn@deimos ~]$ dirname /var/log/mail
        /var/log
        If this is not what you're trying to do, please clarify your question.

        Best Regards,
        Paul

        Comment

        Working...