tinyapps.org / blog


Lock or unlock files recursively in OS X #

$ chflags -R uchg directory
$ chflags -R nouchg directory
View file flags with the -O (capital "o") switch:
$ ls -lO
-rw-r--r-- 1 user staff uchg 0 Dec 13 07:19 locked_file
-rw-r--r-- 1 user staff -    0 Dec 13 07:19 unlocked_file
(via Entrepreneur Geek and macos-x-server.com)

This tip is particularly useful when copying folders like My Documents, My Pictures, etc from Windows machines to OS X. Rather surprisingly, these folders are actually assigned the Read-only attribute in Windows:
Unlike the Read-only attribute for a file, the Read-only attribute for a folder is typically ignored by Windows, Windows components and accessories, and other programs. For example, you can delete, rename, and change a folder with the Read-only attribute by using Windows Explorer. The Read-only and System attributes is only used by Windows Explorer to determine whether the folder is a special folder, such as a system folder that has its view customized by Windows (for example, My Documents, Favorites, Fonts, Downloaded Program Files), or a folder that you customized by using the Customize tab of the folder's Properties dialog box.

OS X honors the Read-only attribute by dutifully locking the directories, leading to unexpected and generally undesirable results.

UPDATE: OS X also hides (in the Finder) files and folders that were hidden in Windows (Local Settings, AppData, etc). chflags can be used to unhide these as well:

$ chflags -R nohidden directory
Rehide:
$ chflags -R hidden directory

/mac | Dec 13, 2009


Subscribe or visit the archives