How to hide and unhide a file in the Windows command line

Updated: 07/13/2023 by Computer Hope
Windows command line (DOS)

There are two methods of hiding files in MS-DOS or the Windows command line without installing any additional software on the computer.

Hide using the attrib command

The first method uses the attrib command as seen below.

attrib +h c:\autoexec.bat

This command hides your autoexec.bat file so a standard user browsing your hard drive would not be able to see the file. To make the file unhidden, use -h instead of the +h so the line would look like the example below.

attrib -h c:\autoexec.bat

Although the file is hidden, someone could still type edit c:\autoexec.bat and edit the file, or if someone typed attrib it lists all files and their attributes.

  • See our attrib command page for full information on this command and other examples.

Hide using Alt codes

The other method uses Alt codes when creating a directory or renaming it and prevents most using an early version of Windows and MS-DOS from accessing the directory. Below are the steps required for creating a directory with these characters.

  1. Type md (hold down Alt and type 987 while continuing to hold Alt; once typed in let go of Alt and a solid block appears).
  2. Press Enter to create the directory.

To get to this directory, type cd followed by a space, and hold Alt while typing 987 to get the block. When pressing Enter, you would then be able to get in the directory.

Tip

Substitute 987 for the dec (decimal) number of any ASCII character.

Note

Windows 3.x and Windows 95 cannot access these directories, and must be accessed through DOS. However, Windows 98 and later has the capability of opening these directories from within Windows. Therefore, if you are using this method for privacy or security, your procedure could be bypassed.

I can't remember what characters I typed. How do I delete the directory now?

See the ASCII (American Standard Code for Information Interchange) dictionary definition that lists a complete listing of ASCII characters or use the "?" wildcard where the ASCII character is.