Question about UNIX file rights


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Question about UNIX file rights
# 1  
Old 04-28-2013
Question about UNIX file rights

Hello experts,

i am a Unix beginner and to test the rules of file rights (rwx)
i created the file

/root/testdir/subdir/test.sh

and set the rights of testdir,subdir, test.sh (using chmod) to various configurations in order to get an idea
in which case you need which rights. Test commands were

- ls ('Can i read the directory in certain change-mod configurations?')
- less test.sh ('What are the requirements in terms of rights to be able to read a file?')
- test.sh ('When can i execute a file?')

My question is, when testing unix access rights, is there a difference
between referencing test.sh by

./tests. and /root/testdir/subdir/test.sh?

I know that for the first command, i need to be in the directory, but in terms of
access rights, are these to ways of referencing the file test.sh totally equivalent? In other words, does
'less ./test.sh' always work when 'less /root/testdir/subdir/test.sh' and vice versa?
Or is there a configuration for the rights of testdir and/or subdir where one works, and the other not? Same question with executing.

Thands in advance for your help!
Mike
mike_bn
# 2  
Old 04-28-2013
Quote:
are these to ways of referencing the file test.sh totally equivalent?
For testing file rights, the two ways are totally equivalent.
For running the program, they are not equivalent.
# 3  
Old 04-28-2013
Wow, thanks for the fast reply.
Can you give one short example for the differences when running the program?
(Execpt for that Unix remembers the current directory from where the programm was called, i can't think of any differences, but as i mentioned, i am a beginner)
Thanks!
mike_bn
# 4  
Old 04-28-2013
Quote:
Execpt for that Unix remembers the current directory
from where the programm was called
Yes, that's the point. Smilie Here is a short example of how test.sh behaves differently based on where you are when you enter the command:
Code:
$ cd /tmp
$ cat test.sh
wc file.txt
$ ls
file.txt  test.sh

Code:
$ cd /tmp
$ ./test.sh
19 19 95 file.txt

Code:
$ cd /
$ /tmp/test.sh
wc: file.txt: No such file or directory

Another difference is that if you are in a directory where you do not have write permission (such as root directory), and the script wants to create some files in that directory, it obviously will fail.

Here are two ways to fix the problem:
Code:
$ cat test.sh
cd /tmp
wc file.txt

Code:
$ cat test.sh
wc /tmp/file.txt

# 5  
Old 04-28-2013
Well, my reply to your last post was not accepted and has to be approved by the moderators
first. All i did is thank you for helping me out, so thanks again!
mike_bn
# 6  
Old 04-28-2013
Quote:
'less ./test.sh' always work when
'less /root/testdir/subdir/test.sh' and vice versa?
I failed to mention, from the command line, if one of those "less" commands works, the other will also work. Of course, if the first command with the relative path is in a shell script, there could well be a problem, just like in the example of "test.sh" script.

You're welcome. Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert UNIX rights in a number in a sh script

Hello, i'm trying to write a script sh to convert the rights of a folder or file in a number. Explain: ls -l = rwxrwxrwx so i must display 777. Do you known where i can find so convert script Thanks Use code tags, thanks. (11 Replies)
Discussion started by: steiner
11 Replies

2. Shell Programming and Scripting

Management application user rights on the files in a Unix / Linux

good evening .. I have a plea, who I can help me with a management application user rights on the files in a Unix / Linux I need for college .. .. and not told us no clue .. thank you (1 Reply)
Discussion started by: alex90
1 Replies

3. Solaris

New user question regarding admin rights

I'm trying to install OpenOffice on Solaris 11 but when I click on the setup icon I get an error message telling me that I need to have admin rights. I've tried logging on as SU or ROOT but cannot. I don't see how to grant myself admin rights. How is it done ? I know there are many many... (7 Replies)
Discussion started by: stansaraczewski
7 Replies

4. UNIX for Dummies Questions & Answers

question about unix file system

Hi, The file system unix use a multilevel indexes access to disk, 12 direct blocks, 1 single indirect block, 1 double indirect block, 1 triple indirect block: Assuming a: block = 512 bytes, pointer = 4 byte, and there is a file of 200 blocks, how many disk access is needed to read the block... (1 Reply)
Discussion started by: blob84
1 Replies

5. UNIX for Dummies Questions & Answers

file access rights?

Hi, I want to execute a customised process like rating engine using a shell script from a directory other than the directory where the customizes process is placed. I have tried it in the following way...and faced a issue when shell script is available in directory /dir1/ and customized... (1 Reply)
Discussion started by: vkishore.btw
1 Replies

6. UNIX for Dummies Questions & Answers

Unix access rights

Hi, Is it true that if I am not the root I can not select access permissions to a file that I own so that my friend (who also isn't the root) can access that file? And is it true that the only way to accomplish it is to ask the root to "put" my friend into "my" group? Then I could simply set... (1 Reply)
Discussion started by: rudo
1 Replies

7. SuSE

UNIX - Linux NFS Rights need Help

Hello, I am running a Suse Linux server and I want to set up a NFS Server for a few Unix machines. For the root account at the unix client it works fine but it doesn't work for other users who have no root rights. I've used the no_root_squash and the rw option in the etc/export file. My folder... (7 Replies)
Discussion started by: Ald-Edv
7 Replies

8. UNIX for Dummies Questions & Answers

File Oput question in Unix?

Just curious in Unix BSD lpr customer would result in the printing of the file customers to a printer but I also came across this command pr| customer| lpr which suppose to prepare the file by formatting before printing. My question is what type of formatting is done to the file for example what... (1 Reply)
Discussion started by: wmosley2
1 Replies
Login or Register to Ask a Question