Awesome! Here's Part 4 of your Linux series, written in the same natural, engaging, beginner-friendly tone:
🐧 Linux Basics – Part 4: Creating, Moving, and Deleting Files and Folders
Hey hey! 👋
Welcome back to our Linux command line series. If you've been following along, you’re already comfy moving around the filesystem like a champ. Now it’s time to level up with something every user needs to know: how to manage files and folders using simple commands.
In this part, we’ll cover how to create, rename, move, copy, and delete files and directories—all from the terminal. Yep, no mouse-clicking needed! 😄
Let’s get straight to it!
📝 Creating Files – touch
Want to create an empty file? Easy. Use touch
.
Example:
touch hello.txt
This instantly creates an empty file called hello.txt
in your current directory.
💡 Windows comparison: Like right-click → New → Text Document.
📁 Creating Directories – mkdir
Want to make a new folder? Use mkdir
(short for make directory).
Example:
mkdir myfolder
Want to create a folder and a subfolder in one go?
mkdir -p projects/python
The -p
flag tells Linux to create parent folders if they don't exist.
✂️ Moving and Renaming – mv
The mv
command works for both moving and renaming files and directories.
Rename a file:
mv hello.txt greetings.txt
Move a file into a folder:
mv greetings.txt myfolder/
🧠 Pro tip: You can move multiple files at once:
mv file1.txt file2.txt myfolder/
📄 Copying Files – cp
Want to duplicate a file? Use cp
.
Example:
cp hello.txt backup.txt
To copy a file into a folder:
cp hello.txt myfolder/
To copy an entire folder and its contents:
cp -r myfolder newfolder
The -r
stands for recursive, which is required when copying directories.
🗑️ Deleting Files and Folders – rm
Use rm
(remove) to delete stuff. Be careful—there’s no “Recycle Bin” here!
Delete a file:
rm hello.txt
Delete a folder and all its contents:
rm -r myfolder
⚠️ Use this command carefully—especially with
-r
!
🧪** Try This!**
Here's a mini practice session:
- Create a folder named
testlab
. - Inside
testlab
, create two files:one.txt
andtwo.txt
. - Rename
one.txt
tofirst.txt
. - Copy
first.txt
into a folder calledbackup
. - Delete
two.txt
.
Commands you'd use:
mkdir testlab
cd testlab
touch one.txt two.txt
mv one.txt first.txt
mkdir backup
cp first.txt backup/
rm two.txt
Boom 💥—you just did file management like a Linux ninja.
🧭 Quick Reference Table
Task | Command |
---|---|
Create file | touch filename.txt |
Create folder | mkdir foldername |
Rename file/folder | mv oldname newname |
Move file/folder | mv item destination/ |
Copy file | cp file destination/ |
Copy folder | cp -r folder newfolder |
Delete file | rm filename.txt |
Delete folder | rm -r foldername |
🔚 Wrapping Up
That’s a wrap on file and folder management in Linux! 🎉
These are essential commands you’ll use all the time. Practice them a bit and you’ll find yourself zipping through file tasks without ever needing a GUI.
Next up in Part 5, we’ll take a look at viewing and editing file content—using commands like cat
, less
, head
, tail
, and even simple editors like nano
.
Stay tuned, and keep exploring! 🚀
Top comments (0)