0

I copied some files from an external drive and now they appear with a yellow background under my ZSH shell on OSX. I believe that its a permissions thing as the normal ones display "drwxr-xr-x" and the ones with yellow don't have the missing permissions i.e. "drwxrwxrwx"

here is an example

total 24
drwxr-xr-x  21 martin  staff   714B Aug  4 00:10 .
drwxr-xr-x+ 63 martin  staff   2.1K Aug  5 18:50 ..
-rw-r--r--@  1 martin  staff    10K Aug  4 00:24 .DS_Store
drwxrwxrwx   9 martin  staff   306B Jul 31 00:44 Tempa
drwxrwxrwx   5 martin  staff   170B Jul 11 21:31 XCode
drwxrwxrwx   5 martin  staff   170B Jul 11 21:31 Items
drwxr-xr-x  21 martin  staff   714B Jul 31 09:13 code-test
..

I you notice above there are 2 items that display without the yellow background. This is .DS_Store file and code-test directory. Actually its worth noting that inside a directory that has a yellow background i.e. "XCode" I have a load more files and directories which have the same issue.

Why do the copied files have these permissions? What do the missing permissions mean? And of course how to fix it, but of course fix it recursively, as it seems inside each effected directory the files and other directories also have the same issue.

  • Maybe related to unix.stackexchange.com/questions/107371/… – Drav Sloan Aug 5 '15 at 21:47
  • 1
    Did you try to change permission with chmod, I mean remove w bit? Anyway include the output of print -l ${(s.:.)LS_COLORS} | grep -v '*' into your question and also stat Tempa code-test. – jimmij Aug 5 '15 at 22:19
  • I am not too good with chmod, but I believe that will fix it, how do I see remove the permission attributes that is in position 6 and 9 but recursively so that drwxrwrwx will become drwxr-xr-x ? – Martin Aug 6 '15 at 20:33
1

Presumably the external drive uses a filesystem such as a FAT variant which doesn't store permissions, and was mounted with all permissions allowed to everybody. The tool you used to copy files retained the original permissions.

The garish color alerts you that the files are world-writable. In the output of ls -l, the rwx permissions are grouped in three blocks of three characters: user, group and other, in this order. So rwxrwxrwx means that everybody can do everything, whereas rwxr-xr-x means a file that everybody can Read and eXecute but only the user who owns the file can Write. See Understanding UNIX permissions and their attributes for more details about permissions and the output of ls -l.

To change the files to be writable only by you, run the chmod command:

chmod -R go-w .

-R means recursive; go means affect the group and other permissions, and -w means to remove the write permissions.

If you want to remove the execute permission from files because they aren't actually executable, don't just add x to this command. Directories must keep the x permission, because on a directory, x actually means the permission to access files inside that directory (r only allows listing the directory contents, not accessing the files). You can use the find command to run chmod only on non-directories. To remove the execute permission from everything under the current directory except directories:

find . -type d -o -exec chmod a-x {} +
  • Great, worked exacly as you said and thanks for a great explanation! – Martin Aug 7 '15 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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