How to stop files moved to Linux from Windows via USB being marked "executable"?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,795
Rep:
How to stop files moved to Linux from Windows via USB being marked "executable"?
Sorry about the long subject line but that pretty much summarizes the problem.
I'm finding this behavior increasingly annoying: When I move files from Windows to Linux using a USB drive, all files are marked as executable. Then double clicking on a ".txt" file gets you the ridiculous dialog box asking whether you want to display the file or execute it. (NOTE: The /etc/fstab entry for the USB mount includes the "noexec" option already and it hasn't helped.) Now that my wife and daughters are moving files back and forth between the two OSs, I'm getting pestered for a solution to this and I haven't been able to track anything down. Yet.
What can one do -- presumably on the Windows side of the transfer -- to prevent these files from being marked executable? Or is it a hopeless problem caused by some dainbread decision made by a Windows developer?
I get the same thing all the time. It happens (in my case) with an ext2 Linux filesystem and a USB stick with a windows format. The windows format filesystem does not have all the bits that the ext2 filesystem does, so when the files are copied the missing attribute bits have to be invented from somewhere.
The copy command supplies them from its defaults.
That is as far as I have got. I usually do a "chmod a-x workdir/* "
after I get irritated enough.
Finding out what the copy command does to supply missing attributes would be difficult. It is likely not paying any attention to where the file comes from or else it presume that no windows file could possiblu be executable on Linux.
Could use dostools to do the file copy, and see if it does better.
Could make a script that does the copy and then removes the execute from all files.
Off the top of my head (which means probably lots of errors):
cp -a $(1) $(2)
if [ -d $(2) ]; then
chmod a-x $(2)/*
else
chmod a-x $(2)
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.