LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-05-2011, 10:49 PM   #1
Debojit777
LQ Newbie
 
Registered: Apr 2011
Posts: 6

Rep: Reputation: 0
bash: ./a.out: Permission denied ......


i am not able to run my .cpp file which is stored in the media.i am using UBUNTU ....i understand i'll have to change the mode of the directory contents..how do i do that?
 
Old 04-05-2011, 10:59 PM   #2
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
How did you compile your program? What command(s) did you use? The typical syntax for compiling a C/C++ program is:

Code:
gcc -o <executable> <source>
or

Code:
g++ -o <executable> <source>
...for C++. The output executable should have been given execute permissions already. If it hasn't (for whatever reason), try "chmod 755 <executable>". If you want more info on what the "755" part means, try looking at the man page; it has a fairly decent explanation IMO.
 
Old 04-05-2011, 11:35 PM   #3
Debojit777
LQ Newbie
 
Registered: Apr 2011
Posts: 6

Original Poster
Rep: Reputation: 0
i compiled it wid g++ (filename).cpp
no error msgs wre displayed...but wen i tried to run it usin ./a.out an error msg popped up stating "u dont ave permission 2 do so" ...whereaas i was accessing it as d root...so wot do i do 2 chnge d rw mode of d file 2 executable mode...???
 
Old 04-05-2011, 11:42 PM   #4
2ck
Member
 
Registered: Mar 2010
Location: /home/twock
Distribution: Debian
Posts: 70
Blog Entries: 9

Rep: Reputation: 21
Quote:
Originally Posted by Debojit777 View Post
i compiled it wid g++ (filename).cpp
no error msgs wre displayed...but wen i tried to run it usin ./a.out an error msg popped up stating "u dont ave permission 2 do so" ...whereaas i was accessing it as d root...so wot do i do 2 chnge d rw mode of d file 2 executable mode...???
Please use proper English.
 
Old 04-05-2011, 11:48 PM   #5
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
You can check the mode of the file with ls -l a.out.

I usually use chmod 'u+x' a.out. It makes the file executable for myself and root without changing the mode for other users. For convenience you can make yourself a simple script.

Code:
foo$ echo '#! /bin/sh
> chmod u+x "$1"' > cx
foo$ ls -l
total 8
-rw-r--r-- 1 you you 26 2011-04-06 00:43 cx
-rw-r--r-- 1 you you 83 2011-04-06 00:30 source.c
foo$ sh ./cx cx
foo$ ls -l
total 8
-rwxr--r-- 1 you you 26 2011-04-06 00:43 cx
-rw-r--r-- 1 you you 83 2011-04-06 00:30 source.c
foo$
To execute a.out you should do one of the following.
  • Invoke it with a full path specification, such as ./a.out or $HOME/src/a.out.
  • Move a.out to a directory on your path, such as mv -iv a.out $HOME/bin/.
  • Add the directory containing a.out to the path, such as PATH=$PWD:$PATH.
  • Add the current working directory to the path, such as PATH=.:$PATH.

Code:
foo$ cat source.c
#include <stdio.h>

int main(void)
{
   printf("Hello, World!\n");
   return 0;
}

foo$ gcc -Wall source.c
foo$ ./cx a.out
foo$ ls -l
total 16
-rwxr-xr-x 1 you you 6363 2011-04-06 00:47 a.out
-rwxr--r-- 1 you you   26 2011-04-06 00:43 cx
-rw-r--r-- 1 you you   83 2011-04-06 00:30 source.c
foo$ ./a.out
Hello, World!
foo$

Last edited by Telengard; 04-05-2011 at 11:52 PM.
 
Old 04-06-2011, 08:56 AM   #6
Debojit777
LQ Newbie
 
Registered: Apr 2011
Posts: 6

Original Poster
Rep: Reputation: 0
My programme is in the path /media/8A28BD0B28BCF773/TC/BIN...And I am executing the code from BIN directory....Whenever I am executing ./a.out ,I am getting "permission denied".I have tried the above code snippet and also chmod command a number of times.But the mode is not changing.If I give "ls -l a.out" command,I am getting the output as

"-rw------- 1 debojit debojit 27 2011-04-06 19:21 a.out"..

I am a beginner in Linux.Please help whether I am missing something...
 
Old 04-06-2011, 10:43 AM   #7
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
Is chmod failing silently, or is it giving an error message?

I'm beginning to wonder about the permissions and ownership of the directory in question. If the directory is owned by debojit, is writable, and resides on a Linux native filesystem then I'm at a loss to explain why chmod would fail.
 
Old 04-07-2011, 02:07 AM   #8
Debojit777
LQ Newbie
 
Registered: Apr 2011
Posts: 6

Original Poster
Rep: Reputation: 0
ya...u've got dat r8....chmod is failing silently...no error msg aftr d command....but wen i use ls -l a.out...it's givin d mode as rw...

Last edited by Debojit777; 04-07-2011 at 02:08 AM.
 
Old 04-07-2011, 04:14 AM   #9
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by Debojit777
My programme is in the path /media/8A28BD0B28BCF773/TC/BIN
Quote:
Originally Posted by Telengard
I'm beginning to wonder about the permissions and ownership of the directory in question. If the directory is owned by debojit, is writable, and resides on a Linux native filesystem then I'm at a loss to explain why chmod would fail.
This is a good point, and I'm thinking that may actually be part of the issue (if not the issue)...

@Debojit777

What filesystem is the disk/partition mounted at "/media/8A28BD0B28BCF773" formatted with? If it's not a Linux-compatible filesystem like ext3/4 or ReiserFS or the like, this could pose a problem with permissions.

You can check the FS type by using mount.

Last edited by MrCode; 04-07-2011 at 04:16 AM.
 
Old 04-07-2011, 11:06 PM   #10
Debojit777
LQ Newbie
 
Registered: Apr 2011
Posts: 6

Original Poster
Rep: Reputation: 0
r8 again...it's an ntfs file system....i had Windows XP installd in my laptop and it's been jst a few weeks dat i've installed ubuntu on my laptop.
 
Old 04-08-2011, 11:49 AM   #11
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
Quote:
Originally Posted by Debojit777 View Post
it's an ntfs file system
NTFS doesn't really expect to work with Linux permissions. I think that may be the source of your trouble.

I think there are some flags you can pass to mount to make files on that volume executable by default. The downside is that it would probably make all files on that volume executable, and that may not be what you want. I think you may find more help if you share the mountline you are using for this volume.

My advice is to simply move the executable to a Linux native filesystem and apply the desired permissions from there.
 
Old 11-07-2011, 10:03 AM   #12
rakesh.palaparthi
LQ Newbie
 
Registered: Apr 2009
Posts: 22

Rep: Reputation: 0
If You didn't Manually mounted by editing the entries in ?etc/fstab

then the system mounts it with defaults characteristics like noexec-do not execute any files from this partion

so edit the above mentioned file like this

/dev/sda3 /media/Wstuff ntfs auto,user,rw,sync,exec 0 0

that should give the partion files the executable status
 
  


Reply

Tags
chmod, executable, ntfs


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: ./labjava1 : permission denied jrme421 Linux - Laptop and Netbook 2 03-02-2009 12:55 PM
bash: Permission Denied Panagiotis_IOA Slackware 5 11-07-2006 10:25 PM
su: /bin/bash: Permission denied dwarf007 Linux - General 10 01-20-2006 04:32 PM
bash: /etc/profile: Permission denied Kanon Linux - Newbie 4 01-21-2005 08:01 AM
RH7.2 bash: permission denied Korshun Linux - Distributions 3 04-29-2002 10:22 AM


All times are GMT -5. The time now is 02:10 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration