A system administrator is troubleshooting a log rotation failure for the file /var/log/syslog. The rotation script cannot access the file because it is held open by a running process. Which of the following commands will most effectively identify the command, process ID (PID), and user associated with the process that has /var/log/syslog open?
The correct command is lsof /var/log/syslog. The lsof (List Open Files) command is used to display information about files that are open by various processes. When given a file path as an argument, it will list all processes that have that specific file open, along with details like the PID, user, and command name. The ps -ef | grep /var/log/syslog command is incorrect because ps lists running processes, but grepping for a file path is not a reliable way to find which process has a file open, as the file path is not typically part of the process's command line information. The file /var/log/syslog command is used to determine the type of a file (e.g., ASCII text, binary), not which process is using it. The stat /var/log/syslog command displays detailed file metadata like size, permissions, and timestamps, but does not show process-related information.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the `lsof` command do?
Open an interactive chat with Bash
Why is `ps -ef | grep` not effective for finding processes holding files?
Open an interactive chat with Bash
What is the difference between `file`, `stat`, and `lsof` commands?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Services and User Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access