在 linux 上查找文件夹是否处于复制过程中
Finding if a folder is in copying process on linux
有什么方法可以查明文件夹是否在复制过程中?
更具体地说:
我在共享驱动器中有一个文件夹,它被其他人复制到那里,我需要使用它,但是,在我访问它的那一刻(承认我检查过
之前存在并且没关系)复制过程可能仍在进行中。
我想从 bash/python
脚本中检查。
试试 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
有什么方法可以查明文件夹是否在复制过程中?
更具体地说:
我在共享驱动器中有一个文件夹,它被其他人复制到那里,我需要使用它,但是,在我访问它的那一刻(承认我检查过 之前存在并且没关系)复制过程可能仍在进行中。
我想从 bash/python
脚本中检查。
试试 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