cp –attributes-only를 언제 사용합니까 사용하고자 할 때 기본적인 유닉스

나는 다음과 같은 명령 줄 옵션을 사용하고자 할 때 기본적인 유닉스 명령에 대한 몇 가지 연구를 수행하고 예를 얻으려고 --attributes-only명령을cp

여기 cp맨 페이지에서

--attributes-only
              don't copy the file data, just the attributes



답변

file1동일한 속성을 가져야한다는 파일이 있다고 가정하십시오 file2( file2올바른 속성 을 가지고 있음).

$ stat file{1,2}
  File: 'file1'
  Size: 0           Blocks: 0          IO Block: 4096   regular empty file
Device: 1fh/31d Inode: 2326956     Links: 1
Access: (0600/-rw-------)  Uid: ( 1000/   chris)   Gid: ( 1000/   chris)
Access: 2013-12-24 09:53:20.248720441 +0800
Modify: 2013-12-24 09:53:20.248720441 +0800
Change: 2013-12-24 09:53:31.011984772 +0800
 Birth: -
  File: 'file2'
  Size: 0           Blocks: 0          IO Block: 4096   regular empty file
Device: 1fh/31d Inode: 2326957     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   chris)   Gid: ( 1000/   chris)
Access: 2013-12-24 09:53:21.045382001 +0800
Modify: 2013-12-24 09:53:21.045382001 +0800
Change: 2013-12-24 09:53:21.045382001 +0800
 Birth: -

일치하는지 확인하는 한 가지 방법 file2은 속성을 확인 하고 수동으로 적용하는 것입니다.

$ chmod 644 file1

그러나 이것은 자동화하고 스크립트하기가 번거 롭습니다. 속성 file2file1프로그래밍 방식으로 가져와 적용하는 것이 더 쉬울 것 입니다.

$ cp --attributes-only --preserve file2 file1
$ stat file1
  File: 'file1'
  Size: 0           Blocks: 0          IO Block: 4096   regular empty file
Device: 1fh/31d Inode: 2326956     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   chris)   Gid: ( 1000/   chris)
Access: 2013-12-24 09:53:21.045382001 +0800
Modify: 2013-12-24 09:53:21.045382001 +0800
Change: 2013-12-24 09:57:06.320604649 +0800
 Birth: -

--attributes-only그 자체로는 아무것도하지 않습니다. 다른 속성 보존 플래그와 결합되어야합니다. 보낸 사람 info cp:

--attributes-only
     Copy only the specified attributes of the source file to the
     destination.  If the destination already exists, do not alter its
     contents.  See the `--preserve' option for controlling which
     attributes to copy.

--preserve는 위에 사용되며, 이에 상응하는 것으로 문서화되어 --preserve=mode,ownership,timestamps있습니다. 내부적으로이를 “복사 속성 만”이 아니라 “데이터를 복사하지 마십시오”라고 생각할 수 있습니다 --preserve.


답변

스마트 폰이 있다면 멀리있는 PC에서 음악을 선택할 수 있습니다.

$ cp -rn --attributes-only ~/Music smartphone/Music

PC에서 멀어지면 디렉토리를 삭제하고 나중에 복사하십시오.

$ cp -rn ~/Music smartphone/Music

선택한 음악과 빈 파일이 제공됩니다.


답변