BeginnerLesson 3 of 5 · 1 min read
Creating and Manipulating Files
touch, mkdir, cp, mv, rm - the core file operations.
In this lesson you'll learn the everyday verbs for working with files and directories.
Make
mkdir projects # create a directory
mkdir -p a/b/c # create nested directories (-p = parents)
touch notes.txt # create an empty file (or update timestamp)
Inspect
cat notes.txt # print file contents
less notes.txt # page through a file (q to quit)
head -n 5 notes.txt # first 5 lines
wc -l notes.txt # count lines
Move / copy / delete
cp notes.txt copy.txt # copy
mv notes.txt renamed.txt # rename / move
rm renamed.txt # delete a file
rm -r projects # delete a directory recursively
Warning:
rmis permanent. There is no recycle bin. Triple-check before runningrm -rf /.
Edit
You'll often edit files straight from the terminal:
nano notes.txt- beginner-friendly editorvim notes.txt- powerful but steep learning curve
Your notes
Notes are kept on this browser only.
Challenge
Create a new directory called `lab` and then create an empty file `lab/notes.txt` inside it. Do it in two commands.
Need a nudge?
Tip: type the command in the sandbox on the right, or paste the solution here. The sandbox runs in real time.
Quiz
Answer these to lock in the concepts. Score at least 80% to mark the lesson complete.
Mark as complete
Skipped the challenge? You can mark this lesson done by hand.