Making Folders
Making folders means creating new directories inside the practice directory. Mkdir creates a directory, and rm removes one.
Make one directory
Mkdir creates a scratch directory, and ls shows it.
$ mkdir ~/practice/scratch
$ ls ~/practice
$ rmdir ~/practice/scratchMake nested directories
Mkdir -p creates a, b, and c in one line, and tree draws them.
$ mkdir -p ~/practice/a/b/c
$ tree ~/practice/a
$ rm -r ~/practice/aRemove an empty directory
Rmdir removes the empty directory, and ls shows it is gone.
$ mkdir ~/practice/empty
$ rmdir ~/practice/empty
$ ls ~/practiceRemove a full directory
Rm -r removes the directory and all inside it, and ls shows it is gone.
$ mkdir -p ~/practice/old/inner
$ rm -r ~/practice/old
$ ls ~/practiceExample
$ mkdir -p ~/practice/work/inner
$ tree ~/practice/work
$ rm -r ~/practice/work
$ ls ~/practiceKey points
- Use mkdir to create a new directory.
- Use mkdir -p to create a directory and its parents in one line.
- Use rmdir to remove an empty directory.
- Use rm -r to remove a directory and all that sits inside it.
- A directory must be empty before rmdir removes it.
- Rm -r removes a directory without asking, so check the name first.
In this example, four lines make, show, and remove one directory. The first line creates work with inner inside it. The second line draws work. The third line removes work and all inside it. The fourth line lists the practice directory, and work is gone.
Note
Removed directories do not come back, so remove only what you made.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does mkdir -p do?