Copy Linux Files and Copy Directory Using cp Command - Linux Basic Command.


Using Linux cp command to copy Linux files and copy directory .


The Linux cp command usually use to copy file and copy directory in Linux operating system. The cp command also can be use to make an link to other file in the system. The execution of cp command and all of the example below tested using bash shell on Linux Fedora Core operating system.


This article demonstrate step by step procedure on how to use Linux cp command to:

• Copy Linux files.

• Copy all file in directory.

• Make an soft link to a file.


Command name: cp


Command Description:

Copy files and directory.


Command type:

On Fedora Core Linux operating system 'cp' command is aliased to the 'cp -i'


[root@fedora ~]# type cp

cp is aliased to `cp -i'


Copy the content of Linux files using Linux cp command.


The cp command below copy the passwd file from the /etc folder to current directory using the same filename.


[root@fedora ~]# pwd


[root@fedora ~]# cp /etc/passwd .

[root@fedora ~]# ls

anaconda-ks.cfg Desktop install.log install.log.syslog mbox passwd test

[root@fedora ~]#


The cp command also can be use to copy the contents of file into another files. The example below show the steps to copy file name passwd from the /etc directory and put the file into current directory using new filename.


[root@fedora ~]# pwd


[root@fedora ~]# cp /etc/passwd new-pass

[root@fedora ~]# ls

anaconda-ks.cfg Desktop install.log install.log.syslog mbox new-pass test

[root@fedora ~]#


To copy a file and preserve the file mode, ownership and timestamps, use cp with -p option.

The example below show the use of -p option:


[root@fedora5 ~]# cp -p /etc/passwd .

[root@fedora5 ~]# ls -l

total 112

-rw------- 1 root root 1209 Apr 9 21:38 anaconda-ks.cfg

drwx------ 2 root root 4096 Apr 8 19:06 Desktop

-rw-r--r-- 1 root root 28948 Apr 9 21:26 install-fedora.log

-rw-r--r-- 1 root root 4152 Apr 9 19:56 install.log.syslog

-rw-r--r-- 1 root root 1750 Apr 8 19:00 passwd

[root@fedora5 ~]# ls -l /etc/passwd

-rw-r--r-- 1 root root 1750 Apr 8 19:00 /etc/passwd

[root@fedora5 ~]#


Note: The ls -l command use in above example is to verify the passwd file is copy in preserve mode.


Copy file in verbose mode.


The example below show the step of using cp command in verbose mode to copy file on Fedora system. By using the cp command with verbose mode we can display the details of the running cp command.


[root@crooked test]# cp -v test.txt linux.txt

`test.txt' -> `linux.txt'

[root@crooked test]# ls -l

total 8

-rw-r--r-- 1 root root 28 Jun 29 17:05 linux.txt

-rw-r--r-- 1 root root 28 Jun 29 16:50 test.txt


The cp command with –v option produce the verbose output shows that test.txt file is copy to linux.txt file.


Using cp command to create identical copy of directory (archive).


To copy directory usually the cp command use with the -a option to make the sure the cp command archive the directory contents.


[root@crooked test]# cp –a directory new_directory


The cp command with –a option create an identical copy of directory called directory and named the directory to new_directory.


Using cp command to create an soft link to a file.


This example show how to create soft link using cp command, in this example the cp command is use to make a link to a linux.txt file.


[root@crooked test]# cp -vs linux.txt linux-link.txt

`test.txt' -> `link.txt'

[root@crooked test]# ls -l

total 8

lrwxrwxrwx 1 root root 8 Jun 29 17:06 linux-link.txt -> linux.txt

-rw-r--r-- 1 root root 28 Jun 29 16:50 test.txt


The cp command with –vs option create a link (name linux-link.txt) to the linux.txt file in verbose mode.


Using cp command to copy all files and folder.


[root@fedora test]# cd ..

[root@fedora ~]# cp -pr /home/fedoracore5/ test/fedoracore5

[root@fedora ~]# ls test/fedoracore5/


[root@fedora ~]# ls /home/fedoracore5/


[root@fedora ~]# ls -al /home/fedoracore5/


Cp command with option 'p' is to preserve the mode, ownership and timestamps of the file an the option 'r' is use to copy directory recursively.


The following are some of the flags and arguments that can be used for the cp command:


-f, --force if an existing destination file cannot be opened, remove it and try again

-i, --interactive prompt before overwrite

-l, --link link files instead of copying.

-p same as --preserve=mode,ownership,timestamps

-R, -r, --recursive copy directories recursively

-s, --symbolic-link make symbolic links instead of copying

-u, --update copy only when the SOURCE file is newer than the destination file or when the destination file is missing

-v, --verbose explain what is being done



cp - copy files and directories


for more information Linux cp command use:

# info cp

# man cp

# cp –help



Copy contents of directory include hidden files and hidden directory using cp command.


Keywords: cp command, copy linux file, copy file, copy folder, copy directory, copy linux directory, linux cp command, linux copy command, link files, copy command, copy file and directory, copy content of linux files, copy linux folder.




Very nice article on how to

Very nice article on how to copy files in linux, The content is in depth


Copy Linux Files and Copy Directory Using cp Command - Linux

It's appropriate time to make some plans for the future and it's time to be happy.

I've read this post and if I could I want to suggest you some interesting things or advice.
Maybe you could write next articles referring to this
article. I want to read more things about it!


I was expecting to work a

I was expecting to work a little bit more with file extensions instead of setting up commands. I know Linux is mostly based on commands but I think it's time for this operating system to become more accessible for wider use.


Copy Linux Files and Copy Directory Using cp Command - Linux

Do you know that the average American has some type of credit card debt.
There could be exceptions, however, as within the case of transactions which can be addressed beneath
the Mortgage Forgiveness Debt Relief Act
of 2007 that's signed into law by President Bush. Be conscious some companies will not supply
you with settlement amounts until you have fallen behind
by no less than one payment, if this will be the case you will have to forgo
a payment but get started with settlement negotiations as soon
when you possibly can.


Install Windows 7 using

Install Windows 7 using RootKit virus
Open desired folder
Find file needed to be copied.
Copy file in new folder.

I love using other operating systems to do tasks. Just like I use my windows to get in and out of my house, instead of using my front door.

I was also thinking of purchasing a vehicle for 70,000$ that I am unable to drive on 95% of the roads. Oh but wait! It cannot be broken into! That will come in handy when I drive it everywhere... Oh wait.. I can't. I'm not allowed to drive on 95% of the roads unless I modify my 70,000$ car.

Most of you will never understand these analogies



I bought Plus for XP, relcetny, then I installed it. I was expecting a Microsoft Plus that added great features like Plus 98. But, it was nothing like that. First, there was 4 measily little themes. And the fish screen saver, which if you want more fish, you'd have to pay for it. Well what was the $ for anyway? And the games! For heavens sake. Why put a stinkin lite edition into a $ collection of programs. And there are other programs that I might not fool with anyway. For those who are looking to buy this, please note that you at least need a 500 megahertz computer, 64MB of RAM, and a 3D video card with 16, I repeat 16MB of video memory. If Microsoft had added such things as an Antivirus to the program, more desktop themes, FULL EDITION Games, and less steep requirements, then I'd recommend this to everyone. So if your at the store, leave this on the shelf!!!PS This program is a prime example of Bloatware.


Calculate the file copying time


I would like to copy one file from my computer to another. Both are linux and I need the log file showing the time taken to copy the file. Please help me asap.



Very nice tutor.. Thanks..

Very nice tutor.. Thanks..


The real basic command

This is the real basic command, i have use this command, it works ! Thanks.


Thanks for your great post, i love it

I just looking for a basic tutorial for linux, i found your site, and after try your tutorial, now i get some basic knowledge, thanks.