Skip to main content
This guide covers the most common file and directory operations on Unix-like systems: creating files, creating directories, copying, moving (including renaming), and deleting. Every command accepts absolute or relative paths — examples show both forms where helpful.

Creating files

Use touch to create an empty file or update an existing file’s timestamp. Create a file named Receipt.pdf in the current directory:
Create the same file at a different location using an absolute path:
Or using a relative path (one directory up, then into jane):
Both absolute and relative paths work the same; choose the form appropriate to your current working directory.

Creating directories

Use mkdir (make directory) to create a folder:
To create nested directories in one command, use -p:

Copying files and directories

The cp command copies files and directories. General form:
Copy a file into a directory:
Common conventions:
  • A trailing slash on a directory (Receipts/) is not required but makes it clear you mean a directory.
  • To copy and rename in a single step, specify a different destination filename:
To copy a directory and everything inside it, use the recursive -r (or -a to preserve attributes) option:
Notes about destination behavior:
  • If the destination exists and is a directory, cp places the source inside that directory (e.g., copying Receipts into an existing Backup of Receipts yields Backup of Receipts/Receipts).
  • If the destination path does not exist, cp -r will create a new directory at the destination name and copy the contents there.

Moving and renaming

Use mv to move or rename files and directories:
This moves Receipt.pdf into the Receipts directory — the file is removed from the original location and appears only in the destination. Rename a file:
Rename a directory:
You do not need -r with mv to move directories; mv moves directories and their contents automatically.

Deleting files and directories

Remove a single file with rm:
Remove a directory and all of its contents recursively:
rm -r will permanently delete the directory and everything inside it. This action is typically irreversible — double-check paths before running recursive deletes.

Quick reference table

Paths can be absolute (for example, /home/jane/Receipt.pdf) or relative (for example, ../jane/Receipt.pdf). Using a trailing slash on a directory name (for example, Receipts/) is a helpful convention to indicate a directory.

Examples: absolute vs relative paths

This covers the fundamental file and directory commands you’ll use daily. Practice with safe targets (temporary directories) until you’re comfortable, especially when using -r with cp or rm.

Watch Video

Practice Lab