Master lsof – List Open Files & Network Connections in Linux!

Need to know which process is locking a file or listening on a port? In this video, we'll show you how to use the lsof (List Open Files) command. In Linux, everything is a file—including network sockets, devices, and pipes. lsof gives you a powerful view of system activity, helping you debug locked files, identify network listeners, and monitor process resource usage. Essential for every sysadmin and developer! Learn: ✅ Step-by-Step Guide: 1.Basic Usage: lsof # List ALL open files (can be huge!) lsof | head -20 # Show just the first 20 lines 2.Check Who Is Using a Specific File: lsof /path/to/file.txt Tip: Keep a file open with 'tail -f file.txt' in another terminal to test this. 3.Check Files in a Directory: lsof +D /home/tona/test Lists every open file inside this directory tree 4.Network Ports & Connections: lsof -i :22 # Who is using SSH? lsof -i :80 # Who is using HTTP? lsof -i :8080 # Who is using port 8080? lsof -i # All network connections lsof -i -P | grep LISTEN # Only listening ports (no DNS resolution) 5.Filter by User or Process: lsof -u username # Files opened by a specific user lsof -u $USER # Files opened by you lsof -p 1234 # Files opened by PID 1234 lsof -c firefox # Files opened by Firefox ✅ Why Use lsof? Debugging Locks: Find out why you can't unmount a drive or delete a file ("Device busy"). Network Security: See exactly which processes are listening on which ports. Resource Monitoring: Identify processes holding onto resources unnecessarily. Versatility: Handles regular files, sockets, pipes, and devices uniformly. ✅ Pro Tips: Speed Up Output: Use -P to disable port-to-service name conversion (e.g., shows 80 instead of http), which makes lsof much faster. Kill by Port: Combine with awk and kill to free a port: kill -9 $(lsof -t -i :8080). IPv4/IPv6: Use -i 4 or -i 6 to filter by IP version. Repeat Mode: Use -r 1 to refresh the list every second (like top for files). Root Privileges: Run with sudo lsof to see files opened by all users and system processes. You can find the full tutorial, command cheat sheet, and troubleshooting examples here: 📁 https://gitlab.com/hatem-badawi/linux... Perfect for Linux users who need deep visibility into system processes and network activity! Hit subscribe for more sysadmin tips and like if this helped. Let us know: What’s the most surprising thing you’ve found with lsof? 👉 Watch now and master open file monitoring in Linux! #LinuxTips #lsof #SysAdmin #Networking #CommandLine #Debugging #ProcessManagement (Short, clear, and packed with practical knowledge!)