Sam
Sam

Reputation: 2432

Identifying files which are not currently written

I want to transfer some log files from one folder to another in Ubuntu operating system.

My question is how do I understand that a log file is written and no more writing is done on that?

Is there any command which would help identifying that?

Actually I want to do that through a shell script.

Thanks.

Upvotes: 1

Views: 45

Answers (2)

hovanessyan
hovanessyan

Reputation: 31433

The lsof command can help you identify if any process is using a certain file.

For a simple example, I have created a test file in my home folder, and tailed to it. This is the output of lsof for that file:

hovanessyan@workstation:~$ lsof /home/hovanessyan/test
COMMAND   PID        USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
tail    16858 hovanessyan    3r   REG    8,1      200 43785764 /home/hovanessyan/test

You can see the command that's using the file, the pid etc.

Here are some more detailed and complex examples: one and two

Upvotes: 0

Eddy_Em
Eddy_Em

Reputation: 872

fuser - identify processes using files or sockets

Also maybe inotify will help.

Upvotes: 1

Related Questions