To copy one file into several directories on Linux, run cp once for each destination, usually in a shell loop. For example, for dir in /srv/archive /mnt/backup; do cp -- report.csv "$dir/"; done copies report.csv into both directories, provided they already exist.
The straightforward way: a shell loop
The regular cp command copies a source file to one destination path. It does not treat a list of directory names as multiple destinations: in cp report.csv /srv/archive /mnt/backup, the command interprets the first two paths as source files and the last as the destination directory, which is not the operation you want. A loop gives each destination its own copy operation.
Use this general form:
for dir in /path/one /path/two /path/three; do
cp -- /path/to/file "$dir/"
done
Replace the example paths with your own. The trailing slash tells cp to put the file inside each directory, keeping its original filename. For instance, copying /home/lee/notes.txt to /tmp/a and /tmp/b creates /tmp/a/notes.txt and /tmp/b/notes.txt.
This approach works in common shells such as Bash and the POSIX shell. Each loop iteration copies the source separately, so it is easy to add or remove destinations and to see which operation failed.
What the command parts mean
In the loop, for dir in ... assigns each listed path to the variable dir in turn. The command between do and done runs once for every value. The shell expands $dir to the current destination, and cp writes a copy there.
cpis the file-copy utility.--ends option processing for GNUcp. It prevents a filename beginning with a hyphen from being mistaken for an option.- The source path names the one file to copy.
"$dir/"is the destination directory, quoted so spaces and shell-special characters in the path stay together.
If you do not need a loop, you can issue separate commands: cp -- report.csv /srv/archive/ and cp -- report.csv /mnt/backup/. That is perfectly reasonable for two destinations. A loop becomes more convenient when there are several paths, when you will repeat the task, or when the destinations are generated by a script.
Paths with spaces and unusual names
Quote variables and paths that might contain spaces. For example, this loop safely handles directory names such as /home/lee/Old Reports:
src='/home/lee/monthly report.csv'
for dir in '/srv/Finance Team' '/mnt/Offline Copy'; do
cp -- "$src" "$dir/"
done
Quoting prevents the shell from splitting a path at spaces or interpreting characters such as * as a wildcard. In the example, each destination is individually quoted in the list, and the expanded variable is quoted in the copy command. A common mistake is writing cp $src $dir/ without quotes; that can break when a path contains whitespace or glob characters.
The -- marker is useful when a filename might start with a dash, such as -draft.txt. If the source is in the current directory, write cp -- ./-draft.txt "$dir/". The ./ makes it unambiguously a path rather than an option. On Linux, GNU coreutils is commonly used, and its cp supports --.
Creating destination directories first
cp does not create missing parent directories. If a destination directory might not exist, create it with mkdir -p before copying:
src='/home/lee/report.csv'
for dir in '/srv/archive' '/mnt/backup'; do
mkdir -p -- "$dir" || continue
cp -- "$src" "$dir/"
done
The -p option asks mkdir to create any missing parent directories and not complain merely because the requested directory already exists. Here, || continue skips the copy for a destination whose directory could not be created. That is a simple failure-handling choice; in a script where every copy must succeed, it is better to report errors and return a failure status rather than silently continue.
Be deliberate about creating directories. A misspelled path can cause mkdir -p to create an unintended directory tree, and then the copy may succeed in the wrong place. Check the destination list before running a script that creates directories automatically.
Overwriting, permissions, and timestamps
By default, cp replaces an existing destination file with the same name, subject to permissions. If report.csv already exists in a target directory, the new copy overwrites its contents. Use cp -i to ask before overwriting interactively, or check the destinations first if the copies are part of an unattended script. GNU cp -n can be used to avoid replacing existing files, but it is not a portable POSIX option and may not be available with identical behavior on every system.
There are also options for file metadata:
cp -pattempts to preserve the source file’s mode, ownership, and timestamps. Some attributes may not be preserved if the user lacks the required permissions.cp -ais an archive mode intended to preserve more attributes and handle directories and symbolic links appropriately. For a single ordinary file, it may be more than you need.cp -vprints each copy operation, which can help confirm where files are going.
Options can be combined, for example cp -pv -- "$src" "$dir/". Be cautious with force-related options: they do not make a copy safer, and they can make it easier to replace a file you meant to keep. Choose overwrite behavior deliberately, especially when the destination folders contain important data.
Using the loop in a script
For a one-time command, the basic loop is usually enough. For a reusable script, make the source and destinations easy to review and provide a clear result if something fails. Here is a Bash example using an array, which keeps each destination as one value even if its name contains spaces:
#!/usr/bin/env bash
src='/home/lee/report.csv'
destinations=( '/srv/archive' '/mnt/Backup Drive' )
for dir in "${destinations[@]}"; do
if ! cp -- "$src" "$dir/"; then
printf 'Copy failed: %s to %s\n' "$src" "$dir/" >&2
exit 1
fi
done
Bash arrays are not supported by every shell, so use the earlier loop if you need a plain POSIX-shell example. The script above stops at the first copy failure and writes a message to standard error. Another valid policy is to attempt all destinations and report a final failure if any copy failed; the right choice depends on whether partial completion is acceptable.
For repeatable jobs, also consider where the script runs and which account runs it. A command that works in your interactive terminal may fail from a scheduled task because it uses a different user, permissions, working directory, or environment. Use explicit paths and test the script under the same account and conditions as the real job.
Alternatives and when to use them
For a few destinations, repeated cp commands are clear. For a list of directories, a loop is usually the most readable option. Other tools can be useful in narrower situations:
installcan copy a file while setting permissions, which is handy when placing a program or configuration file into a known location. It is not a general replacement for everycpuse.rsyncis useful for repeated or large transfers where you want options such as progress reporting, synchronization, or resuming behavior. Run it once per destination; it does not turn one file into several destination copies with a single ordinary target argument.teecan send incoming data to multiple output files, but it is a stream-writing tool rather than a drop-in file copier. It does not preserve file metadata likecp, and an interrupted write can leave incomplete output files.
For example, tee can be used as tee /srv/a/report.csv /mnt/b/report.csv < report.csv > /dev/null, but this reads and writes file contents and has different failure and metadata behavior. Unless you specifically need to duplicate a stream, a loop around cp is easier to understand and less surprising.
Common problems and checks
If the command fails or the result is unexpected, check the source path, destination paths, permissions, and the exact destination filename. A few frequent issues are:
- “Not a directory” or “No such file or directory”: a destination may be missing, misspelled, or not a directory. Confirm it with
ls -ld /path, or create it intentionally withmkdir -p. - Only one copy appears: check that every destination is listed in the loop and that the commands are between
doanddone. - A path with spaces breaks: quote the source and the expanded destination as shown above.
- The old copy disappears:
cpoverwrites same-named destination files by default. Use an interactive option or a deliberate no-overwrite policy if that is not desired.
After copying, verify the result rather than assuming every iteration succeeded. You can list each destination with ls -l, or compare the source and each copy with cmp, which reports whether two files differ. For important data, a separate backup or checksum-based verification may be appropriate.
Frequently Asked Questions
Can cp copy one file to multiple directories in one command?
Not by simply listing several destination directories. Use a loop that runs cp once per directory, or write one separate cp command for each destination.
How do I copy a file into every subdirectory?
If you mean every immediate subdirectory of the current directory, a Bash loop can use for dir in */; do cp -- file "$dir"; done. The glob matches directory names ending in a slash, but it may remain unmatched when there are no subdirectories, depending on the shell settings. Test the pattern before using it on valuable files.
Does cp create the destination folder?
No. The destination directory must already exist. Use mkdir -p first if you intend to create it, and verify the path so a typo does not produce an unwanted directory.
Will cp preserve the original file’s permissions and time?
Plain cp does not promise to preserve all source metadata. Use cp -p to request preservation of mode, ownership, and timestamps where permitted; use archive mode when copying directory trees or when broader preservation is needed.
Can I give each copy a different filename?
Yes. Build the full destination filename inside the loop, such as cp -- "$src" "$dir/weekly-report.csv". Each directory receives the contents under that specified name, regardless of the source file’s basename.