Home  >  Article  >  Operation and Maintenance  >  How to set the cp command in Linux without prompting

How to set the cp command in Linux without prompting

WBOY
WBOYOriginal
2022-05-24 10:06:244439browse

How to set the cp command not to prompt in Linux: 1. Modify the "~/.bashrc" file, disable the alias of the cp command, and just comment out the "alias cp='cp -i'" content. ;2. Add "\" before the cp command, and you can also set the cp command not to prompt when using it.

How to set the cp command in Linux without prompting

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to set the cp command in Linux not to prompt

When using the cp command to overwrite, you will be prompted whether to overwrite regardless of whether you add -f or not. If there are many files to be copied, it will be very troublesome.

Solution:

Method 1: Modify the ~/.bashrc file to disable cp's alias

vi ~/.bashrc

Put alias cp='cp -i 'Comment it out, execute source ~/.bashrc or log in again to copy without prompting for overwriting.

# User specific aliases and functions
alias rm='rm -i'
#alias cp='cp -i'
alias mv='mv -i'
source ~/.bashrc

Method 2: Add a slash in front of the cp command

\cp -rf srcdir dstpath

Expand knowledge:

Linux cp (English Quanpin: copy file) command is mainly used to copy files or directories.

Syntax

cp [options] source dest

or

cp [options] source... directory

Parameter description:

-a: This option is usually used when copying a directory. It retains links and file attributes. and copies everything under the directory. Its effect is equal to the dpR parameter combination.

-d: Keep the link when copying. The links mentioned here are equivalent to shortcuts in Windows systems.

-f: Overwrite an existing target file without giving a prompt.

-i: Contrary to the -f option, a prompt is given before overwriting the target file, asking the user to confirm whether to overwrite. The target file will be overwritten when answering y.

-p: In addition to copying the contents of the file, the modification time and access permissions are also copied to the new file.

-r: If the given source file is a directory file, all subdirectories and files in the directory will be copied.

-l: Do not copy files, just generate link files.

Recommended learning: Linux video tutorial

The above is the detailed content of How to set the cp command in Linux without prompting. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn