Creating files
Usetouch to create an empty file or update an existing file’s timestamp.
Create a file named Receipt.pdf in the current directory:
jane):
Creating directories
Usemkdir (make directory) to create a folder:
-p:
Copying files and directories
Thecp command copies files and directories. General form:
- 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:
-r (or -a to preserve attributes) option:
- If the destination exists and is a directory,
cpplaces the source inside that directory (e.g., copyingReceiptsinto an existingBackup of ReceiptsyieldsBackup of Receipts/Receipts). - If the destination path does not exist,
cp -rwill create a new directory at the destination name and copy the contents there.
Moving and renaming
Usemv to move or rename files and directories:
Receipt.pdf into the Receipts directory — the file is removed from the original location and appears only in the destination.
Rename a file:
-r with mv to move directories; mv moves directories and their contents automatically.
Deleting files and directories
Remove a single file withrm:
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
Links and references
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.