Files and Directories

Create, copy, move, and delete files and folders from the shell

Overview

Most terminal work involves creating and reorganizing files and folders. A handful of commands — touch, mkdir, cp, mv, and rm — cover the vast majority of day-to-day file management. Learning them well makes you faster than any graphical file browser.

Syntax / Usage

Create, copy, move, and remove files and directories with these core commands.

touch notes.txt              # create an empty file
mkdir logs                   # create a directory
mkdir -p src/utils/helpers   # create nested directories in one step
cp notes.txt backup.txt      # copy a file
cp -r src/ src-copy/         # copy a directory recursively
mv backup.txt archive.txt    # rename or move a file
rm archive.txt               # delete a file
rm -r old-project/           # delete a directory and its contents

Examples

Scaffold a small project structure quickly:

mkdir -p blog/{posts,drafts}
touch blog/posts/first-post.md

Back up a file before editing it:

cp config.json config.json.bak

Rename a folder and confirm the result:

mv drafts draft-archive
ls

Common Mistakes

  • Using rm -r (or rm -rf) without double-checking the path — deletions are permanent, with no trash bin
  • Forgetting -r when copying or removing directories
  • Overwriting a file with cp/mv because the destination already existed
  • Assuming mkdir creates parent folders; you need -p for nested paths
  • Putting spaces in filenames without quoting them, e.g. my file.txt

See Also

command-line-navigation command-line-permissions command-line-text-processing