Copy files to a Directory in Linux
When the cp
command has one or more source file arguments and is followed by a destination directory argument, it copies each source file to the destination directory with the same name. If the destination directory does not exist, it is created. If it already exists, the files are overwritten without warning.
cp Src_file1 Src_file2 Src_file3 Dest_directory
Example:
Suppose we have to copy three files name “a.txt“, “b.txt” and “c.txt” to a directory name “new”
cp a.txt b.txt c.txt new/
We used `ls` command to display all the file in the “new” directory to confirm the successful copy of file in that directory.
How to Copy Files and Directories in Linux | cp Command
In the world of Linux computers, a common and important job is copying files. The key tool for this task is the “cp” command. In this simple guide, we’ll explore how to copy a file in Linux, looking at the basic steps, different choices you can make, and giving clear examples. We’ll also take a peek behind the scenes to understand how the “cp” command works. Let’s get started on this easy journey to become familiar with the ins and outs of copying files in Linux!
Table of Content
- Syntax of cp Command
- How to Copy files in Linux with the cp Command
- 1. Copying Between Two Files in Linux
- 2. Copy files to a Directory in Linux
- 3. How to Copy Directories in Linux
- Options Available in `cp` Command in Linux