- Published on
Handling file or directory names with spaces
- Authors
- Name
- hwahyeon
When a file or directory name contains spaces, commands that take file paths as arguments (such as pwd
, cd
, or ls
) may not work as expected. For instance, if there is a directory named "hello world", the following commands will result in an error.
cd hello world
ls hello world
This is because the cd
and ls
commands interpret "hello" and "world" as two separate arguments, leading to a command error. To address this, you can use one of the following methods.
- Wrap the path in
single('')
ordouble quotes("")
:
cd 'hello world'
cd "hello world"
- Escape the space with a
backslash(\)
:
cd hello\ world
- Just use
underscores(_)
orhyphens(-)
instead ofspaces
in file or directory names.