9/9/08

cp

U might know this
But, just FYI

If you want to copy a file in UNIX, cp is the command
man cp gives the following info.
cp - copy files

SYNOPSIS /usr/bin/cp [-fip@] source_file target_file
/usr/bin/cp [-fip@] source_file... target
/usr/bin/cp -r -R [-H -L -P] [-fip@] source_dir... target
/usr/xpg4/bin/cp [-fip@] source_file target_file
/usr/xpg4/bin/cp [-fip@] source_file... target
/usr/xpg4/bin/cp -r -R [-H -L -P] [-fip@] source_dir... target


Usage Example:

$ mkdir testcp
$ mkdir testcpdest
$ cd testcp
$ touch x1.txt
$ cd ..
$ cp -r testcp testcpdest

I made a dir called testcp (which is the source dir)
I made another dir called testcpdest (destination dir)
I have touched a file x1.txt in testcp
I have copied testcp to testcpdest with files using cp -r meaning copy recursively.

Another ex.,
I have a file like this
-rw-r--r-- 1 websphe websphe 13593 Mar 18 11:53 n1.log
I want to cp it to n2.log with the same time stamp and same uid,gid permissions. This is the way
cp -p n1.log n2.log
n2.log will have same time stamp and other info as n1.log
-rw-r--r-- 1 websphe websphe 13593 Mar 18 11:53 n2.log
-rw-r--r-- 1 websphe websphe 13593 Mar 18 11:53 n1.log

No comments: