Fix Invisible File with Mac Terminal Shell Commands

How to Fix an Invisible File on Mac with Terminal shell commands

If you run across an invisible file error such “The file can’t be replaced because it’s invisible”:

The problem is that the “invisibility bit” is set to hidden for the affected file.
Here’s the simple fix using only your Mac Terminal (unix commands).

Here are the magic commands:

# view existing flags (including hidden) on all files in directory or a single file
$ ls -lO      
$ ls -lO somefile

# toggle (in)visibility
$ chflags [hidden|nohidden] somefile

For example, here’s how I fixed my invisible file which incorrectly had its hidden flag set.

# check the existing flags on file 
$ ls -lO someborkedfile.mp4 
-rw-r--r--@ 1 vlanard  staff  hidden 910416393 Feb 24  2016 someborkedfile.mp4

# Note the word 'hidden' above which indicates the file is invisible.  

# UNSET the hidden flag
$ chflags nohidden someborkedfile.mp4 

# verify it's gone
$ ls -lO someborkedfile.mp4 
-rw-r--r--@ 1 vlanard  staff  - 910416393 Feb 24  2016 someborkedfile.mp4

# informationally, if you wanted to actually SET the hidden flag...
> chflags hidden someborkedfile.mp4 
> ls -lO someborkedfile.mp4 
-rw-r--r--@ 1 vlanard  staff  hidden 910416393 Feb 24  2016 someborkedfile.mp4

Note: This assumes you know that the file should NOT be invisible. Key system files are invisible for a reason, so this fix is only intended to be used with erroneously hidden files.

Valerie Lanard

I am a fitness buff, engineering leader, and wearables lover. This blog originally started as part of my now-defunct fitness video startup, Gigabody. It has evolved to encompass my writing on tech and work culture as well. Find me on a bike, on a hike, in a skort, or near a usb port.

Leave a Reply

Your email address will not be published. Required fields are marked *