DEV Community

Cover image for 🐧 Linux Basics – Part 4: Creating, Moving, and Deleting Files and Folders
Alkesh Baghel
Alkesh Baghel

Posted on

🐧 Linux Basics – Part 4: Creating, Moving, and Deleting Files and Folders

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Want to create a folder and a subfolder in one go?

mkdir -p projects/python
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Move a file into a folder:

mv greetings.txt myfolder/
Enter fullscreen mode Exit fullscreen mode

🧠 Pro tip: You can move multiple files at once:

mv file1.txt file2.txt myfolder/
Enter fullscreen mode Exit fullscreen mode

📄 Copying Files – cp

Want to duplicate a file? Use cp.

Example:

cp hello.txt backup.txt
Enter fullscreen mode Exit fullscreen mode

To copy a file into a folder:

cp hello.txt myfolder/
Enter fullscreen mode Exit fullscreen mode

To copy an entire folder and its contents:

cp -r myfolder newfolder
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Delete a folder and all its contents:

rm -r myfolder
Enter fullscreen mode Exit fullscreen mode

⚠️ Use this command carefully—especially with -r!


🧪** Try This!**

Here's a mini practice session:

  1. Create a folder named testlab.
  2. Inside testlab, create two files: one.txt and two.txt.
  3. Rename one.txt to first.txt.
  4. Copy first.txt into a folder called backup.
  5. 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
Enter fullscreen mode Exit fullscreen mode

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)