0

我正在对该目录中的所有文件使用 rsync 递归(也包括子目录中的所有文件):

rathi/20090209.02s1.1_sequence.txt
rathi/20090209.02s1.2_sequence.txt
rathi/20090729.02s4.2_sequence.txt.gz
rathi/Homo_sapiens_UCSC_hg19.tar.gz
rathi/SRR002321.fastq.bz2
rathi/SRR002322.fastq.bz2
rathi/SRR002323.fastq.bz2
rathi/SRR002324.fastq
rathi/SRR002324.fastq.bz2
rathi/human_g1k_v37.fasta.gz
rathi/s_1_1_sequence.txt
rathi/s_1_sequence.txt
rathi/tesssssssssssssssssssssssssssssstttttttt.txt
rathi/test_data.tar.gz
rathi/Homo_sapiens
rathi/Homo_sapiens/UCSC
rathi/Homo_sapiens/UCSC/hg19
rathi/Homo_sapiens/UCSC/hg19/Annotation
rathi/Homo_sapiens/UCSC/hg19/Annotation/Archives
rathi/Homo_sapiens/UCSC/hg19/Annotation/Archives/ok.txt

我对此有一个问题。目录列表如

rathi/Homo_sapiens/UCSC
rathi/Homo_sapiens/UCSC/hg19
rathi/Homo_sapiens/UCSC/hg19/Annotation
rathi/Homo_sapiens/UCSC/hg19/Annotation/Archives 

对我没用。我只想获取带有文件的路径。这种事情是否可能仅与 rsync 一起使用?我subprocess.call用来在 Python 中调用 rsync 。

所以,我希望我的输出是这样的:

rathi/20090209.02s1.1_sequence.txt
rathi/20090209.02s1.2_sequence.txt
rathi/20090729.02s4.2_sequence.txt.gz
rathi/Homo_sapiens_UCSC_hg19.tar.gz
rathi/SRR002321.fastq.bz2
rathi/SRR002322.fastq.bz2
rathi/SRR002323.fastq.bz2
rathi/SRR002324.fastq
rathi/SRR002324.fastq.bz2
rathi/human_g1k_v37.fasta.gz
rathi/s_1_1_sequence.txt
rathi/s_1_sequence.txt
rathi/tesssssssssssssssssssssssssssssstttttttt.txt
rathi/test_data.tar.gz
rathi/Homo_sapiens/UCSC/hg19/Annotation/Archives/ok.txt
4

3 回答 3

0

If you want to skip everything which is below a directory, you can do

rsync -avz --exclude '*/' source_directory destination_directory

If you want skip all the empty directories, you can use

rsync -avz --prune-empty-dirs source_directory destination_directory

But it is not clear to me what exactly you want to achieve. You want to skip directories, but not the files in them, where do you want to sync them then if you didn't sync the directory? Or is this just about the output on the screen?

If you just want to change the output on the screen, you can pipe it through grep, i.e.

rsync -avz source_directory destination_directory | grep "\."

Then you will only see lines with a .. Note that you have to escape ., as it otherwise stands for a wildcard. Of course, this assumes that you don't have any dots in your directory names.

于 2013-06-14T07:06:21.587 回答
0

使用 os.walk ,它将列出所有文件。

import os
for root, dirnames, filenames in os.walk('rathi')
       print filenames

它将列出所有文件名。

于 2013-06-14T08:04:02.333 回答
-1

May option --filter help you?

rsync --filter=- */

于 2013-06-14T07:07:25.003 回答