Solved

-bash: Permission Denied

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

914 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