LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-14-2007, 08:33 PM   #1
rainchild
LQ Newbie
 
Registered: Oct 2006
Location: Cali
Distribution: Suse, fendora
Posts: 6

Rep: Reputation: 0
Changing file permission, How to edit a file?


How do I edit a file thats read only, belonging to root?
(file is) /etc/powersave/cpufreq. Log complains ( CPUFREQ_ENABLED=) should equal no.

It's a Usenet News Message? Strange? ( in Gnome it's a txt file).

Running SUSE 10.1, KDE.

I tried su, /etc/powersave/cpufreq. I get "Permission denied".

New to Linux. Please list exact cmds.

Thanking U in advance.
 
Old 01-14-2007, 09:14 PM   #2
FnordPerfect
Member
 
Registered: Dec 2006
Location: Germany
Distribution: Kubuntu (Feisty Fawn), Debian (SID)
Posts: 127

Rep: Reputation: 15
> It's a Usenet News Message? Strange? ( in Gnome it's a txt file).

Says who?

Since in Unix/Linux programs cannot rely conclusively on the extension of a file to find out its filetype, heuristics are being used to determine the type of data in a file according to its contents.
Sometimes, different heuristics lead to different conclusions.
All configuration files in /etc are formatted in a unique way depending on the program that interprets them, and may for example look similar to Usenet messages.
Strictly spoken, in most cases they are plain ASCII anyway and thus editable with any text editor.

--

Now to your question...
If I read that correctly, maybe you misunderstood the su command?

su changes your identity to that of another user. With no parameter given, to root (the superuser).

After that, you probably typed the name of the file you wanted to edit, by which you're telling the shell to execute it.
And since it is not set executable (= "execution not permitted"), you get this error message.

do this:
* type su
* type in your root password
* now you are root; any command typed henceforth is executed with root priviledges! So, when you now launch a text editors, thus is it.
* edit your file
 
Old 01-14-2007, 09:41 PM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
What permissions does the file have? Do this in a terminal and paste the results:
Code:
ls -l /etc/powersave/cpufreq
Normally you would have to change the permissions (mode) of the file, edit the file, and assuming you want to put it back to the preferred permissions, change the mode back. This would usually mean doing these operations in a terminal. I'm assuming you're using the nano editor here:
Code:
su -
chmod u+w
nano file
chmod u-w
Some editors will allow you to save to read-only files, as long as the user can change the mode. This is a convenience feature of vim for example (using the :w! command).
 
Old 01-14-2007, 10:23 PM   #4
rainchild
LQ Newbie
 
Registered: Oct 2006
Location: Cali
Distribution: Suse, fendora
Posts: 6

Original Poster
Rep: Reputation: 0
Permission is root only. I did this:
su
password
chmod777 /etc/powersave/cpufreq
Then was able to open and edit and save with nano. The "Usenet News Message" file type through me off.

Thanks
 
Old 01-14-2007, 10:49 PM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
That's probably not advisable. 777 means readable, writable and executable by all users on the system! At the most you should have only added write permission for root. Excessive permissions is one of the reasons Windows has been a security minefield in the past (or course, Vista is the most secure OS ever written, so there won't be any more Windows security problems, honest).
 
Old 01-14-2007, 10:52 PM   #6
FnordPerfect
Member
 
Registered: Dec 2006
Location: Germany
Distribution: Kubuntu (Feisty Fawn), Debian (SID)
Posts: 127

Rep: Reputation: 15
> chmod 777 /etc/powersave/cpufreq

Well, you just made that file readable, writable and executable by *absolutely everyone*! Although this of course solved your problem, it is generally a very bad idea, especially for files in /etc !!

If you want to learn the "guts" of Linux, I could explain you what this 777 actually means.
It is quite useful to understand how these octal numeric permission settings work, but in the beginning you should deal with that another way.

You can also change permissions with chmod in a much more intuitive way:

(Hm, it is actually much harder to explain then it is to understand. I hope I can make myself clear...)

What you did by chmod 777 could also be done with chmod ugo+rwx

Every file and directory has a user ownership and a group ownership. It has also permissions associated that define what the owner can do with the file, what the group the file belongs to can do with it, and what *everyone else* that is not the user and does not belong to the group can do with the file.

u means user
g means group
o means other (= everyone else)

Where the + is could also be a -
+ means "add the following permissions"
- means "remove the following permission"

r means readable
w means writable
x means executable

E.g., if you are the owner of a file secret-stuff.txt and do not want any other users of the system (if there are any) to access the file, you would type
chmod og-rwx secret-stuff.txt (Which means "remove read, write and execute permissions for group and others, thus everyone but the owner)

E.g., if you have downloaded or written a shell script named automatic-stuff.sh and want to make it executable by you and its group you would type
chmod ug+x automatic-stuff.sh

You get the idea...

Related commands are chown and chgrp. They're pretty self-explanatory...


cheers

~ fabian

Last edited by FnordPerfect; 01-14-2007 at 10:59 PM.
 
Old 01-14-2007, 11:05 PM   #7
rainchild
LQ Newbie
 
Registered: Oct 2006
Location: Cali
Distribution: Suse, fendora
Posts: 6

Original Poster
Rep: Reputation: 0
I caught that after a reboot and put the file back to it's orignal value chomd 644.
 
Old 01-14-2007, 11:17 PM   #8
rainchild
LQ Newbie
 
Registered: Oct 2006
Location: Cali
Distribution: Suse, fendora
Posts: 6

Original Poster
Rep: Reputation: 0
fabian, I'm taking notes

Thanks
 
Old 01-14-2007, 11:18 PM   #9
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
no, file permissions are generally persistent. There are a few exceptions, for example if your system uses the udev mechanism for generating the /dev/... files, they will be re-generated at boot (I think so anyhow - I'd be pleased to be corrected if that's not accurate).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
change file permission of a mouse device file permanently alexandre_fs Linux - General 5 01-09-2007 07:30 AM
problem changing a file permission permanently alexandre_fs Linux - Newbie 2 11-20-2006 10:22 AM
linux changing file permission a_vall Linux - General 5 04-15-2006 09:48 AM
Changing File Permission in a FTP directory to prevent deleting of files shawnbishop Linux - Software 3 01-10-2006 06:41 AM
change file permissions recursivly without changing permission of directories eNTi Linux - Software 8 10-15-2004 04:37 PM


All times are GMT -5. The time now is 08:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration