Peter Ahn
Peter의 우아한 프로그래밍
Peter Ahn
전체 방문자
오늘
어제
  • 전체 (115)
    • 영어공부 (15)
    • 물생활 (9)
    • 독서 (2)
    • 일상 (1)
    • IT 소식 (15)
      • 최신 기술 소식 (10)
      • 보안 소식 (5)
    • 인공지능 (AI) (2)
    • OS (19)
      • Linux (19)
    • Web (0)
      • Vue.js (0)
    • 객체지향 (1)
      • 개념과 원리 (1)
      • 디자인패턴 (0)
    • 프로그래밍 (37)
      • C (14)
      • C++ (3)
      • C# (1)
      • Python (3)
      • Javascript (2)
      • Bash (4)
      • Vim (9)
    • Database (3)
      • DB2 (3)
      • MongoDB (0)
    • 프레임워크 (1)
      • Ionic (1)
    • Cloud (1)
      • AWS (1)
    • 3D Printer (2)
    • 기록보관소 (5)
    • 초대장 (2)

블로그 메뉴

  • 홈
  • 태그
  • 미디어로그
  • 위치로그
  • 방명록

공지사항

  • 프로그래밍의 세계에 오신 것을 환영합니다.

인기 글

태그

  • 프로그래밍
  • C언어
  • vim 강좌
  • 어항
  • 쉘 프로그래밍
  • C++
  • 영어 표현
  • c강좌
  • vim 비주얼모드
  • call by reference
  • 영어 회화
  • 구피
  • vim
  • 랜섬웨어
  • bash
  • 리눅스 명령어
  • bash shell
  • typescript
  • 하프블랙구피
  • 생활영어
  • 물생활
  • 리눅스
  • 딥러닝
  • 4차 산업혁명
  • 인공지능
  • C언어 강좌
  • AI
  • 구피어항
  • Linux
  • 영어표현

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Peter Ahn

Peter의 우아한 프로그래밍

[Linux] cp 파일 및 디렉토리 복사
OS/Linux

[Linux] cp 파일 및 디렉토리 복사

2018. 5. 3. 09:36
반응형

개요

cp 명령어는 리눅스에서 파일을 복사하는 명령어입니다.

윈도우 환경에서는 마우스로 드래그&드롭을 활용하여 파일 복사를 쉽게 할 수 있습니다.

일반적으로 리눅스 서버 환경에서는 Desktop GUI 환경을 사용하지 않기 때문에 마우스 없이 파일을 복사해야 합니다.

콘솔에서 명령어를 수행해서 말이죠.

익숙해지면 윈도우에서 파일 복사하는 것보다 훨씬 복잡한 명령어도 빠르게 수행할 수 있습니다.


사용법

리눅스에서 사용되는 명령어는 모두 대소문자를 구분하니 주의해주세요.

cp 명령어에 대한 자세한 설명은 cp --help 명령어를 통해 볼 수 있습니다. 

Usage: cp [OPTION]... [-T] SOURCE DEST
  or:  cp [OPTION]... SOURCE... DIRECTORY
  or:  cp [OPTION]... -t DIRECTORY SOURCE...

Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.


Options
Mandatory arguments to long options are mandatory for short options too.
  -a, --archive                same as -dR --preserve=all
      --attributes-only        don't copy the file data, just the attributes
      --backup[=CONTROL]       make a backup of each existing destination file
  -b                           like --backup but does not accept an argument
      --copy-contents          copy contents of special files when recursive
  -d                           same as --no-dereference --preserve=links
  -f, --force                  if an existing destination file cannot be
                                 opened, remove it and try again (this option
                                 is ignored when the -n option is also used)
  -i, --interactive            prompt before overwrite (overrides a previous -n
                                  option)
  -H                           follow command-line symbolic links in SOURCE
  -l, --link                   hard link files instead of copying
  -L, --dereference            always follow symbolic links in SOURCE
  -n, --no-clobber             do not overwrite an existing file (overrides
                                 a previous -i option)
  -P, --no-dereference         never follow symbolic links in SOURCE
  -p                           same as --preserve=mode,ownership,timestamps
      --preserve[=ATTR_LIST]   preserve the specified attributes (default:
                                 mode,ownership,timestamps), if possible
                                 additional attributes: context, links, xattr,
                                 all
  -c                           deprecated, same as --preserve=context
      --no-preserve=ATTR_LIST  don't preserve the specified attributes
      --parents                use full source file name under DIRECTORY
  -R, -r, --recursive          copy directories recursively
      --reflink[=WHEN]         control clone/CoW copies. See below
      --remove-destination     remove each existing destination file before
                                 attempting to open it (contrast with --force)
      --sparse=WHEN            control creation of sparse files. See below
      --strip-trailing-slashes  remove any trailing slashes from each SOURCE
                                 argument
  -s, --symbolic-link          make symbolic links instead of copying
  -S, --suffix=SUFFIX          override the usual backup suffix
  -t, --target-directory=DIRECTORY  copy all SOURCE arguments into DIRECTORY
  -T, --no-target-directory    treat DEST as a normal file
  -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
  -x, --one-file-system        stay on this file system
  -Z                           set SELinux security context of destination
                                 file to default type
      --context[=CTX]          like -Z, or if CTX is specified then set the
                                 SELinux or SMACK security context to CTX
      --help     display this help and exit
      --version  output version information and exit

주로 사용하는 옵션으로는 하위 디렉토리 및 파일들을 재귀적으로 모두 복사하는 -r 옵션과 복사 과정을 출력하는 -v 최신 파일로 업데이트 해주는 -u 옵션 등이 있습니다.


ex) source 디렉토리 내의 파일과 하위의 모든 디렉토리와 파일을 dest 통째로 복사

cp -r source/ dest/

(source 디렉토리를 dest로 통째로 복사)


ex) 대상 경로에 존재하지 않는 파일이나 복사하려는 파일이 더 최신인 경우에만 복사 (업데이트)

cp -r -u source/ dest/



 

 

-Peter의 우아한 프로그래밍

반응형
저작자표시 비영리 동일조건 (새창열림)

'OS > Linux' 카테고리의 다른 글

[Linux] mv 파일 및 디렉토리 이동  (0) 2018.05.09
[Linux] find 로 파일 찾아서 지우기  (5) 2018.05.08
[Linux] find 로 파일 검색하기  (0) 2018.05.05
[Linux] cp 또는 mv 로 파일 강제로 덮어쓰기  (1) 2018.05.03
[Linux] ls (파일 목록 보기)  (0) 2017.04.03
    'OS/Linux' 카테고리의 다른 글
    • [Linux] find 로 파일 찾아서 지우기
    • [Linux] find 로 파일 검색하기
    • [Linux] cp 또는 mv 로 파일 강제로 덮어쓰기
    • [Linux] ls (파일 목록 보기)
    Peter Ahn
    Peter Ahn
    IT 정보 공유, 프로그래밍 지식 공유

    티스토리툴바