Copy File in linux computer system can be performed via terminal using a simple command line. While file also can be created, renamed, modified, grown, and shrunk (truncated). In most cases, software programs that are executed on the computer handle these operations, but the user of a computer can also modify files if necessary.
For instance, files are normally copied by program in response to user commands, but the user can also copy these files directly by using a file manager program such as Windows Explorer (on Windows computers) or via terminal with command line (CLI) on linux system.
How To Copy File in Linux?
You can easily copy file in linux via terminal on your system using the command line with the following methods cp, and Information.
Linux Command To Copy File
“cp” command is used to copy files or group of files or directory from the current directory to a different directory. This is one of the most common administrative tasks you can perform when working on terminal with the linux command line.
To copy file in linux:
- Open “Terminal” on your linux system.
- Keep on the current working directory or go to the specific directory (use “cd” to change directory) that you want to copy the file inside it.
- Use “cp” command with option as alternative and specify the “file-name.ext”.
- The syntax for using the “cp” command as shown below.
cp [option] [source-file-name] [destination]
- Copy a file in the current directory to another directory.
cp doc.txt /home/username/Documents
This will copy “doc.txt” to directory called “Documents”.
- Copy multiple files in the current working directory to another directory.
cp doc.txt image.jpg docs.pdf /home/username/Documents
This will copy “doc.txt”, “image.jpg”, and “docs.pdf” to directory called “Documents”.
- Copy all files to another directory, Use wildcard (*).
cp * /home/username/Documents
This will copy all files to directory called “Documents”.
- Use the “cp” with the “-i” option to confirm before copying it.
cp -i doc.txt /home/username/Documents
- Copy a file in the current directory to another directory.
- Done, now you’ve already copied the files.
More Information
“cp” command related information can be obtained with “–help”.
cp --help
Usage: cp [OPTION]… [-T] SOURCE DEST
or: cp [OPTION]… SOURCE… DIRECTORY
or: cp [OPTION]… -t DIRECTORY SOURCE…
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
By default, sparse SOURCE files are detected by a crude heuristic and the corresponding DEST file is made sparse as well. That is the behavior selected by –sparse=auto. Specify –sparse=always to create a sparse DEST file whenever the SOURCE file contains a long enough sequence of zero bytes. Use –sparse=never to inhibit creation of sparse files.
When –reflink[=always] is specified, perform a lightweight copy, where the data blocks are copied only when modified. If this is not possible the copy fails, or if –reflink=auto is specified, fall back to a standard copy. Use –reflink=never to ensure a standard copy is performed.
The backup suffix is ‘~’, unless set with –suffix or SIMPLE_BACKUP_SUFFIX. The version control method may be selected via the –backup option or through the VERSION_CONTROL environment variable. Here are the values:
- none, off never make backups (even if –backup is given)
- numbered, t make numbered backups
- existing, nil numbered if numbered backups exist, simple otherwise
- simple, never always make simple backups
As a special case, cp makes a backup of SOURCE when the force and backup options are given and SOURCE and DEST are the same name for an existing, regular file.
Many computer systems use extensions in file names to help identify what they contain, also known as the file type. Extensions consist of a dot (period) at the end of a file name, followed by a few letters to identify the type of file. An extension of .txt identifies a text file; a .doc extension identifies any type of document or documentation, and so on.