【问题标题】:Finding if a folder is in copying process on linux在linux上查找文件夹是否正在复制过程中
【发布时间】:2016-05-27 15:25:13
【问题描述】:

有什么方法可以查出一个文件夹是否正在复制过程中?

更具体一点:

我在共享驱动器中有一个文件夹被其他人复制到那里,我需要使用它,但是在我访问它的那一刻(让我们承认我检查了 之前的存在,没关系)复制过程可能仍在进行中。

我想通过 bash/python 脚本检查这个。

【问题讨论】:

    标签: linux process operating-system


    【解决方案1】:

    试试lsof - 列出打开的文件

    lsof +d /path/to/some/directory
    

    这是一个带有大量副本的示例:

    mkdir /tmp/big
    cd /tmp/big
    
    # Create 1 Gb file
    perl -e 'for(1..10000000) { print "x"x100 . "\n" }' > huge
    
    # Start cp process in background, it will take a few seconds
    cp -r /tmp/big /tmp/huge &
    
    $ lsof +d /tmp/big
    COMMAND  PID  USER   FD   TYPE DEVICE   SIZE/OFF    NODE NAME
    cp      4291 felix    3r   REG    8,1 1010000000 2752741 /tmp/big/huge
    

    man lsof

    【讨论】:

      猜你喜欢
      • 2020-02-03
      • 2018-06-13
      • 2015-01-09
      • 1970-01-01
      • 1970-01-01
      • 2017-09-04
      • 2014-06-15
      • 2015-11-06
      • 2014-04-04
      相关资源
      最近更新 更多