Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to write an Unix Shell Script that moves the csv input files from /exp/files folder to /exp/ready directory. The csv input files are written to /exp/files folder by an SFTP server whose behavior I cannot trivially change.

In shell script I need to ensure before doing a move of that csv input file from /exp/files directory no longer any other process is writing to the file. How can I move it?

share|improve this question

lsof might be what you want (it is after all, the command to list open files). If your files have a known naming convention, run an lsof <filename> against it to check if it is indeed being used by a process. If it isn't, lsof will return a non-zero return code.

share|improve this answer
Please note: If you want to check if the file is being written to by another user, you'll need to run lsof (or fuser) as root. If you're checking a file on NFS, lsof or fuser will only tell you something when run on the machine from which the file is being written to. – Emmanuel Joubaud Aug 28 '14 at 9:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .