Solved

-bash: Permission Denied

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

680 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