I am trying to add text to an already existing txt file in a system folder.
When I try sudo nano (or sudo su nano) I get a permission denied error. How can I do that?
I am trying to add text to an already existing txt file in a system folder.
When I try sudo nano (or sudo su nano) I get a permission denied error. How can I do that?
What is the filename, and what is the full command you are typing?
Canāt remember the file name but it shouldnāt change much. Letās call it file.txt. Iām tryin g to change it by using either sudo echo or sudo nano > ctrl-o > ctrl-x.
Iām trying to disable transparent huge pages in this case, but there are other cases where I need the same permission.
Sudo doesnāt automatically allow you to change any file. Read-only files stay read-only, and some editors temporarily add write permission when used as root.
Files that are interfaces to kernel objects can report permission denied if the command youāre trying to write is not possible. So in this case the file path matters a lot.
sudo nano file.txt
should work, but as Dorota said if the file isnāt writable then you wonāt be able to save it.
Something like ls -l file.txt
will print out itās permissions.
To elaborate on that ā¦ if the file that the OP is trying to hack is in /sys
then itās not even a ārealā file system so all bets are off, and a regular text editor may be a bad idea. You may even get the situation that the āfileā is write-only.
So
And sudo echo >...
wonāt work anyway.
For the OP (@vkslputll ), the internet suggests
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
but that might not be right since you havenāt confirmed exactly what you are trying to do - and messing around with systemy things can cause breakage. So care is advised.
Iām getting permission errors doing these:
sudo echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
bash: /sys/kernel/mm/transparent_hugepage/defrag: Permission denied
sudo echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled
bash: /sys/kernel/mm/transparent_hugepage/enabled: Permission denied
Same with sudo nano.
I will try your suggestion soon
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
Yes.
See my previous comment:
And
sudo echo >...
wonāt work anyway.
sudo echo >...
will never work in this situation because the file is opened for output before the sudo
is executed. The file is opened for output in the context of your shell process with only the access that you normally have, not the elevated access that sudo
gives you temporarily.
Thatās why the | sudo tee
hack is needed.
Sorry to necro this topic but now Iām trying to edit
/sys/module/kvm_intel/parameters/preemption_timer
It doesnāt allow me to edit it like the previous one:
echo N | sudo tee /sys/module/kvm_intel/parameters/preemption_timer
(Iām trying to turn off preemption timer from Y to N)
I canāt find docs on it, how did you find that you could write to it?
A guide.
Linux is just a headache. Iām sure bad actors have a million easy ways to manipulate these files (when they have root access) but I have to do hours of research to just change it from āYā to āNā.
Once upon a time, they had to do the same research.
Maybe: https://www.cyberciti.biz/faq/slow-performance-issues-of-openbsd-or-freebsd-kvm-guest-on-linux/
Iām asking what source you had because I suspect youāre trying to do somthing impossible. As I wrote before, kernel objects may not be modifiable at all. ā/sys/ā contains only kernel objects.
Granted, Linux could be more descriptive about errors, but what youāre trying to do is not exactly noob level.
Either way, I can help you only if you cooperate.
Iām not sure but maybe just ls -l /sys/...
for whatever you are trying to change. If the permissions start -r--
then the parameter is read-only. If the permissions start -rw-
then the parameter is read-write. That would be sensible and straightforward.