77

As mentioned in the title, Mac OS X doesn't allow me to name files starting with a dot ( . ).

You can’t use a name that begins with a dot “.”, because these names are reserved for the system. Please choose another name.

But, I need an .htaccess file. Or, better, how do I use an htaccess file in Mac OS X without giving it a name starting with a dot?

I am running Mac OS 10.5.8 and XAMPP 1.7.3.

pkamb
  • 33,281
  • 23
  • 160
  • 191
Diego Favero
  • 1,969
  • 2
  • 22
  • 32

8 Answers8

79

As of 2023, the content of this answer is obsolete, as it was originally written in 2011. Please refer to the up-to-date answer below.


You can't do this with the Finder. Open Terminal.app (Applications -> Utilities -> Terminal), and type:

> cd /path/to/directory/containing/htaccess
> mv current_file_name .htaccess

Example (do not take directory names or initial filename literally, of course):

terminal screenshot

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • 5
    Explorer let's you do it by adding a dot at the end of the name, e.g. `.aws.` saves as `.aws` – Mark Toman Oct 01 '18 at 15:42
  • @mtman are you referring to Windows Explorer? That's not so helpful on a Mac `;-)` – Matt Ball Oct 01 '18 at 16:52
  • 1
    Of course. Your mention about Explorer is incorrect. – Mark Toman Oct 01 '18 at 23:17
  • Oh - I see. Thanks! I didn't read my own answer carefully enough to remember that I'd mentioned Windows Explorer 7+ years ago. – Matt Ball Oct 01 '18 at 23:36
  • 5
    It's easier if you just do `command`+`shift`+`.` to toggle hidden files visibility. Once hidden files are visible you can rename them starting with a dot. No need for terminal (see my answer below). – Daniel Reina Jun 14 '22 at 08:01
74

Finder-only Solution. No Terminal Needed

You need to be able to see invisible files first.

In finder press ++. –command + shift + dot– to toggle hidden files visibility.

Then just go to the folder where the file is and you'll see it there. You can now rename the file to start with a . if you want.

To create a new file you'll need the terminal. Do touch .htaccess once the terminal is at the right folder.

Daniel Reina
  • 5,764
  • 1
  • 37
  • 50
62

You can create files that begin with a "." if you can view hidden files.

Enter the following commands to show hidden files:

defaults write com.apple.finder AppleShowAllFiles -bool YES
killall Finder

When you're done enter these commands to hide them again:

defaults write com.apple.finder AppleShowAllFiles -bool NO
killall Finder
RafH
  • 4,504
  • 2
  • 23
  • 23
Arkhaic
  • 731
  • 5
  • 10
11

Use the terminal instead of Finder to rename it. Try mv.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
5

You can add an alias in your startup script file to make the command shorter. Usually this is .bashrc, .bash_login or .profile file in your home directory.

alias ondot='defaults write com.apple.finder AppleShowAllFiles -bool YES; killall Finder'
alias ofdot='defaults write com.apple.finder AppleShowAllFiles -bool NO; killall Finder'

Now you can just type ondot to show hidden files. and ofdot for hiding hidden files

Beaudinn Greve
  • 810
  • 12
  • 17
  • Very cool. Implemented this on El Capitan using the file called `.bash_profile` in my user directory. Also ran into this [article with a bunch of other potential uses of the .bash_profile file](https://natelandau.com/my-mac-osx-bash_profile/). – joelhaus Mar 17 '16 at 19:59
3

This works so far as it goes. But TextEdit automatically added .txt to the end of the filename so I ended up with .htaccess.txt

And files with names starting with . don't show up in folders in Finder. You only see it if you go back into Terminal and use ls -a. And if it can't be seen then it can't be uploaded to an online webserver.

Using Fetch as my FTP client, I found it has a function which enables me to create a simple text file directly on the server. This worked to create .htaccess where I really needed it.

Tony LAw
  • 39
  • 1
  • If you are needing to edit a text file, use a text editor and not a word processor. `emacs`, `vim`, and `nano` are accessible via the command line all come pre-installed on macOS. If you want an editor with a GUI, Sublime Text is a popular choice. [citation needed] – Ashton Wiersdorf Aug 14 '17 at 20:33
2

Since .htaccess files will not be viewable once you change the name with Terminal (without some annoying searching) it is simpler to just drag an empty text file into the directory of choice using FTP and then rename away. Both filename and extensions can be change/removed once inside FTP.

Cybernetic
  • 12,628
  • 16
  • 93
  • 132
  • 1
    This question has nothing to do with FTP. – Jake Wilson Feb 18 '14 at 17:37
  • It’s an htaccess file, which means OP is working with servers. FTP is a valid solution to working with servers and handling files. SO doesn’t demand word parity between question and answer it demands relevance, which I provided. – Cybernetic Oct 02 '18 at 12:55
2

Use Terminal.

  1. Open Terminal.

  2. Change Directory to source folder where you want to create the file

    • cd Desktop
  3. Create the file using touch

    • touch .htaccess
  4. Open the file in any text editor

    • atom .htaccess
Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
Lawrence
  • 29
  • 2