Naming Files in the Terminal

When you create your files and directory, you can name them pretty much anything you’d like.

However, there are some symbols that will get you into trouble.

Take the humble space.
If you tried to name your a file “hello world” without the quotes, then you might be surprised that you ended up with two files, rather than one.

touch hello world

The reason for this, is that the shell sees the space as a separator.

If you really want a space in your filename, then there are two ways to get around this.

The first way, is to quote your filename.

touch "hello world"

The second way, is escape the problem character using the backslash symbol.

touch hello\ world

Symbols that require you to either escape them or quote them are:

$Start of a variable
|Vertical bar or pipe symbol
?Question mark
( )Brackets
[ ]Square brackets
{ }Braces
Symbols that require escaping

However, there are some symbols that you will struggle to create a file with on the terminal.

For example, the asterisk (*).  Finder will allow you to use the asterisk as a filename.  Once the file has been created, then you can escape the asterisk or quote it, so that you can access it.

Interestingly, you can also escape the carriage return, but it gets substituted with a space, but it works well for breaking up long commands.

echo String \  
> broken \
> by \
> carriage \
> returns

String broken by carriage returns


Whilst building web applications, Daniel also sets up web servers from scratch because he has yet to find the perfect hosting solution. His philosophy is “Why settle, when you can build it better yourself?”

Recent Posts