Solved

-bash: Permission Denied

Posted on 2011-03-25
4
1,097 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

815 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

8 Experts available now in Live!

Get 1:1 Help Now