LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 08-13-2016, 04:37 AM   #1
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Rep: Reputation: 11
Post Who use directory or file?


Hello.
I want to know who open a file or directory. For example, when you want delete a file it show you an error that file used by others but how can I find the user?

Tnx.
 
Old 08-13-2016, 04:55 AM   #2
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,665

Rep: Reputation: Disabled
Quote:
Originally Posted by hack3rcon View Post
Hello.
I want to know who open a file or directory. For example, when you want delete a file it show you an error that file used by others but how can I find the user?
See
Code:
man lsof
.

Quote:
Originally Posted by hack3rcon View Post
Tnx.
What's this? Intentional insult or just ignoring forum rules?
 
1 members found this post helpful.
Old 08-13-2016, 08:37 AM   #3
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Original Poster
Rep: Reputation: 11
But when I use "lsof directory" then it never show anything!!!!
 
Old 08-13-2016, 12:46 PM   #4
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
I am guessing that English is NOT your native language

so WHAT folder are you trying to delete ?

for example folders in /tmp can be owned by many users and processes
 
Old 08-13-2016, 01:07 PM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,784

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
Something strange is happening here. Just because a file is in use should not prevent you from deleting it. The file gets unlinked from the directory immediately; the inode and file content remain available on the disk until no process has the file open. There are directories like /tmp that have the "sticky" bit set, and that prevents you from deleting files that you do not own, but that is unrelated to whether the file is currently "in use".
 
Old 08-14-2016, 06:06 AM   #6
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by hack3rcon View Post
But when I use "lsof directory" then it never show anything!!!!
try
Code:
lsof|grep directory
 
Old 08-14-2016, 10:01 AM   #7
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
try
Code:
lsof|grep directory
Code:
lsof +D /path/to/directory/
will show you every process running
in directory.
 
1 members found this post helpful.
Old 08-15-2016, 12:47 PM   #8
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
^ that would certainly be preferable inside a script.
pipes often allow for a oneliner quickie, no need to read the manual...
 
Old 08-16-2016, 04:05 AM   #9
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Original Poster
Rep: Reputation: 11
Thank you. Problem Solved via "lsof +D /path/to/directory/".
 
  


Reply



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
File and Directory Permissions using Active Directory Users jokar.mohsen Linux - Security 8 12-28-2014 06:05 PM
[SOLVED] Invoke root directory owner/group while moving file/directory yogesh_attarde Linux - Security 5 04-14-2014 11:36 PM
su:warning: cannot change directory to home/orausr: No such file or directory cdhar Linux - Newbie 4 09-11-2012 06:17 AM
Get first file of directory then copy to other directory andd rename the file Faye Linux - Software 4 01-30-2011 09:16 AM
How to protect a file/directory in your home login directory (RH Linux) jitsenho Linux - Security 9 07-03-2006 11:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:32 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
Open Source Consulting | Domain Registration