Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Whenever I create or copy few shell files to usb storage device, then I am not able to make them executable.

If I create test.sh, it's default file permission will be 644, but when I execute

chmod 777 test.sh

no error reports and echo $? also returns "0". But still ls -l shows permission as 644 and I can not execute it as ./test.sh

share|improve this question
1  
Check your mount flags you are probably using the noexec mount option. –  Ulrich Dangel Jun 25 '12 at 6:47
add comment

2 Answers 2

up vote 9 down vote accepted

Yes, this can occur if your device is formatted with a filesystem that does not support that kind of permission setting, such as VFAT. In those cases, the umask is made up on the fly from a setting in the fstab (or the hotplugging equivalent).

See, most probably, man mount for details. For example, for VFAT, we find:

Mount options for fat

uid=value and gid=value

Set the owner and group of all files. (Default: the uid and gid of the current process.)

umask=value

Set the umask (the bitmask of the permissions that are not present). The default is the umask of the current process. The value is given in octal.

etc.

share|improve this answer
add comment

It looks like your filesystem is mounted with the noexec option, which forbids executing programs on that filesystem by acting as if all execution bits in permissions were unset. If you use the user mount option (or if some user interface uses it under the hood), noexec is turned on unless you explicitly turn it off with exec.

Most USB sticks use the MSDOS-derived VFAT filesystem, which has no notion of permissions. You can only specify permission bits when you mount the filesystem, and these permissions apply to all the files on that filesystem.

If you don't have permission to execute a script, call the interpreter explicitly:

sh /media/stick/test.sh

For a dynamically linked binary, invoke the dynamic linker.

/lib/ld-linux.so.2 /media/stick/myprog
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.