Copy File to Directory or Copy File to Folder on Linux Fedora System



Configuration for GNU Linux Fedora Computer using Linux Command

 

     The example below show how to copy file to directory in Linux system using Linux cp command.  The step by step example use the example file name testcopy.txt that is locate in the current directory and then we copy the file to another directory in the system.

Linux command use on this example:

$ touch <-- create file

$ mkdir <-- create directory

$ ls          <-- List file and folder

$ cp    <-- Copy file

 

Create necessary file and folder to show the example of copying file to the directory on the system.

1.  Create files name testcopy.txt

Create file on Linux using touch command

[fedora@fedora ~]$ touch testcopy.txt

[fedora@fedora ~]$

 

2.  Create directory name this_is _directory

Make new directory on Linux using mkdir command

[fedora@fedora ~]$ mkdir this_is_directory

[fedora@fedora ~]$

 

3.  List file in the directory.

List files inside directory with ls command

[fedora@fedora ~]$ ls

Desktop Download Pictures Templates this_is_directory

Documents Music Public testcopy.txt Videos

[fedora@fedora ~]$

 

Copy file to directory

   Use the cp command with option -pr to copy the file with preserve mode ( preserve file ownership and preserve timestamps of the file ) to directory named this_is_directory.

 

4.  The cp command below copy the testcopy.txt file to the directory named this_is_directory

Copy linux file to directory

[fedora@fedora ~]$ cp -pr testcopy.txt this_is_directory/

[fedora@fedora ~]$

 

5.  Another example:  The command below cp the testcopy.txt file and name the file to testcopy2.txt and put the file to directory named this_is_directory.

Copy and rename file on Linux using cp command

[fedora@fedora ~]$ cp -pr testcopy.txt this_is_directory/testcopy2.txt

[fedora@fedora ~]$

 

6.  DONE:  Now use the ls command to verify the file copy to the directory...

List file in Linux directory

[fedora@fedora ~]$ ls this_is_directory/

testcopy2.txt testcopy.txt

[fedora@fedora ~]$

 




1 comments:

Yanuar said...

Thank you, I was looking for a way to copy files in Fedora.