DEV Community

Cover image for Mastering File Operations in Linux: The Power of cp, mv, mkdir, and More (Day 2 of 30)
Sheikh Hassaan Bin Nadeem
Sheikh Hassaan Bin Nadeem

Posted on

3

Mastering File Operations in Linux: The Power of cp, mv, mkdir, and More (Day 2 of 30)

Table of Contents

  1. Introduction
  2. The Power of Simple Commands
  3. Summary

1. Introduction

When working with Linux, the real magic often begins with basic file operations. Whether you’re organizing configuration files, preparing codebases, or setting up automated scripts — commands like cp, mv, mkdir, and others are your everyday tools. Think of them as your file management toolkit — fast, reliable, and always available right inside your terminal.

Linux Commands Mind Map


2. The Power of Simple Commands

cp – Copy Files and Folders

What it is:

The cp command lets you copy files or directories from one place to another.

Use Case:

Copy a file from your current directory to a backup folder:

Linux cp command

Why It Matters:

Backups often start here. You may not use cp for large-scale backup solutions (like rsync or tar), but for small manual backups or quick duplication, it's perfect.

Pro Tip:

Use -r for recursive copy (directories), and -v for verbose output.

Linux cp -r command


mv – Move or Rename with Control

What it is:

Moves files/directories from one location to another. It also acts as the "rename" command in Linux.

Use Case:

Rename a file:

Linux mv command

Move a file to another folder:

Linux mv command to move

Why It Matters:

When organizing files or managing logs, mv helps clean things up or archive old files.

Pro Tip:

If you're renaming a lot of files, combine mv with shell scripting or find for batch renaming.


mkdir – Create Directories Like a Pro

What it is:

Used to create one or more directories.

Use Case:

Create a folder structure in one go:

Linux mkdir command

Why It Matters:

Directory planning is key for maintainability. mkdir helps you quickly set up organized environments.

Pro Tip:

Use -p to create parent directories automatically — it saves time and prevents errors.


rm – Remove with Caution

What it is:

Deletes files or directories.

Use Case:

Remove a file:

Linux rm Command

Remove a directory and everything inside it:

Linux rm -rf command

Why It Matters:

Clean up is part of system maintenance. But misuse can be risky — especially when used with -rf.

Pro Tip:

On modern Linux systems like Red Hat 9, rm -rf / is blocked by default for safety — but you should never try it anyway.

If you force it using --no-preserve-root, it will attempt to delete your entire system.

Instead, set an alias to add a confirmation prompt:

Linux rm -rf in RHEL 9


touch – Quickly Create Empty Files

What it is:

Creates new, empty files or updates timestamps on existing ones.

Use Case:

Create a new log file or placeholder:

Linux touch command

Why It Matters:

Used in scripting, testing, and placeholder creation. It’s lightweight but powerful.

Pro Tip:

Combine with mkdir to create folder/file structures for new projects:

Linux mkdir command


3. Summary

The basic commands in Linux like cp, mv, mkdir, rm, and touch are more than just simple tools — they’re fundamental to daily workflows. Once you get comfortable with them, you’ll navigate your system with ease, automate smartly, and build the habits of a Linux power user.

As we progress in this 30-day journey, mastering these basics will give you the confidence to handle more advanced scripting, backups, and DevOps tasks with clarity.

Top comments (4)

Collapse
 
moopet profile image
Ben Sinclair

I don't see the use case for using touch to create files. I think it's a great command, for updating tinestamps, but I don't know why people promote it for file creation. (see also dev.to/moopet/creating-files-with-... )

Collapse
 
sheikhhassaanbinnadeem profile image
Sheikh Hassaan Bin Nadeem

Hey Ben, thanks for coming up with this great use case. I'll check it out!

Collapse
 
dtemi profile image
OLUWADAMILOLA FASHINA

This was a good read…

Collapse
 
sheikhhassaanbinnadeem profile image
Sheikh Hassaan Bin Nadeem

Thanks for the feedback Oluwadamilola!