Working with Files

Beginner

Overview

touch creates an empty file (or updates a timestamp). mkdir makes directories — add -p to create nested paths in one go.

cp copies, mv moves or renames, and rm deletes. Directories need the recursive flag -r for cp and rm.

rm is permanent — there is no recycle bin. Be especially careful with rm -rf, and never run it on / or with unverified variables.

Cheatsheet

touch file.txtCreate an empty file
mkdir -p a/b/cCreate nested directories
cp -r src dstCopy a directory recursively
mv old.txt new.txtRename or move a file
rm -r buildDelete a directory and its contents
cat file.txtPrint a file's contents

Try it

A safe, simulated terminal. Run the suggested commands to see typical output.

simulated terminal

Type a command and press Enter, or click a suggestion below to run it.

$

Quick quiz

1. Which flag lets mkdir create parent directories as needed?

2. How do you delete a directory and everything inside it?