A Practical Linux Command-Line Workflow for Everyday Server Tasks
When a server behaves oddly, the hard part is often knowing what to check first. A useful command-line workflow starts with your location, narrows down the problem, and only then changes files or services. Here’s a small toolkit for common tasks: finding a log, searching it, checking a service, and confirming that there’s enough disk space. The commands are common across Linux systems, though…
When a server exhibits unusual behavior, the first step is to identify where to begin troubleshooting. A practical Linux command-line workflow begins with confirming your location, narrowing down the issue, and only then making changes to files or services. This toolkit provides common commands for everyday server tasks, although some utilities and service names may vary depending on the distribution.
To start, orient yourself by checking your current directory and listing files within it. The `pwd` command prints your current directory, while `ls -lah` shows files—including hidden ones—in a detailed, human-readable format. Linux file paths are case-sensitive, so "Config" and "config" could refer to different files. Move to a specific directory using the `cd` command, then verify your location again with `pwd`.
If you encounter an unfamiliar command, always consult its manual page for guidance rather than trying to guess the available flags. Pressing "q" exits most manual pages. In documentation, square brackets typically indicate optional parts, which should not be typed literally.
To locate log files, use the `find` command to search for regular files ending in ".log" within the `/var/log` directory. The `head` command can limit the displayed results to make it easier to review a long list. For more advanced search options by file name, type, size, or modification time, refer to practical guides on using the `find` command in Linux.
Once you have identified a candidate log file, you can read it interactively using the `less` command. This allows you to navigate through the file using arrow keys and exit with "q". To quickly view the most recent lines, use the `tail` command. For searching within a specific file for a particular word, such as "error", use the `grep` command with the `-i` flag to ignore case and the `-n` flag to include line numbers.
When investigating a service, avoid making assumptions about its status. Use `systemctl status` to check if the service is active and for recent status details. Replace "nginx" with the actual service name you are investigating. If you need to inspect its logs, `journalctl` can filter the systemd journal by service and apply time-based filters. Limit the time range with `--since` and exclude the pager output with `--no-pager` to directly print the output.
Before taking any action, always review the service status and logs to understand the root cause of the issue. Restarting a service should be a last resort after thoroughly examining its status and logs, as it can potentially disrupt users and may not address the underlying problem. It's crucial to verify the service name and logging setup, as they can vary across different systems.
When checking disk space, use `df -h` to view the space available on mounted filesystems, and `du -sh` to estimate the space used by a particular directory. These commands provide different insights and may not always match, so it's essential to understand what each command is measuring. Remember to exercise caution when making changes, as commands like `rm` typically remove files without placing them in a desktop trash folder. Avoid applying broad recursive changes unless you have a clear understanding of their impact.
For a comprehensive troubleshooting sequence, follow this order: run `pwd` and inspect the relevant directory using `ls`, locate the file or service you need to investigate, review recent output with `tail`, `less`, or `journalctl`, search for a specific symptom using `grep`, and finally check the service status and filesystem capacity.
Only make targeted changes after confirming their impact. The aim is not to memorize every Linux command but to master a few reliable tools, verify what they are pointing at, and understand the output before making any changes.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.