Solved

-bash: Permission Denied

Posted on 2011-03-25
4
1,143 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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.:
Suggested Courses

738 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