Linux Basics: Creating, Copying, and Removing Files
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 -dThe 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
lstouch 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 archivenotes-copy.txtcp 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 archiveAnswer 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
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