got a basic doubt on cat-file permissions


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers got a basic doubt on cat-file permissions
# 1  
Old 08-10-2007
got a basic doubt on cat-file permissions

Hi all,
Today I was just fooling around with directories and faced this. I create a directory 'testdir' and create a file 'myfile' inside it.
Code:
gandalf@gondor:~$ mkdir testdir
gandalf@gondor:~$ cd testdir
gandalf@gondor:~/testdir$ touch myfile

Then I set the following permissions for the directory.
Code:
gandalf@gondor:~$ chmod 664 testdir

The file inside the directory has 644 permissions.
Code:
gandalf@gondor:~/testdir$ ls -l
total 0
-rw-r--r-- 1 gandalf gandalf 0 2007-08-10 22:17 myfile

Now. I can 'cd' to the directory. I can do a 'ls' on that directory.
Code:
gandalf@gondor:~$ ls testdir
testdir/myfile

Now, if I try a 'cat' on the file, it fails.
Code:
gandalf@gondor:~$ cat testdir/myfile
cat: testdir/myfile: Permission denied

The file has read permissions and the directory too has read permissions. Then why is cat not able to read and display the file? Is it dependent on the implementation of 'cat'? My box is
Code:
gandalf@gondor:~/testdir$ uname -a
Linux gondor 2.6.15-28-386 #1 PREEMPT Wed Jul 18 22:50:32 UTC 2007 i686 GNU/Linux

# 2  
Old 08-10-2007
You don't have execute permissions on the directory which let you use it as part of a path.
# 3  
Old 08-11-2007
Thanks

Thanks for the reply. But does 'cat' move to the directory and then read the file. I was assuming that since 'read' permissions were available for the directory and the file, 'cat' should be able to print it put. How does 'cat' really work then?
# 4  
Old 08-11-2007
It's nothing to do with cat.

If I do "cat file" then all I need is to read the file.

If I do "cat dir/file" then I need to first navigate through dir to get to file.

The execute permission on a directory allows this navigation.
# 5  
Old 08-11-2007
Ok

Ok! got that Porter. Thanks again!!
# 6  
Old 08-22-2007
Check whether the file is readable or not using vi command

vi <filename.extension>

Some time we can't open the file where file insdie the not executable permission dir.


Regards,
Siva.P
Bangalore
# 7  
Old 08-23-2007
MySQL

If you are craeting a file inside a directory then the first thing you have to consider is the permissions of the directory,if the dir has sufficient permissions then only you an can do manipulations on the file.
Its something like this--

You are standing infront of a house,inside the house you ahve so many treasures,but you do not have the door key.

Thanks,
Namish
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Basic doubt in UNIX

Hi, I'm new to this and very much interested to learn unix. Can any one explain me the symbols y we use this is scripting(~ and $). It would be great if some one explain with the eg. Thanks Naveen A (2 Replies)
Discussion started by: Pranaveen
2 Replies

2. UNIX for Dummies Questions & Answers

sed basic doubt

Hi , what is the equivalent of below awk in sed. awk '$1=="ABC"&&$2=="XYZ" {print $0}' infile Thanks, Shruthi (6 Replies)
Discussion started by: shruthidwh
6 Replies

3. Shell Programming and Scripting

shell script basic doubt

hi, I am new script learner, so my basic doubt is , how to store value of any command in a variable example $ ls | wc -l i want to stote the output of this in a variable c. so that i can use c in if else loop. and when do we use " ` " symbol in script.. can anyone also tell for... (5 Replies)
Discussion started by: hi2_t
5 Replies

4. UNIX for Advanced & Expert Users

The best way to skin a cat OR how do I get file system info on the most basic level?

Hi, We have an FTP server (vsftpd) running on Linux, that I've kinda built a "Data Management" system around. I could use some ideas as to the best way to handle/create "triggers" for file notifications. Internal users drag 'n drop files from their Windows boxes to the server via Samba... (2 Replies)
Discussion started by: mph
2 Replies

5. Shell Programming and Scripting

Basic SED doubt

Hi Friends!! I want to add a / at the end of a number. for example i have CQ65758 /, in this case i want to shift that backspace one space to the left so the my result becomes CQ65758/. How can i do that with sed. Thanks Adi (3 Replies)
Discussion started by: asirohi
3 Replies

6. Shell Programming and Scripting

Have a basic 'for i in cat list' - Trying to get i to be set to a name with a space

Hi Have a file called ldap.list: ****** "o=unix forum" o=groups ****** i wrote a basic script that runs: for i in `cat ldap.list` do ldapsearch -h host -p 389 -b $i THE PROBLEM: - It looks like when the for i in cat ldap.list runs, it doesn't seem to care about the " ", it... (2 Replies)
Discussion started by: littlefrog
2 Replies

7. Shell Programming and Scripting

basic cat replace string

trying to exclude hostnames ending in "s" from a host file: # cat hosts ssef ssefd ssefsfff ssefsfs # for x in `cat hosts`; do echo "${x/*s}" ;done ef efd fff # How can I echo/or not echo only 'ssefsfs' ?? thanks (4 Replies)
Discussion started by: prkfriryce
4 Replies

8. Shell Programming and Scripting

Shell scripting basic doubt

Hi, I have a script called sam.sh which consists of a single echo statement like this #/usr/bin/ksh echo "Mani" I changed the mode for the script by giving chmod a+x sam.sh. If I want to execute the scrpt by just giving the name at the command line "sam.sh", what should I necessarily do?... (3 Replies)
Discussion started by: sendhilmani123
3 Replies

9. Shell Programming and Scripting

Certainly basic doubt about IF

On the below "IF" i test if the user have put the first argument. I also would like to test if the user have written a second argument. So, my doubt is: - How can i evaluate 2 conditions on a if statement? How is the OR created? - How can i to verify if the second argument is non... (1 Reply)
Discussion started by: tmxps
1 Replies

10. HP-UX

file permissions doubt

hi, i am working in hp ux 11i. 1). the command "ll" (-- long listing) shows the permissions of the files. i like to know.... the first letter of the permissions (prw------- and sometimes i get -r--r--r--) i like to know the first letter 'p' (i know for directories it will be 'd') ... (2 Replies)
Discussion started by: sekar sundaram
2 Replies
Login or Register to Ask a Question