Avatar of Durga Ojha
Durga Ojha
Flag for India asked on

in Linux, need one SHELL Script for How many files currently open

in Linux, need one SHELL Script for How many files currently open
Linux

Avatar of undefined
Last Comment
David Favor

8/22/2022 - Mon
Durga Ojha

ASKER
any help please
Alex [***Alex140181***]

you'll need the LSOF command for this I guess

https://en.wikipedia.org/wiki/Lsof
ASKER CERTIFIED SOLUTION
Gerwin Jansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Durga Ojha

ASKER
yes its LSOF command .. but I need to create a script file .. by running it will write the output in a log file with the currently opened files in Linux
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
SOLUTION
Gerwin Jansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
simon3270

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Gerwin Jansen

Durga Charan Ojha - why did you use 'Request Attention'? You can just ask about that number 38025 here by posting a comment.

The output of this simple script I suggested is showing date/time + text + number of files. If you just want the number then do this:

 echo $(lsof | grep REG | wc -l) >> output.txt
Durga Ojha

ASKER
Hi Gerwin Jansen, EE MVE
Do you mean 38025  is the number of file opened in linux ?
Let say I have firefox, chrome and one libre office file opened .. is there any command to check this from ssh
so that output will show only for the opened applications
SOLUTION
Gerwin Jansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Durga Ojha

ASKER
I tried only lsof - the output keeps on running .. i just closed the terminal
as said I need only output like as i know in the machine I have just opened chrome, firefox, editor
so it should show output .
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Gerwin Jansen

>> I tried only lsof
Of course it does, you should just wait patiently (it will stop after some time) or apply a filter like "-c firefox"

Just try for firefox first:

lsof -c firefox | grep REG | wc -l

should give you just the number.

lsof -c firefox | grep REG

this should show you the files
SOLUTION
David Favor

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.