
- Kali Linux Tutorial
- Kali Linux - Home
- Installation & Configuration
- Information Gathering Tools
- Vulnerability Analyses Tools
- Kali Linux - Wireless Attacks
- Website Penetration Testing
- Kali Linux - Exploitation Tools
- Kali Linux - Forensics Tools
- Kali Linux - Social Engineering
- Kali Linux - Stressing Tools
- Kali Linux - Sniffing & Spoofing
- Kali Linux - Password Cracking Tools
- Kali Linux - Maintaining Access
- Kali Linux - Reverse Engineering
- Kali Linux - Reporting Tools
- Kali Linux Useful Resources
- Kali Linux - Quick Guide
- Kali Linux - Useful Resources
- Kali Linux - Discussion
How to copy a file, group of files, or directory in Linux?
In this article, we will learn to copy a file or directory in the Linux/Unix operating system using terminal, we use the cp command to copy a file or directory in the Linux system.
cp (copy) - The cp command is used to copy files or directories in the Linux system. If we want to copy a file from a source directory and paste it into another destination directory then we have to use the cp command. By default, the cp command will not copy directories to copy directories we have to use -R option with cp command otherwise error will be prompt.
Syntax
The general syntax of the cp command is as follows −
cp [OPTION]...[-T] SOURCE DESTINATION cp [OPTION]...SOURCE DESTINATION cp [OPTION]...-t DIRECTORY SOURCE...
Brief description of option available in the cp command.
Sr.No. | Option & Description |
---|---|
1 | --attributes-only Copy only attributes of file |
2 | --backup Create backup of destination file |
3 | -b Create backup file without argument |
4 | -f Copy forcefully |
5 | -i, interactive Prompt before overwriting files |
6 | -l, --link Create hard link of files instead of copying |
7 | -R, -r, --recursive Copy directories recursively |
8 | --help Displays a help message and then exits. |
9 | --version It gives info about the version and then exits. |
We will copy a file from a directory and paste it into another directory using cp command
$ cp file.txt ../snow
After executing this command files will be copied, to ensure we will change the directory and list the contents of the directory using the below command.
$ cd ../snow $ ls file.txt
We will copy all .txt (text) files available in a source directory and paste it into the destination directory using * wildcard with cp command in the Linux system.
$ cp *.txt ../snow
Here, we use the -i option to copy a file from the source directory and paste it into the destination directory if the file is already existing in the destination directory with the same name then a warning message will be prompt before overriding the file.
$ cp -I file1.txt ../shadow cp: overwrite ‘../shadow/file.txt’? y
- Related Articles
- Copy Directory Structure Without Files on Linux
- How to move a file, group of files, and directories in Linux?
- How to copy files into a directory in C#?
- Copy a directory to an existing directory Linux?
- How to change file or directory permission in Linux/Unix?
- How to copy files to a new directory using Python?
- How to unzip all zipped files in a Linux directory?
- How to Copy a File to Multiple Directories in Linux?
- How to add, delete, change ownership (of files) of a group in Linux?
- How to Copy File Permissions and Ownership to Another File in Linux?
- How to disable delete permission of File and Directory in Linux?
- How to Count Number of Files and Subdirectories inside a Given Linux Directory?
- How to Copy files or Folder without overwriting existing files?
- How to Get the most recent file in a directory in Linux?
- Linux – How to find the files existing in one directory but not in the other directory?
