What's a directory?
Directories are paths in your computer in which files are stored. You might be a lot more familiar with directories than you think!
For example, your desktop is a directory. You oftentimes navigate through directories using your finder app on Mac OS, and I also wrote an article about how to navigate directories using Bash.
Today, we're gonna learn about how to create and delete directories using bash.
"mkdir"
The command "mkdir" stands for "make directory", and is used for... well... making directories.
Let's make our own directory called "hello" on our desktop!
For starters, make sure that you are currently in the desktop directory using "pwd" to print where you currently are in your terminal. It should look like this...
/Users/admin/Desktop
Now, let's create our "hello" directory! Input the following...
mkdir hello
Ta-da! Now you have created your first directory. You can now navigate into that directory in your terminal by using the "cd" command, followed by the directory name. After you cd into our new directory, input pwd and the following will be displayed.
/Users/admin/Desktop/hello
"rmdir"
The "rmdir" command stands for "remove directory" (starting to see a pattern here?). By inputing rmdir followed by the name of a directory, you will permanently delete thqt directory and its contents.
Emphasis on PERMANENTLY, be careful with what you delete using this command. You will NOT be able to recover it.
If you've been following along with this post, you should have a directory on your desktop titled "hello", which we are now going to delete. Be sure that you are in your desktop directory...
/Users/admin/Desktop
And input the following...
rmdir hello
Now that directory has been permanently deleted. Again, please be careful with what you choose to delete using this command, as it will be gone forever.
Boom, Bash!
Now we've learned how to navigate our terminal and create and remove both files and directories. It's about time to get into the meat and potatoes of Bash. See you there!
Leave a Reply