S
S
Sergey2018-02-09 19:05:37
linux
Sergey, 2018-02-09 19:05:37

Ubuntu weird permissions issue when creating a file?

In Ubuntu 16, I noticed that I can’t write to a file using sudo, for example, I write

[email protected]:~$ sudo ls > 1.txt                                                                                                                                                     
-bash: 1.txt: Permission denied

and if the root then everything is normal
[email protected]:~$ sudo -s                                                                                                                                                                                     
[email protected]:~# ls > 1.txt
[email protected]:~# ls

What needs to be fixed, otherwise it’s not a hunt to log in under the root

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pfg21, 2018-02-09
@Raschen

sudo in this line only applies to ls. After > the rights "are reset" and record goes from the normal user.
Option 1: write the file as root.
sudo ls | sudo tee 1.txt
Option 2: wrap the entire command in the root
command sudo sh -c "ls > 1.txt"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question