Results 1 to 10 of 10

Thread: Open file in GEDIT as READ-ONLY

  1. #1
    Join Date
    Mar 2009
    Beans
    7

    Open file in GEDIT as READ-ONLY

    How can I open a file in GEDIT as READ-ONLY

    I want to open it, see it but I DONT WANT TO MAKE ANY INVOLUNTARY CHANGES in it.

    Thank you in advance

  2. #2
    Join Date
    Oct 2010
    Location
    London
    Beans
    482
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Open file in GEDIT as READ-ONLY

    I don't know how to do exactly what you describe (or why you'd want that - surely just don't make any changes, and don't save it if you do accidentally make changes?), but if this is just a specific file, have you tried just changing the file permissions? GUI-wise, right-click on the file and open 'Properties', then go to the 'permissions' tab and set all the options to 'read-only'.

    Via terminal, the command to change permissions like that would be:
    chmod 444 filename
    or if you want to be able to execute it:
    chmod 555 filename

    I hope that helps...

  3. #3
    Join Date
    Feb 2012
    Beans
    2

    Re: Open file in GEDIT as READ-ONLY

    A bash shell script to open the file read-only and then reset the permissions after opening the file:

    #!/bin/bash
    #bash shell script
    #Written by LightRust
    perm=`stat -c%a $1`
    chmod ugo-w-x $1
    gedit $1 &
    sleep 5
    chmod $perm $1

    Cludgy at best but it does work...


  4. #4
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    Re: Open file in GEDIT as READ-ONLY

    LightRust's script will do it.

    But there are also other alternatives. For example, you can use the lightweight 'terminal windows viewer' less. See
    Code:
    man less

  5. #5
    Join Date
    Feb 2012
    Beans
    2

    Re: Open file in GEDIT as READ-ONLY

    True but try printing with context highlighting from 'less'...

    In this case... less is... just less

  6. #6
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    Re: Open file in GEDIT as READ-ONLY

    Quote Originally Posted by LightRust View Post
    True but try printing with context highlighting from 'less'...

    In this case... less is... just less
    I agree that highlighting is very valuable.

    But it is always nice to have alternatives. Less is also good because you can pipe to it, for example to view your hardware
    Code:
    gksudo lshw | less
    navigate with the normal keys and quit with q.

  7. #7
    Join Date
    Jan 2009
    Beans
    261
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Open file in GEDIT as READ-ONLY

    In post#3, in bash script
    What does this line do?
    Code:
    sleep 5

  8. #8
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Open file in GEDIT as READ-ONLY

    wait/sleep 5 seconds
    gedit is run in the background with the file changed to readonly and sleep 5 gives it some time to access the file before restoring its original permissions.

    quote $1 if you don't want problems with spaces ("$1")

  9. #9
    Join Date
    Jan 2010
    Location
    Sydney, Australia
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Open file in GEDIT as READ-ONLY

    When i have to open a file in read only mode , i often use view .
    View starts vim in read-only mode. You will be protected from writing the files.
    “Progress is made by lazy men looking for easier ways to do things”
    — Robert A. Heinlein

  10. #10
    Join Date
    Jul 2012
    Beans
    1

    Re: Open file in GEDIT as READ-ONLY

    Well, I am not using Ubuntu, but what I am doing is:

    1) I open 2 gedit instances.
    2) In one of them, I open the desired file. It gets open as Write-enabled.
    3) Then I switch to the other gedit instance, and open the same desired file. Then a pop-up appears asking if you want to open it as writtable or as read-only.
    4) Select the read-only option.
    5) Go to the first gedit instance, and close the write-enabled one.

    You got in the second instance of gedit the file open as read-only.

    Usually, when I need to open one file read-only is to edit another similar one in the other gedit instance, so I can read both instances, and edit only in the selected one.

    It is a pain to do my suggested way, but at least it works on Fedora, so I guess it will work in any other Linux distribution, as this seems not distribution-dependent.

    I was researching (googling) for a new (better for me) way to do that. Will continue looking for

    It would be nice if gedit incorporates in the Edit menu an open option to toggle edit/read-only the current working file.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •