Solved

-bash: Permission Denied

Posted on 2011-03-25
4
1,067 Views
Last Modified: 2013-12-05
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.
0
Comment
Question by:aseisman
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
pilson66 earned 500 total points
ID: 35214766
You need to create bash srcipt, like:
 
#!/bin/bash

sort 1.txt >2.txt

Open in new window


set the permissions "chmod ugo+x scriptname"
and run:
sudo scriptname
0
 

Author Comment

by:aseisman
ID: 35215312
That worked. Could you explain why it is necessary?
0
 
LVL 8

Assisted Solution

by:pilson66
pilson66 earned 500 total points
ID: 35215409
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.
0
 

Author Comment

by:aseisman
ID: 35215416
Thank you
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If you use Debian 6 Squeeze and you are tired of looking at the childish graphical GDM login screen that is used by default, here's an easy way to change it. If you've already tried to change it you've probably discovered that none of the old met…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now