How do u open a read only file in Unix?

Showing Answers 1 - 75 of 83 Answers

Rakesh Gautam

  • 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 

  Was this answer useful?  Yes

Ramakrishna Choudarapu

  • Nov 4th, 2005
 

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

  Was this answer useful?  Yes

Anuradha

  • Aug 30th, 2006
 

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

Syntax - open(<filename>,O_RDONLY)

 

  Was this answer useful?  Yes

sandhiya

  • Oct 17th, 2006
 

more <file_name> is the best option.

  Was this answer useful?  Yes

rajugowda

  • 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.

  Was this answer useful?  Yes

UncaAlby

  • Nov 7th, 2008
 

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.

  Was this answer useful?  Yes

abrenar

  • Nov 4th, 2009
 

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.

  Was this answer useful?  Yes

Raj

  • 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.

  Was this answer useful?  Yes

Sudhir

  • Sep 22nd, 2012
 

less filename

  Was this answer useful?  Yes

tushar makkar

  • Sep 24th, 2012
 

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

  Was this answer useful?  Yes

SaintHax

  • 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.

  Was this answer useful?  Yes

Nice Thomas

  • Jan 2nd, 2013
 

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

  Was this answer useful?  Yes

Amit Singh

  • Dec 2nd, 2014
 

We can open a file without read permission by using view command...

Code
  1. vnjsb

  Was this answer useful?  Yes

Abhisek

  • Dec 22nd, 2014
 

readonly variablename

  Was this answer useful?  Yes

santosh barik

  • Jan 9th, 2015
 

cat

  Was this answer useful?  Yes

Sanjeev

  • Apr 3rd, 2015
 

If file has read permission and need to only open and not modify, one can use any editer/display command

  Was this answer useful?  Yes

Heena

  • Apr 16th, 2015
 

read filename

  Was this answer useful?  Yes

paras

  • May 7th, 2015
 

cat filename

  Was this answer useful?  Yes

John

  • Jun 16th, 2015
 

cat

  Was this answer useful?  Yes

vivek mishra

  • Jul 21st, 2015
 

more file_name

  Was this answer useful?  Yes

Ather Ahmed

  • Nov 9th, 2015
 

vi -R

  Was this answer useful?  Yes

Angel

  • Apr 28th, 2016
 

By using view or cat command

  Was this answer useful?  Yes

pranay

  • May 20th, 2016
 

using cat command

  Was this answer useful?  Yes

UMA

  • May 24th, 2016
 

Using cat command

  Was this answer useful?  Yes

devendra

  • Jul 8th, 2016
 

$ cat file_name

  Was this answer useful?  Yes

neha pawar

  • Jul 30th, 2016
 

cat filename

  Was this answer useful?  Yes

payal

  • Aug 3rd, 2016
 

read filename

  Was this answer useful?  Yes

Akula Uday

  • Nov 23rd, 2016
 

view filename

  Was this answer useful?  Yes

Ravindar

  • Jan 2nd, 2017
 

vi -R filename
This will open the file in read mode in vi editor(which is available in almost all unix version)

  Was this answer useful?  Yes

Give your answer:

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

 

Related Answered Questions

 

Related Open Questions