Understanding Linux Directory Basics
Before we dive into creating directories with spaces, it is important to understand how Linux handles directories and file paths.
In Linux, everything is organized in a hierarchical directory structure starting from the root directory, represented by a forward slash /
. Your user's home directory is typically located at /home/username
- in our case, /home/labex
.
Let us start by exploring our current directory. Open your terminal and run:
pwd
This command shows your present working directory. You should see:
/home/labex/project
Next, let us see what files and directories are in our current location:
ls
You might see various files or directories, or the directory might be empty if no files have been created yet.
Now, let us try to create a simple directory using the mkdir
(make directory) command:
mkdir TestDirectory
To verify that the directory was created, run the list command again:
ls
You should now see TestDirectory
in the output.
Linux allows you to use various characters in directory names, including spaces. However, spaces in directory names require special handling because the shell (command-line interpreter) uses spaces to separate command arguments. Without proper handling, spaces in directory names can cause confusion for the shell.
For example, if we try to create a directory named "My Documents" without any special handling:
mkdir My Documents
The shell interprets this as two separate arguments: "My" and "Documents", and creates two separate directories instead of one. Let us verify this:
ls
You will see both My
and Documents
listed as separate directories, which is not what we intended.