-bash: Permission Denied

I am running Fedora linux and trying out sort a text file and output it to another text file:

sudo sort 1.txt >2.txt

The sort alone works ok. I and also do this in the user's home directory. However, in other parts of the server, i get:

-bash: 2.txt: Permission denied

This is despite the fact that in the same directory I can create a text file (sudo vim 3.txt) without any problem or complaint about permissions to the folder.
Who is Participating?
pilson66Connect With a Mentor Commented:
You need to create bash srcipt, like:

sort 1.txt >2.txt

Open in new window

set the permissions "chmod ugo+x scriptname"
and run:
sudo scriptname
aseismanAuthor Commented:
That worked. Could you explain why it is necessary?
pilson66Connect With a Mentor Commented:
You trying to redirect the output of sudo, and since you do not have rights to create a file - you get permission denied.
And inside the script you redirect a output of command sort, inside sudo.
aseismanAuthor Commented:
Thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.