Sunday, 24 April 2016

What is the use of lsof command (List Open Files) ?


lsof List Open Files

Lists files (pipes, sockets, directories, devices, etc.) information that are opened by various processes. 
This information contains :
  •  FD : File descriptor 
    • cwd : Current working directory
    • txt : Text file
    • mem : Memory mapped file
    • mmap : Memory mapped device
    • NUMBER : Actual file descriptor
  • TYPE : File type
    • REG : Regular File
    • DIR : Directory
    • FIFO : First In First Out
    • CHR : Character special file
  • NAME : File name
  • PID : Process ID

Examples

List all opened files belongs to all active processes
# lsof

List processes which opened a specific file
# lsof /opt/application/myapp/logs/myapp.log
# lsof /var/log/syslog

List processes which is using a mount point
# lsof /home

List opened files under a dir
# lsof +D /var/log/
List files opened by specific user
# lsof -u shaan
List files opened by specific process
# lsof -p 1753
List processes listening on a specific port
# lsof -i :25

No comments:

Post a Comment

Note: only a member of this blog may post a comment.