4. Linux - Creating, Copying, Moving and Deleting Safely

30 Sep 2026 · Linux

 

Linux File Management — Creating, Copying, Moving and Deleting Files Safely

 

Working with files is one of the most basic tasks in Linux administration. However, basic does not mean unimportant.

A Linux administrator constantly creates configuration files, copies files for backups, moves files between directories, renames files and removes files that are no longer needed.

The important part is not only knowing the commands. It is knowing what they will change before executing them.

 

Creating Files and Directories

 

To create an empty file, I can use:

touch config.txt

I can verify that the file was created with:

ls -l

To create a directory:

mkdir backup

And then check it:

ls -ld backup

I can also create a directory structure at once:

mkdir -p project/config/nginx

The -p option allows me to create the required parent directories if they do not already exist.

 

Copying Files

 

The cp command is used to copy files.

For example:

cp config.txt backup/

This creates a copy of config.txt inside the backup directory.

I can verify the result:

ls -l backup/

I can also copy a file and give the copy a different name:

cp config.txt backup/config.backup

This is useful when I want to create a backup before modifying a configuration file.

For directories, I need to copy their contents recursively:

cp -r project project_backup

The -r option means that directories and their contents are copied recursively.

 

Moving and Renaming Files

 

The mv command is used to move files and directories.

For example:

mv config.txt backup/

The file is moved from the current directory into backup.

The same command can also be used to rename a file:

mv config.txt config.old

There is no separate rename command required for this basic operation.

I can verify the change with:

ls -lah

 

Deleting Files

 

To remove a file:

rm config.old

After deleting it, I should verify that it is no longer present:

ls -lah

Removing directories requires more attention.

An empty directory can be removed with:

rmdir backup

If the directory contains files, rmdir will not remove it.

A directory and its contents can be removed recursively with:

rm -r backup

This is a destructive operation, so I should always verify the path before executing it.

 

Working Safely

 

The most important lesson is not the syntax of cp, mv or rm.

It is the workflow.

Before modifying the filesystem, I should know:

Where am I?
What files are here?
What exactly am I changing?
What will the command do?
Can I recover the data if something goes wrong?

For example, before removing something, I can inspect the target:

pwd
ls -lah

Then execute the operation and verify the result:

rm config.old
ls -lah

This simple habit becomes much more important when working with real servers and important configuration files.

 

Practical Example

 

Imagine that I have an Nginx configuration file:

nginx.conf

Before modifying it, I can create a backup:

cp nginx.conf nginx.conf.backup

Now I have:

nginx.conf
nginx.conf.backup

If I make a mistake while editing the configuration, I still have the original copy available.

This is a simple example of how basic file-management commands can be used as part of a safer administration workflow.

 

Key Takeaways

 

The commands covered in this lesson are:

touch   → create a file
mkdir   → create a directory
cp      → copy files/directories
mv      → move or rename files/directories
rm      → remove files/directories
rmdir   → remove empty directories
ls      → inspect files and directories
pwd     → show the current directory

The commands themselves are easy to learn.

The important skill is using them carefully:

Inspect → Change → Verify.

 

 

← Back to blog