How can I permanently unhide all files in a folder?

Solution 1:

@nohillside's answer is correct if the cause is that the unix hidden flag has been set. But there are other potential causes. Here is an answer that should be read in addition to @nohillside's answer.

macOS sets extended file attributes (xattr) on files. These include an attribute com.apple.FinderInfo which is used by Finder. It can be shown with:

xattr -px com.apple.FinderInfo <file> where the <file> is replaced by a file name and extension.

If the xattr is present it is 32 bytes long and displayed in hexadecimal, like this. Here is an example for a file called culinary.docx (it just happens to be on my Desktop):

% xattr -px com.apple.FinderInfo culinary.docx
57 58 42 4E 4D 53 57 44 40 10 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

The bit represented by the 4 in the 9th byte (40) is the hidden or invisible bit.

The format of com.appleFinderInfo can be found in this header file Carbon Headers. Look for kIsInvisible. I will call it the "inVisible" bit.

One method of clearing the inVisible bit is to delete all extended attributes, like this: xattr -c <file> or to do it recursively: xattr -cr <folder>

But this is somewhat drastic and will, for example, remove the kIsAlias bit so that any aliases will no longer work! I am not sure what else.

There is a better method. It requires that you install the Xcode Command Line Tools. If you don't have these, you can install with: xcode-select –-install

You will then have the command GetFileInfo and SetFile (note the capitalisation). Please read the help pages man GetFileInfo and man SetFile. Here is an example:

% GetFileInfo -a culinary.docx
aVbstclinmEdz

The V indicates that the inVisible bit is set. In general the capitals are set bits. We can clear the inVisible with SetFile like this:

% SetFile -a v culinary.docx
% GetFileInfo -a culinary.docx
avbstclinmEdz

Now the inVisible bit is a small v and that indicates that it is not set.

Combine this with a find command and we can clear the inVisible bit for all files and folders in Desktop with:

find ~/Desktop -exec SetFile -a v {} \;

After running that all files and folders will be visible in Finder. You might need to choose another folder and then come back to ~/Desktop.

Solution 2:

cd Desktop
chflags nohidden *

should do the trick for all files on your desktop.

To change all files and directories you can run

chflags -R nohidden $HOME

It may unhide files which have been intentionally hidden by the OS (but this shouldn't cause any harm).

PS: man chflags has all the details.