You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

chflags hidden not working on Mojave or Cataline

Hi,


I often use the 'chflags hidden ' Terminal command to hide files, in particular folders – but I've noticed a problem on Mojave and now on Catalina, too.


Though the command will hide a files in a folder, when that folder is copied to a a different disk they reappear.


Does anyone have a solution?


iMac 27", macOS 10.15

Posted on Jan 3, 2020 12:18 PM

Reply
Question marked as Top-ranking reply

Posted on Jan 3, 2020 1:11 PM

That chflags setting is an extended attribute. If you copy that folder/file to another drive, and especially if that drive is not APFS or HFS+, then you risk having that chflags attribute removed in the process.


In the Terminal, there is cp -p, rsync -E, or ditto that will copy and preserve attributes.

5 replies
Question marked as Top-ranking reply

Jan 3, 2020 1:11 PM in response to Kingsley_net

That chflags setting is an extended attribute. If you copy that folder/file to another drive, and especially if that drive is not APFS or HFS+, then you risk having that chflags attribute removed in the process.


In the Terminal, there is cp -p, rsync -E, or ditto that will copy and preserve attributes.

Jan 5, 2020 4:21 AM in response to VikingOSX

Thanks VikingOSX,


I'm not a Terminal user, apart from that command, so I don't understand the method of preserving attributes you mention. Could you elaborate? Or link to a guide? Ie, how to do I combine the 'chflags hidden' command with those to hide files?


As a bit of elaboration, I need to hide the files on a CD that I'm burning, simply to tidy up the look of it.


Thanks again.


Jan 5, 2020 6:19 AM in response to Kingsley_net

I haven't burned CDs in years so uncertain if the burning process will or will not preserve the file attributes on the CD. If you are using the hdiutil command line tool to burn that CD, then it has no protections for extended attributes and they will be stripped — thus hidden (chflags) files will appear on the CD, and there is nothing you can do to fix that. Probably same issue if you are using any other burning utility.

Jan 5, 2020 10:15 AM in response to VikingOSX

Thanks again for your swift response. It's not specifically a CD problem – that's just what the end product is supposed to be. The problem persists whether burning to a CD or simply hiding filenames and then moving the folder they're in to another directory.


I have another Mac running 10.12 Sierra, and on that OS there is no problem at all in hiding files. Very odd!


Could you explain how I'd use "cp -p, rsync -E, or ditto that will copy and preserve attributes" along with the chflags hidden command?

Jan 5, 2020 10:40 AM in response to Kingsley_net

The chflags command would come first on the content that you want to copy to another folder, and the next command would be the copy command with the preserve (-p) flag.


cd ~/Desktop
chflags hidden ./foo.txt
cp -p ./foo.txt ./Test
ls -Ol ./Test/foo.txt


That is the sequence. For illustrative purposes, I ensure that my current directory is the Desktop, where a folder named Test resides. If I omit the -p flag on the copy, then the hidden attribute is dropped when you look for it in the target folder using the last command sequence. I use the "./" notation to tell the shell that the PATH to the file or folder is "right here," in the same directory location.


Same command sequence on Mojave or Catalina.

chflags hidden not working on Mojave or Cataline

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.