rsync가 소스의 하위 폴더에서 파일을 복사하지 않는 이유를 누가 말해 줄 수 있습니까? [복사]

rsync가 소스의 하위 폴더에서 파일을 복사하지 않는 이유를 누가 말해 줄 수 있습니까? [복사]

rsync현재 폴더의 모든 TIF 이미지 파일을 "Documents" 아래의 "HR" 폴더로 복사하려고 했지만 지금까지 성공하지 못했습니다.

rsync -r *.tif /home/myusername/Documents/HR

내가 볼 수 있듯이 -r옵션은 재귀 복사를 위한 것이지만 이 명령은 현재 폴더에 있는 모든 TIF 파일만 복사합니다.

누구든지 내가 어디로 잘못 가고 있는지 말해 줄 수 있습니까?

현재 폴더에는 수백 개의 TIF 파일이 포함된 다중 계층 하위 폴더가 많이 있습니다.

답변1

*쉘에 의해 확장되는 명령줄에 와일드카드( )가 있으므로 rsync현재 디렉토리에 있는 TIFF 파일 목록을 가져오는 것을 볼 수 있습니다. 예를 들어 명령줄은 다음과 같이 확장될 수 있습니다.

rsync -r cry.tif frown.tif smile.tif /home/myusername/Documents/HR

이러한 TIFF 파일은 디렉터리가 아니므로 rsync해당 파일로 재귀할 수 있는 방법이 없습니다.

반면에 이것을 시도하면 rsync디렉토리를 찾고 그 디렉토리로 재귀적으로 들어갈 수 있는 기회를 활용할 수 있습니다. 나는 이 -a플래그를 사용하여 파일 메타데이터(권한, 타임스탬프)를 유지합니다. 이 시도는 으로 끝나는 파일뿐만 아니라 모든 파일을 복사 .tif하지만 충분할 경우 이해하기 쉬운 솔루션은 다음과 같습니다.

rsync -a . /home/myusername/Documents/HR/

이제 퍼즐의 마지막 부분이 다가옵니다. ( 일치하는) TIFF 파일만 복사하려면 재귀적일 수 있지만 해당 파일만 복사해야 한다고 알려야 *.tif합니다 . rsync이것은 명령의 가장 복잡한 부분이지만 rsync운 좋게도 매뉴얼 페이지에서 거의 독점적으로 예제로 인용되어 있습니다( man rsync"hidden"을 참조하고 검색하세요).

rsync -am --include '*.tif' --filter 'hide,! */' . /home/myusername/Documents/HR/

답변2

나는 보통 읽는다남성명령을 사용하기 전의 페이지입니다.

그래서 를 사용할 때는 , 또는 ( ) 및 (verbose) 와 같은 옵션을 rsync사용합니다 .-av-rlptgoDv-rlptgoD-a-v

편집(귀하의 의견 이후):

나에게도 똑같은 일이 일어났습니다. 몇 달 전에 사용법 섹션을 읽었는데, 아니나 다를까 거기에 (첫 번째 예 이후에) 다음과 같이 적혀 있었습니다 Note that the expansion of wildcards on the commandline (*.c) into a list of files is handled by the shell.... 나는 또한 그것이 -r날짜를 지키지 않고 -v편리하다는 것을 알았습니다. -av그것은 완벽하다고 생각합니다.

매뉴얼 페이지에서:

[..]
USAGE
   You use rsync in the same way you use rcp. You must specify a source and a destination, one of which may be remote.

   Perhaps the best way to explain the syntax is with some examples:

          rsync -t *.c foo:src/

   This  would  transfer  all  files matching the pattern *.c from the current directory to the directory src on the machine foo. If any of the files already exist on the remote system then the rsync remote-update protocol is used to update the file by sending
   only the differences in the data.  Note that the expansion of wildcards on the commandline (*.c) into a list of files is handled by the shell before it runs rsync and not by rsync itself (exactly the same as all other posix-style programs). 

          rsync -avz foo:src/bar /data/tmp

   This would recursively transfer all files from the directory src/bar on the machine foo into the /data/tmp/bar directory on the local machine. The files are transferred in "archive" mode, which ensures that symbolic links, devices, attributes,  permissions,
   ownerships, etc. are preserved in the transfer.  Additionally, compression will be used to reduce the size of data portions of the transfer.

          rsync -avz foo:src/bar/ /data/tmp

   A  trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination.  You can think of a trailing / on a source as meaning "copy the contents of this directory" as opposed to "copy the directory by name",
   but in both cases the attributes of the containing directory are transferred to the containing directory on the destination.  In other words, each of the following commands copies the files in the same way, including  their  setting  of  the  attributes  of
   /dest/foo:

          rsync -av /src/foo /dest
          rsync -av /src/foo/ /dest/foo
   Note also that host and module references don’t require a trailing slash to copy the contents of the default directory.  For example, both of these copy the remote directory’s contents into "/dest":

          rsync -av host: /dest
          rsync -av host::module /dest

   You can also use rsync in local-only mode, where both the source and destination don’t have a ’:’ in the name. In this case it behaves like an improved copy command.

   Finally, you can list all the (listable) modules available from a particular rsync daemon by leaving off the module name:

          rsync somehost.mydomain.com::
  [...]

관련 정보