Linux Survival Basics
Read-only, sensitive outputInspect One Process Open Files
You need a small sample of open files for a known PID.
Command
sudo lsof -p 1234 | head
Before you run this
System impact: Read-only. Output may expose users, paths, tokens, keys, IPs, process arguments, or log details.
When not to use it: Do not share raw lsof output without redacting private paths and sockets.
Expected output
A small sample of files, sockets, and descriptors owned by PID 1234.
System impact
Read-only, sensitive output. Nothing changes. The command reads current state and prints diagnostic evidence.
May require elevated permissions on protected paths or service-owned files.
Recovery / rollback: no state is changed.
When to use it
Use only after replacing 1234 with the target PID.
When not to use it
Do not share raw lsof output without redacting private paths and sockets.
Example run
Commands shown
These are the commands shown for inspection. Treat them as an example, not proof that your system will behave identically.
sudo lsof -p 1234sudo lsof -p 1234 | head
next steps
Related commands
Count Open Files for One Process
Count handles for the target process before raising limits.
sudo lsof -p 1234 | wc -l
Find the dpkg Lock Owner
Find the process holding the dpkg lock before touching lock files.
sudo lsof /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock 2>/dev/null
Find the Processes Using Memory
The server felt slow. Memory pressure was the first thing to rule out.
ps -eo pid,comm,%mem,%cpu --sort=-%mem | head
List Contents of a Backup Tarball
You can inspect an archive without extracting it.
tar -tf archives/site-backup.tar | sort | head
Show Hidden CRLF in a Script Shebang
The hidden carriage return is often the whole bug.
head -1 script.sh | cat -v
next diagnostic step
Where to go from this command
- Too many open files hub Use after finding the target PID.
Study mapping
Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.
Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.