LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to stop files moved to Linux from Windows via USB being marked "executable"? (https://www.linuxquestions.org/questions/linux-general-1/how-to-stop-files-moved-to-linux-from-windows-via-usb-being-marked-executable-834746/)

rnturn 09-27-2010 09:56 AM

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?

TIA

--
Rick

AlucardZero 09-27-2010 10:04 AM

What filesystems are in use on all three ends (Linux source, USB stick, Windows destination)?

selfprogrammed 09-28-2010 07:15 PM

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

TobiSGD 09-28-2010 07:29 PM

Quote:

Originally Posted by selfprogrammed (Post 4111973)
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

This will not work correctly if there are folders in a copied folder. If you use the -R option of chmod you can shorten the script to this:
Code:

cp -a $(1) $(2)
chmod -R a-x $(2)


MTK358 09-28-2010 07:32 PM

Quote:

Originally Posted by rnturn (Post 4110373)
Or is it a hopeless problem caused by some dainbread decision made by a Windows developer?

It's because Windows and it's filesystems (NTFS, FAT*) have no concept whatsoever of Unix-style file permissions.


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