Does anyone know if it is possible to use a script for printing to the screen that .bashrc
is in use or not.
I found .bashrc
under home directory, but is there any script which can print the status of the file, like it is open, in use and etc.
Does anyone know if it is possible to use a script for printing to the screen that .bashrc
is in use or not.
I found .bashrc
under home directory, but is there any script which can print the status of the file, like it is open, in use and etc.
There are two issues here:
You want only to check if a file is being accessed now in any manner
You want to monitor a file for changes, like keeping a continuous watch
For case 1:
You can use fuser
or lsof
, these are the common tools for this:
lsof ~/.bashrc
or
fuser ~/.bashrc
Check man lsof
and man fuser
For case 2:
If you want to have a continuous check, Linux provides inotify
family of system calls to monitor any filesystem events.
So you can add a continuous watch by the -m
(--monitor
) option of inotifywait
:
inotifywait -m ~/.bashrc
From here, you can take actions e.g. run a command if a specific event e.g. read or write takes place.
There are also many options and use cases, take a look at man inotifywait
. You might need to install inotify-tools
first.
Read man bash
, and learn that .bashrc
is read, processed, and closed when a shell starts (read the man
page for more detail). However, you could sudo lsof $HOME/.bashrc
in a terminal window to see if any process has the file open at the moment.