OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Shell script question


Post Reply New Thread Subscribe

 
Thread Tools
Niwrad
Guest
 
Posts: n/a

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
QUOTE Thanks
MacAddikt

 
MacAddikt's Avatar
 
Member Since: Dec 30, 2002
Location: Sunny So Cal
Posts: 2,118
MacAddikt is a glorious beacon of lightMacAddikt is a glorious beacon of lightMacAddikt is a glorious beacon of lightMacAddikt is a glorious beacon of lightMacAddikt is a glorious beacon of lightMacAddikt is a glorious beacon of light
Mac Specs: G5•2x1.8•1.5•320•8x+/-

MacAddikt is offline
ls -la

QUOTE Thanks
rman
Inactive Staff
 
rman's Avatar
 
Member Since: Dec 24, 2002
Location: Los Angeles, California
Posts: 12,591
rman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud of
Mac 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

rman is offline
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!
QUOTE Thanks
rman
Inactive Staff
 
rman's Avatar
 
Member Since: Dec 24, 2002
Location: Los Angeles, California
Posts: 12,591
rman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud of
Mac 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

rman is offline
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!
QUOTE Thanks
Niwrad
Guest
 
Posts: n/a

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.

Last edited by Niwrad; 06-27-2005 at 08:24 PM.
QUOTE Thanks
rman
Inactive Staff
 
rman's Avatar
 
Member Since: Dec 24, 2002
Location: Los Angeles, California
Posts: 12,591
rman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud of
Mac 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

rman is offline
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!

Last edited by rman; 06-28-2005 at 10:39 AM. Reason: removing the stray h
QUOTE Thanks
Niwrad
Guest
 
Posts: n/a

Exactly....Any ideas?
QUOTE Thanks
rman
Inactive Staff
 
rman's Avatar
 
Member Since: Dec 24, 2002
Location: Los Angeles, California
Posts: 12,591
rman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud of
Mac 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

rman is offline
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!
QUOTE Thanks
Niwrad
Guest
 
Posts: n/a

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)?
QUOTE Thanks
rman
Inactive Staff
 
rman's Avatar
 
Member Since: Dec 24, 2002
Location: Los Angeles, California
Posts: 12,591
rman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud of
Mac 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

rman is offline
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!

Last edited by rman; 06-28-2005 at 01:14 PM. Reason: corecction
QUOTE Thanks
Niwrad
Guest
 
Posts: n/a

Awesome. Thanks again, I'll see what I can do.
QUOTE Thanks
Niwrad
Guest
 
Posts: n/a

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?

Last edited by Niwrad; 06-28-2005 at 02:22 PM.
QUOTE Thanks
Niwrad
Guest
 
Posts: n/a

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
QUOTE Thanks
rman
Inactive Staff
 
rman's Avatar
 
Member Since: Dec 24, 2002
Location: Los Angeles, California
Posts: 12,591
rman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud ofrman has much to be proud of
Mac 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

rman is offline
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!
QUOTE Thanks
Niwrad
Guest
 
Posts: n/a

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.
QUOTE Thanks

Post Reply New Thread Subscribe


« Trying to learn C on Mac | Need help customizing sudo »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Video production question macinsandiego Movies and Video 4 11-17-2004 07:39 AM
Shell Script on Desktop starrin OS X - Operating System 2 07-28-2004 11:25 AM
Postscript question battleangel444 OS X - Operating System 2 07-09-2004 12:45 PM
tsch script - nested loop dynamic variable reference lizardthefish OS X - Development and Darwin 0 03-04-2004 11:53 PM
Writing a script to change browser preferences - Help ysuee OS X - Operating System 0 01-22-2004 06:28 PM

All times are GMT -4. The time now is 12:56 AM.

Powered by vBulletin
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?