LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-16-2009, 03:31 AM   #1
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Rep: Reputation: 48
how to know which file is being used by which process


Are there commands to know the list of files being used by operating system because task manager just gives list of applications not the absolute path of files being used
 
Old 04-16-2009, 03:45 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Look at the lsof command. You have to run it as root or even as a regular user giving the full path, that usually is /usr/sbin/lsof.
 
Old 04-16-2009, 10:29 AM   #3
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 297

Rep: Reputation: 62
Another option is the fuser utility if it is available on your system
 
Old 11-10-2009, 03:17 AM   #4
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Original Poster
Rep: Reputation: 48
how to use lsof command

Quote:
Originally Posted by colucix View Post
Look at the lsof command. You have to run it as root or even as a regular user giving the full path, that usually is /usr/sbin/lsof.
I ran lsof then it gave long list of file.
Say I want to know files of my flash drive i.e /media/PENDRIVE that are opened then what should i do?
 
Old 11-10-2009, 03:50 AM   #5
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,261

Rep: Reputation: 297Reputation: 297Reputation: 297
lsof | grep /media/PENDRIVE
 
Old 11-10-2009, 04:25 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
No!

Quote:
Originally Posted by Guttorm View Post
lsof | grep /media/PENDRIVE
No: 'lsof -Pwn +D/media/PENDRIVE'
 
Old 11-10-2009, 08:17 PM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 7,169

Rep: Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205Reputation: 2205
More than one way to skin the cat... I do tend to use grep a lot for things like this.

For the Peanut Gallery ... when you see a construct like lsof | grep foo, that's a nifty Unix trick called 'piping." Basically, the output of the "lsof" command, which would normally spew out onto your terminal window, is "piped into" a second command, "grep", whose purpose happens to be to filter whatever is piped into it and to spit out only what matches the filter (namely: foo).

Almost always, "there's more than one way to do it." (In fact, a very smart guy named Larry Wall all but trademarked that phrase, known to Perl programmers the world over as TMTOWTDI.) So, when someone tells you about "yet another way to do it," just smile appreciatively.
 
Old 11-10-2009, 11:55 PM   #8
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Original Poster
Rep: Reputation: 48
suggestion by unSpawn is FASTER and gives title of all columns so more useful and customised.In next post there is a tip to make 'lsof' use those options by default.

Last edited by sumeet inani; 11-12-2009 at 02:59 AM.
 
Old 11-11-2009, 12:02 AM   #9
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Original Poster
Rep: Reputation: 48
Solution for all

SOLUTION FOR ALL
This has been compiled taking above useful suggestions into account
Code:
You can add following line to ~/.bashrc 
alias lsof='lsof -Pwn'
Now if you want to find files of particular folder being used then simply run
lsof +D folder
I found out that options with 'lsof' help in following manner
-P 	--inhibits the conversion of port numbers to port names for network files.
-w 	--disables the suppression of warning message
+D d 	--search for all open instances of directory D and all the files and directories it contains to its complete depth.
-n	--inhibits the conversion of network numbers to host names for network files.
If this helps you than thank me by pressing thumbs up button(in the same way I have thanked suggestions found useful).Thank You.

Last edited by sumeet inani; 11-17-2009 at 08:37 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to tell what process last wrote to a file? - hosts file being updated by unk kcoriginal Linux - General 1 12-29-2008 12:53 AM
lock file between two process shogun1234 Programming 2 07-28-2007 11:54 PM
Using xargs to process file from list? jon_k Programming 2 01-14-2007 05:14 PM
process file in different directory izza_azhar Programming 1 02-15-2005 10:29 AM
process.h file in Linux ashwinipahuja Programming 6 05-11-2004 12:50 PM


All times are GMT -5. The time now is 10:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration