cp

将一个或多个文件复制到另一个位置

语法

  cp [options]... Source Dest
  cp [options]... Source... Directory

选项

-a, --archive                与-dpR相同

-b, --backup                 在删除之前进行备份

-d, --no-dereference         保留链接

-f, --force                  删除现有目标,永不提示

-i, --interactive            覆盖前的交互式提示

-l, --link                   链接文件而不是复制

-p, --preserve               尽可能保留文件属性

-P, --parents                将源路径附加到DIRECTORY

-r                           以递归方式复制

-R, --recursive              递归复制目录

-s, --symbolic-link          制作符号链接而不是复制

-S, --suffix=SUFFIX          覆盖通常的备份后缀

-u, --update                 仅当SOURCE文件较新时才更新

-v, --verbose                解释正在做什么

-V, --version-control=WORD   覆盖通常的版本控制

-x, --one-file-system        停留在此文件系统上
  --help                     显示帮助并退出
  --version                  输出版本信息并退出

例子

将demofile复制到demofile.bak :

$ cp demofile demofile.bak
or
$ cp demofile{,.bak}

使用变量确保引用所有内容:

$ cp "$SOURCE" "$DEST"

将demofile.txt复制到demofile.bak :

$ FILE="demofile.txt"
$ cp "$FILE" "${FILE%.*}.bak"

将软盘复制到主目录:

$ cp -f /mnt/floppy/* ~

将所有.jpg文件复制到CA文件夹,对于文件名中包含“New York”的文件,替换为“California _ ”

$ mkdir CA
$ for f in *.jpg; do cp "$f" "CA/${f/New York/California_}"; done

cp 命令实例:

linux命令:cp -a ~/.bash_history ~/.bash_history.bak && perl -ne 'print unless $seen{$_}++' ~/.bash_history.bak >~/.bash_history >~/.bash_history ~/.bash_history.bak $seen{$_}++' unless 'print -ne perl && ~/.bash_history.bak ~/.bash_history -a cp cp -a ~/.bash_history ~/.bash_history.bak && perl -ne 'print unless $seen{$_}++' ~/.bash_history.bak >~/.bash_historyrootopen.com
linux命令:cp -a ~/.bash_history ~/.bash_history.bak && perl -ne 'print unless $seen{$_}++' ~/.bash_history.bak >~/.bash_history >~/.bash_history ~/.bash_history.bak $seen{$_}++' unless 'print -ne perl && ~/.bash_history.bak ~/.bash_history -a cp cp -a ~/.bash_history ~/.bash_history.bak && perl -ne 'print unless $seen{$_}++' ~/.bash_history.bak >~/.bash_historyrootopen.com
2019-06-04 22:22:40

linux命令:cp /home/tecmint/file1 /home/tecmint/Personal/ /home/tecmint/Personal/ /home/tecmint/file1 cp cp /home/tecmint/file1 /home/tecmint/Personal/rootopen.com
linux命令:cp /home/tecmint/file1 /home/tecmint/Personal/ /home/tecmint/Personal/ /home/tecmint/file1 cp cp /home/tecmint/file1 /home/tecmint/Personal/rootopen.com
2018-08-22 22:31:32

linux命令:cpio --extract < /dev/fd0 /dev/fd0 < --extract cpio cpio --extract < /dev/fd0rootopen.com
linux命令:cpio --extract < /dev/fd0 /dev/fd0 < --extract cpio cpio --extract < /dev/fd0rootopen.com
2018-07-28 11:16:11

linux命令:cp -pr /home/fedoracore5/ test/fedoracore5 test/fedoracore5 /home/fedoracore5/ -pr cp cp -pr /home/fedoracore5/ test/fedoracore5rootopen.com
linux命令:cp -pr /home/fedoracore5/ test/fedoracore5 test/fedoracore5 /home/fedoracore5/ -pr cp cp -pr /home/fedoracore5/ test/fedoracore5rootopen.com
2018-07-27 22:20:28

linux命令:cp -vs linux.txt linux-link.txt linux-link.txt linux.txt -vs cp cp -vs linux.txt linux-link.txtrootopen.com
linux命令:cp -vs linux.txt linux-link.txt linux-link.txt linux.txt -vs cp cp -vs linux.txt linux-link.txtrootopen.com
2018-07-27 22:18:41

linux命令:cp –a directory new_directory new_directory directory –a cp cp –a directory new_directoryrootopen.com
linux命令:cp –a directory new_directory new_directory directory –a cp cp –a directory new_directoryrootopen.com
2018-07-27 22:17:20

linux命令:cp file.txt{,.bak} file.txt{,.bak} cp cp file.txt{,.bak}rootopen.com
linux命令:cp file.txt{,.bak} file.txt{,.bak} cp cp file.txt{,.bak}rootopen.com
2018-03-03 04:05:48

linux命令:cp -p file-you-want-backup{,_`date +%Y%m%d`} # for bash bash for # +%Y%m%d`} file-you-want-backup{,_`date -p cp cp -p file-you-want-backup{,_`date +%Y%m%d`} # for bashrootopen.com
linux命令:cp -p file-you-want-backup{,_`date +%Y%m%d`} # for bash bash for # +%Y%m%d`} file-you-want-backup{,_`date -p cp cp -p file-you-want-backup{,_`date +%Y%m%d`} # for bashrootopen.com
2018-03-09 02:52:48

linux命令:cp -pr directory-you-want-to-backup{,_`date +%Y%m%d`} # for bash bash for # +%Y%m%d`} directory-you-want-to-backup{,_`date -pr cp cp -pr directory-you-want-to-backup{,_`date +%Y%m%d`} # for bashrootopen.com
linux命令:cp -pr directory-you-want-to-backup{,_`date +%Y%m%d`} # for bash bash for # +%Y%m%d`} directory-you-want-to-backup{,_`date -pr cp cp -pr directory-you-want-to-backup{,_`date +%Y%m%d`} # for bashrootopen.com
2018-04-11 11:29:48

linux命令:cp /really/long/path/and/file/name{,-`date -I`} -I`} /really/long/path/and/file/name{,-`date cp cp /really/long/path/and/file/name{,-`date -I`}rootopen.com
linux命令:cp /really/long/path/and/file/name{,-`date -I`} -I`} /really/long/path/and/file/name{,-`date cp cp /really/long/path/and/file/name{,-`date -I`}rootopen.com
2018-02-26 01:59:48

linux命令:cp /some/path/to/myfile{,.back} /some/path/to/myfile{,.back} cp cp /some/path/to/myfile{,.back}rootopen.com
linux命令:cp /some/path/to/myfile{,.back} /some/path/to/myfile{,.back} cp cp /some/path/to/myfile{,.back}rootopen.com
2018-05-30 03:08:48

linux命令:cp --backup=t source.file target.file target.file source.file --backup=t cp cp --backup=t source.file target.filerootopen.com
linux命令:cp --backup=t source.file target.file target.file source.file --backup=t cp cp --backup=t source.file target.filerootopen.com
2018-02-18 08:22:48

linux命令:cp ./* .[!.]* ..?* /path/to/dir /path/to/dir ..?* .[!.]* ./* cp cp ./* .[!.]* ..?* /path/to/dirrootopen.com
linux命令:cp ./* .[!.]* ..?* /path/to/dir /path/to/dir ..?* .[!.]* ./* cp cp ./* .[!.]* ..?* /path/to/dirrootopen.com
2018-02-16 14:01:48

linux命令:cp --parents /source/file /target-dir /target-dir /source/file --parents cp cp --parents /source/file /target-dirrootopen.com
linux命令:cp --parents /source/file /target-dir /target-dir /source/file --parents cp cp --parents /source/file /target-dirrootopen.com
2018-01-20 11:53:48

linux命令:cpp /usr/include/stdio.h | grep -v '^#' | grep -v '^$' | less less | '^$' -v grep | '^#' -v grep | /usr/include/stdio.h cpp cpp /usr/include/stdio.h | grep -v '^#' | grep -v '^$' | lessrootopen.com
linux命令:cpp /usr/include/stdio.h | grep -v '^#' | grep -v '^$' | less less | '^$' -v grep | '^#' -v grep | /usr/include/stdio.h cpp cpp /usr/include/stdio.h | grep -v '^#' | grep -v '^$' | lessrootopen.com
2018-04-01 09:21:48

linux命令:cp `ls -x1tr *.jpg | tail -n 1` newest.jpg newest.jpg 1` -n tail | *.jpg -x1tr `ls cp cp `ls -x1tr *.jpg | tail -n 1` newest.jpgrootopen.com
linux命令:cp `ls -x1tr *.jpg | tail -n 1` newest.jpg newest.jpg 1` -n tail | *.jpg -x1tr `ls cp cp `ls -x1tr *.jpg | tail -n 1` newest.jpgrootopen.com
2018-04-03 14:50:48

linux命令:cp -bfS.bak filename filename filename filename -bfS.bak cp cp -bfS.bak filename filenamerootopen.com
linux命令:cp -bfS.bak filename filename filename filename -bfS.bak cp cp -bfS.bak filename filenamerootopen.com
2018-03-07 03:22:48

linux命令:cp texfile.toc texfile.toc.bak; latex texfile.tex; cmp -s texfile.toc texfile.toc.bak; if [ $? -ne 0 ]; then latex texfile.tex; fi fi texfile.tex; latex then ]; 0 -ne $? [ if texfile.toc.bak; texfile.toc -s cmp texfile.tex; latex texfile.toc.bak; texfile.toc cp cp texfile.toc texfile.toc.bak; latex texfile.tex; cmp -s texfile.toc texfile.toc.bak; if [ $? -ne 0 ]; then latex texfile.tex; firootopen.com
linux命令:cp texfile.toc texfile.toc.bak; latex texfile.tex; cmp -s texfile.toc texfile.toc.bak; if [ $? -ne 0 ]; then latex texfile.tex; fi fi texfile.tex; latex then ]; 0 -ne $? [ if texfile.toc.bak; texfile.toc -s cmp texfile.tex; latex texfile.toc.bak; texfile.toc cp cp texfile.toc texfile.toc.bak; latex texfile.tex; cmp -s texfile.toc texfile.toc.bak; if [ $? -ne 0 ]; then latex texfile.tex; firootopen.com
2018-03-11 02:56:48

linux命令:cp path/filename{,-$(date +%Y-%m-%d)} +%Y-%m-%d)} path/filename{,-$(date cp cp path/filename{,-$(date +%Y-%m-%d)}rootopen.com
linux命令:cp path/filename{,-$(date +%Y-%m-%d)} +%Y-%m-%d)} path/filename{,-$(date cp cp path/filename{,-$(date +%Y-%m-%d)}rootopen.com
2018-01-21 20:02:48

linux命令:cp -pr olddirectory newdirectory newdirectory olddirectory -pr cp cp -pr olddirectory newdirectoryrootopen.com
linux命令:cp -pr olddirectory newdirectory newdirectory olddirectory -pr cp cp -pr olddirectory newdirectoryrootopen.com
2018-05-02 09:42:48

linux命令:cpan -r -r cpan cpan -rrootopen.com
linux命令:cpan -r -r cpan cpan -rrootopen.com
2018-05-14 07:05:48

linux命令:cp -arv ~/Documents/{foo,bar} --target-directory=~/buzz/ --target-directory=~/buzz/ ~/Documents/{foo,bar} -arv cp cp -arv ~/Documents/{foo,bar} --target-directory=~/buzz/rootopen.com
linux命令:cp -arv ~/Documents/{foo,bar} --target-directory=~/buzz/ --target-directory=~/buzz/ ~/Documents/{foo,bar} -arv cp cp -arv ~/Documents/{foo,bar} --target-directory=~/buzz/rootopen.com
2018-05-29 18:50:48

linux命令:cp "/var/lib/mpd/music/`mpc --format '%file%' | head -n1`" /some/where/else /some/where/else -n1`" head | '%file%' --format "/var/lib/mpd/music/`mpc cp cp "/var/lib/mpd/music/`mpc --format '%file%' | head -n1`" /some/where/elserootopen.com
linux命令:cp "/var/lib/mpd/music/`mpc --format '%file%' | head -n1`" /some/where/else /some/where/else -n1`" head | '%file%' --format "/var/lib/mpd/music/`mpc cp cp "/var/lib/mpd/music/`mpc --format '%file%' | head -n1`" /some/where/elserootopen.com
2018-02-26 01:47:48

linux命令:cp -n <src> <dst> <dst> <src> -n cp cp -n <src> <dst>rootopen.com
linux命令:cp -n <src> <dst> <dst> <src> -n cp cp -n <src> <dst>rootopen.com
2018-05-21 14:50:48

linux命令:cp_p() { if [ `echo "$2" | grep ".*\/$"` ]; then pv "$1" > "$2""$1"; else pv "$1" > "$2"/"$1"; fi; } } fi; "$2"/"$1"; > "$1" pv else "$2""$1"; > "$1" pv then ]; ".*\/$"` grep | "$2" `echo [ if { cp_p() cp_p() { if [ `echo "$2" | grep ".*\/$"` ]; then pv "$1" > "$2""$1"; else pv "$1" > "$2"/"$1"; fi; }rootopen.com
linux命令:cp_p() { if [ `echo "$2" | grep ".*\/$"` ]; then pv "$1" > "$2""$1"; else pv "$1" > "$2"/"$1"; fi; } } fi; "$2"/"$1"; > "$1" pv else "$2""$1"; > "$1" pv then ]; ".*\/$"` grep | "$2" `echo [ if { cp_p() cp_p() { if [ `echo "$2" | grep ".*\/$"` ]; then pv "$1" > "$2""$1"; else pv "$1" > "$2"/"$1"; fi; }rootopen.com
2018-01-03 01:58:48

linux命令:cp -i FILENAME{,.`date +%Y%m%d`} +%Y%m%d`} FILENAME{,.`date -i cp cp -i FILENAME{,.`date +%Y%m%d`}rootopen.com
linux命令:cp -i FILENAME{,.`date +%Y%m%d`} +%Y%m%d`} FILENAME{,.`date -i cp cp -i FILENAME{,.`date +%Y%m%d`}rootopen.com
2018-01-30 02:12:48

linux命令:cp -av source dest dest source -av cp cp -av source destrootopen.com
linux命令:cp -av source dest dest source -av cp cp -av source destrootopen.com
2018-03-20 18:21:48

linux命令:cp filename{,.`date +%Y%m%d`} +%Y%m%d`} filename{,.`date cp cp filename{,.`date +%Y%m%d`}rootopen.com
linux命令:cp filename{,.`date +%Y%m%d`} +%Y%m%d`} filename{,.`date cp cp filename{,.`date +%Y%m%d`}rootopen.com
2018-01-16 18:21:48

linux命令:cp /dev/cdrom file.iso file.iso /dev/cdrom cp cp /dev/cdrom file.isorootopen.com
linux命令:cp /dev/cdrom file.iso file.iso /dev/cdrom cp cp /dev/cdrom file.isorootopen.com
2018-04-10 03:41:48

linux命令:cp httpd.conf{,.bk} httpd.conf{,.bk} cp cp httpd.conf{,.bk}rootopen.com
linux命令:cp httpd.conf{,.bk} httpd.conf{,.bk} cp cp httpd.conf{,.bk}rootopen.com
2018-05-04 14:46:48

linux命令:cp -dpRx /* /mnt/target/ /mnt/target/ /* -dpRx cp cp -dpRx /* /mnt/target/rootopen.com
linux命令:cp -dpRx /* /mnt/target/ /mnt/target/ /* -dpRx cp cp -dpRx /* /mnt/target/rootopen.com
2017-12-27 18:45:48

linux命令:cp --sparse=always <SRC> <DST> <DST> <SRC> --sparse=always cp cp --sparse=always <SRC> <DST>rootopen.com
linux命令:cp --sparse=always <SRC> <DST> <DST> <SRC> --sparse=always cp cp --sparse=always <SRC> <DST>rootopen.com
2018-05-16 00:14:48

linux命令:cp /work/host/phone/ui/main.cpp !#$:s/host/target !#$:s/host/target /work/host/phone/ui/main.cpp cp cp /work/host/phone/ui/main.cpp !#$:s/host/targetrootopen.com
linux命令:cp /work/host/phone/ui/main.cpp !#$:s/host/target !#$:s/host/target /work/host/phone/ui/main.cpp cp cp /work/host/phone/ui/main.cpp !#$:s/host/targetrootopen.com
2018-02-19 00:36:48

linux命令:cpo(){ [[ $# -lt 2 ]] && echo 'need IP and port' && return 2; [[ `wget -q "http://dnstools.com/?count=3&checkp=on&portNum=$2&target=$1&submit=Go\!" -O - |grep -ic "Connected successfully to port $2"` -gt 0 ]] && return 0 || return 1; } } 1; return || 0 return && ]] 0 -gt $2"` port to successfully "Connected -ic |grep - -O "http://dnstools.com/?count=3&checkp=on&portNum=$2&target=$1&submit=Go\!" -q `wget [[ 2; return && port' and IP 'need echo && ]] 2 -lt $# [[ cpo(){ cpo(){ [[ $# -lt 2 ]] && echo 'need IP and port' && return 2; [[ `wget -q "http://dnstools.com/?count=3&checkp=on&portNum=$2&target=$1&submit=Go\!" -O - |grep -ic "Connected successfully to port $2"` -gt 0 ]] && return 0 || return 1; }rootopen.com
linux命令:cpo(){ [[ $# -lt 2 ]] && echo 'need IP and port' && return 2; [[ `wget -q "http://dnstools.com/?count=3&checkp=on&portNum=$2&target=$1&submit=Go\!" -O - |grep -ic "Connected successfully to port $2"` -gt 0 ]] && return 0 || return 1; } } 1; return || 0 return && ]] 0 -gt $2"` port to successfully "Connected -ic |grep - -O "http://dnstools.com/?count=3&checkp=on&portNum=$2&target=$1&submit=Go\!" -q `wget [[ 2; return && port' and IP 'need echo && ]] 2 -lt $# [[ cpo(){ cpo(){ [[ $# -lt 2 ]] && echo 'need IP and port' && return 2; [[ `wget -q "http://dnstools.com/?count=3&checkp=on&portNum=$2&target=$1&submit=Go\!" -O - |grep -ic "Connected successfully to port $2"` -gt 0 ]] && return 0 || return 1; }rootopen.com
2018-03-09 10:29:48

linux命令:cp -a /etc /destination /destination /etc -a cp cp -a /etc /destinationrootopen.com
linux命令:cp -a /etc /destination /destination /etc -a cp cp -a /etc /destinationrootopen.com
2018-06-03 19:36:48

linux命令:cp -r * .??* /dest /dest .??* * -r cp cp -r * .??* /destrootopen.com
linux命令:cp -r * .??* /dest /dest .??* * -r cp cp -r * .??* /destrootopen.com
2018-05-02 02:11:48

linux命令:cpupower frequency-info frequency-info cpupower cpupower frequency-inforootopen.com
linux命令:cpupower frequency-info frequency-info cpupower cpupower frequency-inforootopen.com
2018-03-06 14:45:48

linux命令:cp -auv /SorceDirectory/ /ParentDestination/ /ParentDestination/ /SorceDirectory/ -auv cp cp -auv /SorceDirectory/ /ParentDestination/rootopen.com
linux命令:cp -auv /SorceDirectory/ /ParentDestination/ /ParentDestination/ /SorceDirectory/ -auv cp cp -auv /SorceDirectory/ /ParentDestination/rootopen.com
2018-03-11 15:00:48

linux命令:cp -r path/to/file/tree $(mkdir -p new/path/here; echo new/path/here) new/path/here) echo new/path/here; -p $(mkdir path/to/file/tree -r cp cp -r path/to/file/tree $(mkdir -p new/path/here; echo new/path/here)rootopen.com
linux命令:cp -r path/to/file/tree $(mkdir -p new/path/here; echo new/path/here) new/path/here) echo new/path/here; -p $(mkdir path/to/file/tree -r cp cp -r path/to/file/tree $(mkdir -p new/path/here; echo new/path/here)rootopen.com
2018-04-02 11:13:48

linux命令:cp $(find /media/ -type f -name "*.wav" -printf "%T@ %h/%f\n" | sort | tail -1 | awk '{ print $2 }') . . }') $2 print '{ awk | -1 tail | sort | %h/%f\n" "%T@ -printf "*.wav" -name f -type /media/ $(find cp cp $(find /media/ -type f -name "*.wav" -printf "%T@ %h/%f\n" | sort | tail -1 | awk '{ print $2 }') .rootopen.com
linux命令:cp $(find /media/ -type f -name "*.wav" -printf "%T@ %h/%f\n" | sort | tail -1 | awk '{ print $2 }') . . }') $2 print '{ awk | -1 tail | sort | %h/%f\n" "%T@ -printf "*.wav" -name f -type /media/ $(find cp cp $(find /media/ -type f -name "*.wav" -printf "%T@ %h/%f\n" | sort | tail -1 | awk '{ print $2 }') .rootopen.com
2018-03-26 05:44:48

linux命令:cp -rf srcdir/* destdir destdir srcdir/* -rf cp cp -rf srcdir/* destdirrootopen.com
linux命令:cp -rf srcdir/* destdir destdir srcdir/* -rf cp cp -rf srcdir/* destdirrootopen.com
2018-04-27 07:44:48

linux命令:cp foo.txt foo.txt.tmp; sed '$ d' foo.txt.tmp > foo.txt; rm -f foo.txt.tmp foo.txt.tmp -f rm foo.txt; > foo.txt.tmp d' '$ sed foo.txt.tmp; foo.txt cp cp foo.txt foo.txt.tmp; sed '$ d' foo.txt.tmp > foo.txt; rm -f foo.txt.tmprootopen.com
linux命令:cp foo.txt foo.txt.tmp; sed '$ d' foo.txt.tmp > foo.txt; rm -f foo.txt.tmp foo.txt.tmp -f rm foo.txt; > foo.txt.tmp d' '$ sed foo.txt.tmp; foo.txt cp cp foo.txt foo.txt.tmp; sed '$ d' foo.txt.tmp > foo.txt; rm -f foo.txt.tmprootopen.com
2018-02-23 14:47:48

linux命令:cp -p `ls -l | awk '/Apr 14/ {print $NF}'` /usr/users/backup_dir /usr/users/backup_dir $NF}'` {print 14/ '/Apr awk | -l `ls -p cp cp -p `ls -l | awk '/Apr 14/ {print $NF}'` /usr/users/backup_dirrootopen.com
linux命令:cp -p `ls -l | awk '/Apr 14/ {print $NF}'` /usr/users/backup_dir /usr/users/backup_dir $NF}'` {print 14/ '/Apr awk | -l `ls -p cp cp -p `ls -l | awk '/Apr 14/ {print $NF}'` /usr/users/backup_dirrootopen.com
2018-06-03 01:19:48

linux命令:cpan Devel::REPL; re.pl re.pl Devel::REPL; cpan cpan Devel::REPL; re.plrootopen.com
linux命令:cpan Devel::REPL; re.pl re.pl Devel::REPL; cpan cpan Devel::REPL; re.plrootopen.com
2018-05-25 11:39:48

linux命令:cp foo{,bak} foo{,bak} cp cp foo{,bak}rootopen.com
linux命令:cp foo{,bak} foo{,bak} cp cp foo{,bak}rootopen.com
2018-01-02 15:00:48

linux命令:cp filename{,.`date +%Y%m%d-%H%M%S`} +%Y%m%d-%H%M%S`} filename{,.`date cp cp filename{,.`date +%Y%m%d-%H%M%S`}rootopen.com
linux命令:cp filename{,.`date +%Y%m%d-%H%M%S`} +%Y%m%d-%H%M%S`} filename{,.`date cp cp filename{,.`date +%Y%m%d-%H%M%S`}rootopen.com
2018-05-11 00:27:48

linux命令:cp -p file.txt{,.bak} file.txt{,.bak} -p cp cp -p file.txt{,.bak}rootopen.com
linux命令:cp -p file.txt{,.bak} file.txt{,.bak} -p cp cp -p file.txt{,.bak}rootopen.com
2018-05-05 08:08:48

linux命令:cp -Rs dir1 dir2 dir2 dir1 -Rs cp cp -Rs dir1 dir2rootopen.com
linux命令:cp -Rs dir1 dir2 dir2 dir1 -Rs cp cp -Rs dir1 dir2rootopen.com
2018-03-31 23:58:48

linux命令:cp -a file_to_backup{,-$(date +%F)} +%F)} file_to_backup{,-$(date -a cp cp -a file_to_backup{,-$(date +%F)}rootopen.com
linux命令:cp -a file_to_backup{,-$(date +%F)} +%F)} file_to_backup{,-$(date -a cp cp -a file_to_backup{,-$(date +%F)}rootopen.com
2018-01-28 16:21:48

Linux的Bash命令行(A-Z排序)