Results 1 to 15 of 15
  1. #1
    Niwrad
    Guest
    Shell script question
    Is there a shell script or command that will list out the permissions for every directory from a file's path?

    e.g: If we wanted to run the script on ~/dir1/dir2/dir3/file, the desirable output would be something like:

    drwxrwxr-t 333 root admin 333 Jun 3 13:33 Users
    drwxr-xr-x 33 $shortname $shortname 333 Jun 3 13:33 $shortname
    drwxr-xr-x 3 $shortname $shortname 333 May 3 13:33 dir1
    drwxr-xr-x 3 $shortname $shortname 333 May 3 13:33 dir2
    drwxr-xr-x 3 $shortname $shortname 333 May 3 13:33 dir3
    -rwxr-xr-x 3 $shortname $shortname 333 May 3 13:33 file

  2. #2
    Shell script question
    MacAddikt's Avatar
    Member Since
    Dec 30, 2002
    Location
    Sunny So Cal
    Posts
    2,118
    Specs:
    G52x1.81.53208x+/-
    ls -la

  3. #3
    Shell script question
    rman's Avatar
    Member Since
    Dec 24, 2002
    Location
    Los Angeles, California
    Posts
    12,584
    Specs:
    2 x 3.0GHz Quad-Core, 6GB OS X 10.6.8 | 15in MacBook Pro 2.2GHz OS X 10.6.8 | 64GB iPad 2 WiFi
    Cool
    ls -al will give you a long list of what you have in the current directory, including the dot files (hidden files).
    Life isn't about waiting for the storm to pass, It's about learning to dance in the rain!

  4. #4
    Shell script question
    rman's Avatar
    Member Since
    Dec 24, 2002
    Location
    Los Angeles, California
    Posts
    12,584
    Specs:
    2 x 3.0GHz Quad-Core, 6GB OS X 10.6.8 | 15in MacBook Pro 2.2GHz OS X 10.6.8 | 64GB iPad 2 WiFi
    Cool
    Another question occurs to me. Do you mean only the top most directories/folders in the current directory/folder or all of the directories/folders downward in the current directory/folder? Looking at your example, it appears staright forward, just want to be sure.
    Life isn't about waiting for the storm to pass, It's about learning to dance in the rain!

  5. #5
    Niwrad
    Guest
    What I'm interested in is not the files in a directory, but the files that compose the absolute path of the directory. One possible use for such a script would be to identify permission problems when troubles arise in opening a file. The script should show ONLY the file itself and its super-directories along with their "ls -l" info.

  6. #6
    Shell script question
    rman's Avatar
    Member Since
    Dec 24, 2002
    Location
    Los Angeles, California
    Posts
    12,584
    Specs:
    2 x 3.0GHz Quad-Core, 6GB OS X 10.6.8 | 15in MacBook Pro 2.2GHz OS X 10.6.8 | 64GB iPad 2 WiFi
    Cool
    Here is my understanding of what you want. You want to parse a string of directories, down to the file. At each directory level you want the file permissions of that directory. So if a file was located in the following path (i.e. /export/home/niward/direct1/direct2/file). So you would the permission of the export directory, followed by the home directory, and the niward, etc. Is this what you mean?
    Life isn't about waiting for the storm to pass, It's about learning to dance in the rain!

  7. #7
    Niwrad
    Guest
    Exactly....Any ideas?

  8. #8
    Shell script question
    rman's Avatar
    Member Since
    Dec 24, 2002
    Location
    Los Angeles, California
    Posts
    12,584
    Specs:
    2 x 3.0GHz Quad-Core, 6GB OS X 10.6.8 | 15in MacBook Pro 2.2GHz OS X 10.6.8 | 64GB iPad 2 WiFi
    Cool
    I believe that a perl script can handle that job easier. I have a little understanding of perl. It would take some time and a little work to create a shell script.

    What is it that you are trying to do? Maybe there is another solution to your problem.
    Life isn't about waiting for the storm to pass, It's about learning to dance in the rain!

  9. #9
    Niwrad
    Guest
    Is there any way to use a loop that will start from the top directory and work its way through the path? I think I could get this script to work if I knew how to make the list command treat a directory like a file when listing, i.e. when given a directory argument, the ls -l command would list the directory information as opposed to the information of its contents. Does anyone know of a command on Darwin that allows you to simply get a directory's info (in long format)?

  10. #10
    Shell script question
    rman's Avatar
    Member Since
    Dec 24, 2002
    Location
    Los Angeles, California
    Posts
    12,584
    Specs:
    2 x 3.0GHz Quad-Core, 6GB OS X 10.6.8 | 15in MacBook Pro 2.2GHz OS X 10.6.8 | 64GB iPad 2 WiFi
    Cool
    Use ls -ld to only list the directory and not its contents.
    Life isn't about waiting for the storm to pass, It's about learning to dance in the rain!

  11. #11
    Niwrad
    Guest
    Awesome. Thanks again, I'll see what I can do.

  12. #12
    Niwrad
    Guest
    So basically if we want the whole path we need a script that executes something like the following series of commands:

    For "/export/home/niward/direct1/direct2/file"

    ls -l file > file_info
    ls -ld >> file_info
    cd ..
    ls -ld >> file_info
    cd ..
    ls -ld >> file_info
    cd ..
    etc..........

    This loop seems like it might work, and you can run the loop until[ -e ../ ] is false. Will it work?

    I know how to do loop "checks", but don't know how to loop a command yet, anyone know how to do this? If so, what is the general form?

  13. #13
    Niwrad
    Guest
    Here is my attempt at solving the problem using a loop. It creates the "$file info" file, but only contain the file and its parent. What am I doing wrong?

    1 #!/bin/sh
    2 # This script creates a file listing the permissions that affect the acc essability of a file.
    3
    4 file="$1"
    5
    6 ls -ld $file > "$file info"
    7
    8 if [ -e ../ ] ; then
    9 ls -ld >> "$file info"
    10
    11 while [ -e ../ ] ; do
    12 cd ..
    13
    14 done
    15 fi

  14. #14
    Shell script question
    rman's Avatar
    Member Since
    Dec 24, 2002
    Location
    Los Angeles, California
    Posts
    12,584
    Specs:
    2 x 3.0GHz Quad-Core, 6GB OS X 10.6.8 | 15in MacBook Pro 2.2GHz OS X 10.6.8 | 64GB iPad 2 WiFi
    Cool
    There is a better way. Before I go farther, how many times are you going to run this script that you are trying to create?

    You can move to the directory you want and then parse the path string. That is why perl would be a better solution.
    Life isn't about waiting for the storm to pass, It's about learning to dance in the rain!

  15. #15
    Niwrad
    Guest
    I haven't learned Perl yet (it's on my to-do list this summer), but have heard that it is a great tool to have in your box. Right now I'm just focusing on getting comfortable with my OS. Such a script would in application be actually quite useful, but I'm more interested in the process of solving the problems using shell script so I can become more familiar with them and there basic forms.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Intro & Shell Script Question
    By verynew2macs in forum OS X - Development and Darwin
    Replies: 1
    Last Post: 08-31-2012, 11:14 AM
  2. Quick question regarding a shell script
    By Seventh in forum OS X - Operating System
    Replies: 1
    Last Post: 03-27-2012, 08:25 PM
  3. Shell script help
    By Hyper in forum OS X - Development and Darwin
    Replies: 12
    Last Post: 05-22-2011, 11:36 AM
  4. Terminal -- shell script -- script will only read two lines of a file
    By Straitsfan in forum OS X - Apps and Games
    Replies: 0
    Last Post: 01-30-2011, 09:04 PM
  5. Shell Script on Desktop
    By starrin in forum OS X - Operating System
    Replies: 2
    Last Post: 07-28-2004, 11:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •