How to Copy a Directory in Linux: Commands, Options, and What to Know First
Copying a directory in Linux sounds straightforward — and in many cases it is — but the details matter. Whether you're backing up a project folder, migrating files to a new drive, or duplicating a configuration directory, the command you use and the flags you pass will determine whether you get exactly what you expected or end up with missing files, broken permissions, or a partial copy.
The Core Command: cp -r
The standard tool for copying directories in Linux is cp, and the key flag is -r (or --recursive). Without it, cp will refuse to copy a directory and return an error.
Basic syntax: