LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   chmod not working (https://www.linuxquestions.org/questions/linux-newbie-8/chmod-not-working-4175553773/)

carter38 09-17-2015 12:03 PM

chmod not working
 
With Raspberry Pi standard Debian distro, I cannot get chmod to grant execution permission to C files compiled with gcc that do not have the ".exe" extension. I run chmod as the owner (pi) in a directory owned by me (pi).

If I compile the C file with the ".exe" extension, the execution permission miraculously applies without my use of chmod.

How can I make chmod work without the ".exe" extension?

rtmistler 09-17-2015 01:01 PM

How about some further details:
Code:

$ ls -l <executable-file-name>
Outcome if you did something like:
Code:

$ chmod +x <executable-file-name>
Or rather how about you post the particular form of the chmod command you are using.

When you say it won't grant, are you sure? For instance, if the local path is not in your $PATH variable, that being either the path as fully defined or ".", then trying to run an executable even locally may not work or be auto-recognized. An example of when you try to run it and what happens would be helpful too. You should be able to just do:
Code:

$ ./<executable-file-name>

norobro 09-17-2015 01:02 PM

Would you share with us your chmod command and the command you use to compile the source file?

The compiler should output an executable file. From man gcc:
Code:

-o file
Place output in file file. This applies regardless to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.
If -o is not specified, the default is to put an executable file in a.out, the object file for source.suffix in source.o, its assembler file in source.s, a precompiled header file in source.suffix.gch, and all preprocessed C source on standard output.


HMW 09-17-2015 01:30 PM

Quote:

Originally Posted by norobro (Post 5421788)
The compiler should output an executable file

^True.

Check this out:
Code:

$ cat test.c
#include <stdio.h>

int main()
{
    printf("Hello LQ!\n");
    return 0;
}

Code:

$ ls -lr | head -2
totalt 12
-rw-r--r-- 1 HMW HMW  75 sep 17 20:19 test.c

Code:

$ gcc -o test test.c
Code:

$ ls -lr | head -3
totalt 20
-rw-r--r-- 1 HMW HMW  75 sep 17 20:19 test.c
-rwxr-xr-x 1 HMW HMW 4928 sep 17 20:26 test

Code:

$ ./test
Hello LQ!

No .exe applied and as you can see the executable bit is set by gcc.

Best regards,
HMW

jpollard 09-17-2015 05:00 PM

Quote:

Originally Posted by carter38 (Post 5421768)
With Raspberry Pi standard Debian distro, I cannot get chmod to grant execution permission to C files compiled with gcc that do not have the ".exe" extension. I run chmod as the owner (pi) in a directory owned by me (pi).

If I compile the C file with the ".exe" extension, the execution permission miraculously applies without my use of chmod.

How can I make chmod work without the ".exe" extension?

Show your command.

I bet what you did was use the -c option which saves an object file - not an executable.

Executables don't need a ".exe" extension. Executable is determined strictly by the access control bit.

carter38 09-25-2015 12:46 PM

chmod not working
 
The problem turned out to be the vfat file format on the USB drive I was using. Format vfat does not respond to chmod execution permission changes. I switched over to the ext4 formatted SD card on my Raspberry Pi and all works well. Thanks to all who helped this newbie.

jpollard 09-26-2015 05:08 AM

Quote:

Originally Posted by carter38 (Post 5425621)
The problem turned out to be the vfat file format on the USB drive I was using. Format vfat does not respond to chmod execution permission changes. I switched over to the ext4 formatted SD card on my Raspberry Pi and all works well. Thanks to all who helped this newbie.

The only vfat requirement is for the boot partition (which sucks) and that is dictated by the manufacturer of the CPU. Root (nor any of the other filesystems) ever used vfat.


All times are GMT -5. The time now is 12:26 AM.