Beginner LinuxLesson 4 of 27 1 min read
Creating and Manipulating Files
touch, mkdir, cp, mv, rm - the core file operations.
On this page4 sections
In this lesson you'll learn the everyday verbs for working with files and directories.
Make
bash
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
bash
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
bash
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
Challenge
Create a new directory called lab and then create an empty file lab/notes.txt inside it. Do it in two commands.
Want to experiment first? Try things in the practice terminal (opens in a new tab), then enter the command that solves the task here.
Quiz
Lock in the concepts. Score at least 80% to mark the lesson complete.
Done with this one?
Skipped the challenge? You can mark the lesson complete by hand.
Your notes
Kept on this browser only.