The CP command in Linux

Source: Internet
Author: User
Tags file copy

CP command--file copy

Copy commands for directories and files

CP command syntax and parameters:

CP [OPTION] ... SOURCE ... DIRECTORY

-A All Equivalent to DPR
-D
When you copy a symbolic link source file, the destination file also creates the original file of the symbolic link execution source file
-P Preserve Preserve file attributes, owner, group, permissions, and time
-R Recursive Sub-Files in the recursive directory

Example:

[Email protected] ~]# ll/etc/services

-rw-r--r--1 root root 362031 2006-02-23/etc/services

[Email protected] ~]# stat/etc/services

File: "/etc/services"

size:362031 blocks:728 IO block:4096 general file

device:fd00h/64768dinode:2282597 links:1

Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)

access:2014-11-11 11:20:33.000000000 +0800

modify:2006-02-23 21:09:23.000000000 +0800

Change:2014-10-21 15:21:26.000000000 +0800


[Email protected] ~]# cp-a/etc/services/tmp/services

[Email protected] ~]# ll/tmp/services

-rw-r--r--1 root root 362031 2006-02-23/tmp/services

[Email protected] ~]# stat/tmp/services

File: "/tmp/services"

size:362031 blocks:728 IO block:4096 general file

device:fd00h/64768dinode:1434761 links:1

Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)

access:2014-11-11 11:20:33.000000000 +0800

modify:2006-02-23 21:09:23.000000000 +0800

change:2014-11-11 11:44:39.000000000 +0800

Description: All properties and permissions for the file have been copied, and CTime has changed


Extension: The source file is copied to the destination directory where the hint file already exists, how to overwrite the target file directly? And let the system not prompt to overwrite it?

[Email protected] ~]# cp-a/etc/services/tmp/

CP: Do you want to overwrite "/tmp/services"?

In scripts, it is not possible to manually participate in the interaction, the workaround:

    1. [Email protected] ~]# \cp-a/etc/services/tmp/services

    2. [Email protected] ~]# Unalias CP
      [Email protected] ~]# cp-a/etc/services/tmp/

    3. [Email protected] ~]#/bin/cp-a/etc/services/tmp/services
      Description: By default, cp= Cp-i but the-i parameter is the meaning of the hint overlay


This article is from the Linux Operations sharing blog, so be sure to keep this source http://liangey.blog.51cto.com/9097868/1575258

The CP command in Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.