GeekInterview.com
Series: Subject: Topic:
Question: 49 of 55

How do u open a read only file in Unix?

Asked by: Interview Candidate | Asked on: Jul 5th, 2005
Showing Answers 1 - 14 of 14 Answers
Rakesh Gautam

Answered On : Jul 5th, 2005

vi filename  
e.g vi abc.txt but you cannot write to it 
 
easy way if file is small  
cat filename and contents is display on screen 

  
Login to rate this answer.
Ramakrishna Choudarapu

Answered On : Nov 4th, 2005

view is a better option. It will not allow writing to a file normally, unless done forcefully like "wq!" or "x!"...

  
Login to rate this answer.
kiranck007

Answered On : Jan 30th, 2006

View all answers by kiranck007

"vi -R filename"

Yes  1 User has rated as useful.
  
Login to rate this answer.
Anuradha

Answered On : Aug 30th, 2006

In a shell script, you can open a file in read only mode by using O_RDONLY

Syntax - open(,O_RDONLY)

 

  
Login to rate this answer.
sandhiya

Answered On : Oct 17th, 2006

more is the best option.

  
Login to rate this answer.
cmanne

Answered On : Mar 25th, 2007

View all answers by cmanne

more
cat
less

  
Login to rate this answer.
rajugowda

Answered On : Jun 18th, 2007

To Open read only file in Unix

Vi

or Cat

The Question is not clearly being told that which file should open, means - already created file or newly creating file.

  
Login to rate this answer.
UncaAlby

Answered On : Nov 7th, 2008

View all answers by UncaAlby

If you mean open a file in Unix which has read-only permission

... then you open it the same way you open any other file.  The system will simply prevent you from writing to it.

If you mean open a file in Unix such that you can not write to the file, even though you otherwise would be allowed because you do have write permission ...

... then it depends on what mechanism you use to open the file.  Others have already answered for opening with the "vi" editor.  Other programs, such as "emacs", or other text editors, would have other ways.

  
Login to rate this answer.
abrenar

Answered On : Nov 4th, 2009

View all answers by abrenar

The best way is to open a read only file. use SUDO, because you do not know what or who is the owner of the file in this scenario.

  
Login to rate this answer.
Raj

Answered On : Jun 14th, 2012

The answer to your question depends on what type of file you want to read and what you what to do with the file after reading it.

  
Login to rate this answer.
Sudhir

Answered On : Sep 22nd, 2012

less filename

  
Login to rate this answer.
tushar makkar

Answered On : Sep 24th, 2012

suppose the name of read only file is t.txt
chmod u+rw t.txt
gedit t.txt

  
Login to rate this answer.
SaintHax

Answered On : Oct 4th, 2012

Anything that opens a file, can open a read only file: cat, more, less, awk, pg, et all. The chmod command you put does not make a file read only, it makes it read/write for the user/owner.

  
Login to rate this answer.
Nice Thomas

Answered On : Jan 2nd, 2013

Using vi editor. Read only files can be opened without any issues

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.