• The Forums are now open to new registrations, adverts are also being de-tuned.

Linux Help: Permissions of Parent Directories

Spinal

MB Enthusiast
Joined
Sep 14, 2004
Messages
4,806
Location
between Uxbridge and the Alps
Car
x254, G350, Duster, S320, Mach1, 900ss and a few more
This ones a weird one...

I'm writing a script to check some permissions... that said, the script needs to be written into a GUI-based tool... which is causing a problem or two...

In essence, the script needs to check file permissions, so assuming you're working in root:
\Users\root\

idea is to check all files/directories in the home folder are owned by root and only editable by root... easy:
ls -lar | grep -v "root root"
-> gives us any files not owned by root with group root, and similar commands for the permissions. The GUI tool allows for AND, OR and NOT operators.

Second part I'm having trouble with... need to check that the parent folders are only writable by root...
so, in the example above,
\Users\root
and
\Users\
need to only root writable...
again, not too complex if given a scripting language...

Problem is, I need to write this as a 1-line command... any ideas of of a command that returns all the parent directories?

i.e.
root@~ someCommand .
would return
\Users\root
\Users
\

(which I could then pipe into ls, and in turn into grep... normally, while loop would do the trick...)

M.
 
Last edited:
Problem is, I need to write this as a 1-line command... any ideas of of a command that returns all the parent directories?

i.e.
root@~ someCommand .
would return
\Users\root
\Users
\

Use 'pwd' and split the returned path. This will give you a path - of sorts.

One of the problems you have under Unix/Linux is that there may be more than one path - with hard links.
 
Depending on the shell you are using try `echo $cwd`

And you should be using '/' not '\' as this is used to escape the character.

Try striping out the current top level filesystem from 'df .' and piping it into 'find' with the -exec switch.
 
Alfie pretty much has it (not that I write shell scripts)
Remember that you are returning the owner and group NOT the permissions - i.e. just because a file owner is root, that doesn't mean you automatically have rwx permissions if you are logged in as root.

And last of all remember unix actually works in octal! :)
 
Great, thanks.

Re \ vs / - very true, that was a typo from the dark side :p

Unfortunately, the tool wont let me do recursive things, so using a while/for loop is out.

I've found a workaround though... I wrote a tiny script that does the checks and returns a 0 or a 1... I'm using the fancy £200k tool to call my script and then report on the return condition...

Sigh... I was trying to avoid using additional bits and keep it as kosher as possible :p

M.
 

Users who are viewing this thread

Back
Top Bottom