Now that you can move around the filesystem, it is time to shape it. In this lesson you will create files and folders, copy and move them, rename things, and delete safely. These five commands—touch, mkdir, cp, mv and rm—are the daily bread of anyone working on a Linux system.
touch creates an empty file if it does not exist, or updates the modification time if it does:
touch notes.txt
touch index.html style.css app.js # create several at once
ls -l notes.txtWhy would you want an empty file? Placeholders for a project skeleton, log files a script will append to, or simply a quick way to test other commands.
mkdir projects # one directory
mkdir docs images scripts # several at once
mkdir -p site/assets/css # -p creates the whole nested pathThe -p (parents) flag is the one to remember: it builds every missing level of a path in one go and never complains if the directory already exists. Without it, mkdir site/assets/css fails unless site/assets already exists.
cp copies files and directories. The last argument is always the destination:
cp notes.txt backup.txt # copy to a new name
cp notes.txt ~/backups/ # copy into a directory, same name
cp index.html style.css site/ # copy multiple files into a folder
cp -r site site-backup # -r copies a directory recursivelyTwo flags will save you pain:
cp -i asks before overwriting an existing file (interactive).cp -r is required for directories; without it cp refuses to copy a folder.Linux does not have a separate rename command—mv does both jobs:
mv draft.txt final.txt # rename a file
mv final.txt ~/documents/ # move it elsewhere
mv old-site/ archive/old-site/ # move a whole directory (no -r needed)
mv -i report.txt done/ # ask before overwritingMoving within the same disk is instant regardless of file size, because Linux only rewrites the directory entry, not the data itself.
rm scratch.txt # delete a file
rm -i *.log # confirm each deletion
rmdir empty-folder # delete a directory only if it is empty
rm -r old-project # delete a directory and everything insideThere is no trash can on the command line. rm deletes immediately and permanently. Build these habits from day one:
ls on the target first so you see exactly what will match.rm -i while learning.rm -rf on a path you have not double-checked, and be extremely careful with variables or wildcards in the path.The shell expands * to match any characters, which works with all of these commands:
cp *.jpg images/ # copy every .jpg file
mv report-*.txt done/ # move report-1.txt, report-2025.txt, ...We cover patterns in depth in the searching lesson; for now, test any wildcard with ls before using it with rm.
mkdir -p myapp/{src,tests,docs}
touch myapp/src/main.py myapp/README.md
cp myapp/README.md myapp/docs/
mv myapp/docs/README.md myapp/docs/overview.md
ls -R myappThe {src,tests,docs} brace expansion creates three sibling folders in one command—a taste of how expressive the shell can be.
touch creates empty files; mkdir -p builds whole directory paths.cp copies (-r for folders); mv both moves and renames, no -r needed.rm is permanent—check with ls first and use -i while learning.*.txt let one command act on many files.Next lesson: Viewing Files: cat, less, head, tail — read file contents without opening an editor.