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

Valerie Lanard

Valerie Lanard is a software engineer and fitness lover. Once upon a time, exercise was a chore she did to chase the elusive "skinny". Somewhere along the way, it morphed into a source of daily joy, motivation, and strength. Find her on a bike, on a hike, in a skort, or near a usb port. Chances are, she's wearing a gadget and a smile.

Leave a Reply

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