I have created a .tar.gz file for backup purposes. While it's still in the middle of being transferred via SCP (it's a 6 GB file), I accidentally deleted it in the SSH session.

The SCP transfer is still running. What happens in that case? Will the file be ok? Why? Will it be broken? If so, why doesn't the file transfer interrupt?


scp will copy your file without problems.

If you delete a film that is opened by a process only the file name gets removed but the file still exists. You can access the deleted file via a symlink in /proc/$PID/fd where $PID is the process id of the process using the file.


I had a great idea and I think I figured it out myself:

# lsof | grep www
sftp-serv 2490  root  3r  REG  253,0 6878784186   14549364 /mnt/var/www.tar.gz (deleted)

For me, this means that SCP is still accessing the file and still has a valid file handle. For anyone else, the file is deleted as indicated in parentheses. So nobody else will get a valid file handle for that deleted file handle any more.

Now, since the SCP download completed, I could check again:

# lsof | grep www

Note that the result is empty, the file handle has been closed.

On my client, I was able to unzip the .tar.gz file with 7Zip (Windows). It didn't complain about broken checksums or anything else. This supports above theory.

Well done, Linux!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.