Skip to content
Linux Basics: Creating, Copying, and Removing Files

Linux Basics: Creating, Copying, and Removing Files

October 4, 2026

These commands work on Debian and Ubuntu. Practice in a new temporary directory so the examples do not affect your existing files.

Create a workspace

mktemp -d

The command prints a new directory, such as /tmp/tmp.ABC123. Run cd followed by the actual path it printed. Temporary directories are for practice, not for keeping important work.

Then create an empty file and a directory:

touch notes.txt
mkdir archive
ls

touch creates a file if it does not exist. If it already exists, touch updates its timestamps without erasing its contents. mkdir creates a directory.

Copy and move

cp -i notes.txt notes-copy.txt
mv -i notes-copy.txt archive/
ls archive
notes-copy.txt

cp copies a file. mv moves it; giving it a new filename also renames it. Here, archive/ is the destination directory.

The -i option asks before overwriting an existing destination file. Read the prompt before answering.

Remove the practice copy

rm -i archive/notes-copy.txt
rmdir archive

Answer y only when the removal prompt names the practice copy. rm removes files directly rather than putting them in a desktop trash folder. Check the path carefully.

rmdir removes an empty directory. It refuses to remove one that still contains files, which makes it useful while learning.

Your original notes.txt remains in the workspace. Use ls to check the result after each step.

Reference

GNU Coreutils file operations

Acknowledgements

This post was created with assistance from AI.

Linux Basics — lesson 4 of 25. Series index

Previous: Reusing Bash Command History · Next: Reading and Searching Text Files

Last updated on