DEV Community

Stack All Flow
Stack All Flow

Posted on • Originally published at stackallflow.com on

How to enter a file or directory with special characters in its name?

cd-commandcommand linefilename

I want to enter the following folder in the terminal:

Milano, Torino (Jan)-Compressed

Enter fullscreen mode Exit fullscreen mode

How should I write the command cd to enter this directory?

Spaces and several other special characters like `,*,),(and?` cause problems when I try to use them in the command line or scripts, e.g.:

`
$ cd space dir
bash: cd: space: No such file or directory

$ cat space file
cat: space: No such file or directory
cat: file: No such file or directory

$ cat (
bash: syntax error near unexpected token `newline'

$ echo content >

^C

$ ls ?
( ) * ?


How do I enter file or directory names that contain special characters in the terminal in general?

#### Accepted Answer

That command is ambiguous because spaces are normally used to separate arguments. cd does not know what you want to do but you have two possibilities to solve it:

Either you “ **mask** ” the spaces (and all other special characters) so that the terminal knows you mean the space as a character and not as a separator:

Enter fullscreen mode Exit fullscreen mode

cd Milano, Torino (Jan)-Compressed


Or you put your folder name or path into **quotes** :

Enter fullscreen mode Exit fullscreen mode

cd "Milano, Torino (Jan)-Compressed"




The post [How to enter a file or directory with special characters in its name?](https://stackallflow.com/ubuntu/how-to-enter-a-file-or-directory-with-special-characters-in-its-name/) appeared first on [Stack All Flow](https://stackallflow.com).
Enter fullscreen mode Exit fullscreen mode

Top comments (0)