Linux Tutorial / Manage Files and Directories: Create, Copy, Move, and Delete
Use mkdir to make a directory, touch to prepare an empty file, cp and mv to copy or move it, and rm and rmdir to remove files and empty directories. This lesson keeps all changes inside a new practice folder in your home directory and checks the result after each operation.
Prepare a safe practice directory
These steps assume Bash and an ordinary user account. ~/linux-course-07-practice is meant to be a new, empty directory. If it already exists, choose another name rather than touching existing data. The first mkdir command will report an error if the name is taken; treat that as a reason to stop, not as a step to skip.
mkdir ~/linux-course-07-practice
On success, mkdir normally prints nothing. Check that the directory was created with ls -ld. The rest of the exercise assumes that this step succeeded and that the directory was empty.
ls -ld ~/linux-course-07-practice
Create two subdirectories, then list the practice directory:
mkdir ~/linux-course-07-practice/drafts ~/linux-course-07-practice/archive ls ~/linux-course-07-practice
You should see archive and drafts. mkdir -p is useful when creating deeper paths, but it also accepts an existing directory, so this exercise does not use it.
Create and check an empty file
touch creates an empty file when its name does not exist. On an existing file, it can update timestamps instead, so it should not be understood as a command that only creates new files.
touch ~/linux-course-07-practice/drafts/notes.txt ls -l ~/linux-course-07-practice/drafts/notes.txt
Because the new file has no content, ls -l will generally show a size of 0 bytes. Permissions and dates depend on your system. touch does not write text into the file; that requires an editor or another command.
Compare copying and renaming
cp leaves the source in place and creates a separate copy. This command copies notes.txt from drafts to archive. With GNU cp, -i asks before overwriting an existing destination of the same name.
cp -i ~/linux-course-07-practice/drafts/notes.txt ~/linux-course-07-practice/archive/notes.txt ls -1 ~/linux-course-07-practice/drafts ls -1 ~/linux-course-07-practice/archive
The two ls -1 commands produce the following lines in order: first the contents of drafts, then those of archive. Both contain notes.txt. Changing the content of one copy later does not automatically update the other.
notes.txt notes.txt
mv moves a file to another location or changes its name within the same directory. Here it renames the original file to notes-old.txt; the archived copy keeps its original name.
mv -i ~/linux-course-07-practice/drafts/notes.txt ~/linux-course-07-practice/drafts/notes-old.txt ls -1 ~/linux-course-07-practice/drafts ls -1 ~/linux-course-07-practice/archive
Now the first output line, from drafts, is notes-old.txt. The second, from archive, remains notes.txt. The source name changed without changing the copy.
notes-old.txt notes.txt
If the last argument to cp or mv is an existing directory, the file is placed inside that directory under its name. Check whether the destination is a file or directory before running the command. Do not approve an -i overwrite prompt without reading it.
Remove a file and an empty directory
rm removes a named file. It does not send the file to a recycle bin by default, so check the path with ls first. Here -i requests confirmation before deletion. Read the file name in the prompt and agree only if it is the intended target.
ls -l ~/linux-course-07-practice/drafts/notes-old.txt rm -i ~/linux-course-07-practice/drafts/notes-old.txt
If you confirmed the deletion, drafts is now empty. Use rmdir, which removes only an empty directory:
rmdir ~/linux-course-07-practice/drafts ls ~/linux-course-07-practice
The final listing still contains archive. Because archive contains notes.txt, trying to remove it with rmdir would fail. Keep the practice data until you no longer need it, then check the exact path before cleaning it up separately. A blanket rm -rf is not a good shortcut for this beginner exercise.
Checks to make before changing files
- Current location: Run
pwdwhen a relative path depends on where you are. - Target: Use
ls -ldto inspect the named file or directory itself. - Overwriting: Back up important data and check the destination for an existing name before copying or moving.
- Deletion:
rmdoes not provide a built-in recovery mechanism; do not guess a short path and run it.
For more options and edge cases, see the guides to touch, mkdir, cp, mv, rm, and rmdir.
Official documentation
Consult the GNU Coreutils manual for these commands and their options. Check man or --help on your own system when the installed implementation matters.









