This is an old revision of the document!
We can make a new directory using the command
mkdir (MaKe DIRectory):
mkdir <newdirectoryname> …
Quick Tip: The … means that you can add either one or more newdirectorynames.
Exercise: Let's make a new directory called “mynewdir”:
$ mkdir mynewdir $ ls
We can remove empty directories using
rmdir (ReMove DIRectory):
rmdir <directoryname> …
Exercise: Let's remove the “mynewdir” directory:
$ ls $ rmdir mynewdir $ ls
mkdirto make that directory.
mkdirseparated by spaces:
mkdir dir1 dir2 dir3
mkdircommand, make the directories “01_Notes”, “02_Exercises”, “03_Assignments”.
lsto see the subdirectories.
Files are documents that live within directories. All files in the Linux environment should follow some naming standards…
There are many ways to make a new file. We'll cover just a few:
We can make a new file with touch:
Exercise: Let's navigate into your directory 01_Notes and make the file
$ touch quick_tips.txt $ ls $ ls -alh $ more quick_tips.txt #peek into the file quick_tips.txt
Well, that's a pretty boring file. Let's add some content to it using the linux text editor called nano. This command will be different than previous commands we've executed. Instead of spitting something out to the screen below the prompt, nano will take us to a little text editor app within the terminal where we can type in some text. To exit out of nano, type CTRL+X. To save, type
Exercise: Let's add content to
quick_tips.txt using nano:
$ nano quick_tips.txt
$ less quick_tips.txt
We can also make new files by skipping touch and just starting up nano directly.
Exercise: Let's make the new file
$ nano common_pitfalls.txt
We will learn other ways to create new files in future lessons, too.
We can remove files using
rm [-i] <filename.txt>
-i is an option for to run
rm interactively. It requests a confirmation to remove. Please get in the habit of using this option.
Common pitfall: THERE IS NO UNDO IN LINUX. Yep, that's right. If you remove a file, it's gone. There's no trash can or recycle bin you can pull that file out of. It is gone-gone.
Quick tip: Always make sure you have a good backup system in place. A good back up system is automatic.
Let's say we don't want the file
$ ls $ rm -i common_pitfalls.txt $ ls
lscommand, you should see the directories “01_Notes”, “02_Exercises”, “03_Assignments”
lessto peek into your new text file.
rm -ito delete your newly made text file.
Quick tip: When using
less to browse a short file, the prompt will return immediately. However, if your file is long, use
spacebar to scroll through the pages and
q to escape back to the prompt.
We can also remove directories AND all their contents using
rm [-ir] <directoryname>
-i because there is the potential for deleting more than you bargained for.
Common pitfall: Until you are at Linux ninja status, please use
-i with all your
rm commands. Please use caution when using
rm. Also, please have a good backup strategy in place as well.