Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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?
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.
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...???
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...???
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$
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
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.