Now you can move around and see what's there. Next up: making your own directories. Organizing files into folders is how you keep a Unix system from turning into a messy room.
Make a directory — mkdir
mkdir creates a new, empty directory.
$ mkdir projects
$ ls -l
drwxr-xr-x 2 you you 4096 Jun 15 11:00 projects
You'll see the new directory in your listing. It's empty until you put something in it.
Try it Yourself →Nested directories with mkdir -p
What if you want to create a whole path at once? mkdir projects/website/css would fail if projects and website don't exist yet. The -p flag creates parent directories automatically.
$ mkdir -p projects/website/css
$ ls -R projects
projects:
website
projects/website:
css
ls -R shows directories recursively — handy for seeing the tree structure. The -p flag is a lifesaver. I use it every time I create a nested path.
Remove empty directories — rmdir
rmdir deletes a directory, but only if it's empty. It's the safe way to clean up.
$ rmdir projects/website/css
$ ls projects/website
If the directory has files inside, rmdir will refuse with a message like "Directory not empty." That's its way of saying "are you sure?" — you'd need rm -r for that, which we'll cover later.
Directory naming tips
Stick to lowercase letters, numbers, hyphens, and underscores. Avoid spaces in directory names — if you must use them, you'll need to quote the path or escape each space with a backslash. Most Unix folks just use hyphens or underscores. my-project is way easier to type than my project.