Merry Christmas & Happy 2027! Less downtime. More good times. Celebrating 13 years of sorlavit.com
Skip to content
Sorlavit KimIT Support, Network & Infrastructure Services Let’s talk

ปุ่มแปลไทยจะเปิดบทความผ่าน Google Translate เพื่อแปลอัตโนมัติ โดยคงโค้ดและคำสั่งไว้ตามต้นฉบับ

Linux Commands / IT Support Guides

Follow a Linux application log with tail

Follow only newly appended log lines, recognize rotation behavior and capture a bounded incident excerpt without clearing the application log.

Start hands-on practice · เริ่มภาคปฏิบัติ ↓

Compiled for Sorlavit Kim · Published · Updated · 3 min read

Practical guide · คู่มือลงมือทำ

Download worksheet · ดาวน์โหลดขั้นตอน

Detailed practical guide

Prepare your workspace and inputs

Open two terminals on a test machine. In terminal A create a new temporary file and note its printed path. In terminal B use that exact path. Never substitute a real production file into the sample write or truncate operations.

Platform context: Linux with GNU tail and Bash. The first steps use a temporary synthetic log; production diagnostics are read-only.

Scenario to reproduce or investigate

An operator follows a rotated file descriptor and misses events in the newly created log path. A controlled fixture makes the difference between following a descriptor and a filename observable.

Evidence to record in your worksheet
  • Actual target and platform release
  • Exact inputs or substituted values
  • Baseline result
  • Per-step expected and observed output
  • Failure encountered and corrective action
  • Final acceptance and recovery state
  1. Create a synthetic append-only observation target

    Run the first two commands in terminal A and copy the resulting path. In terminal B start tail with zero historical lines and follow-by-name behavior. The one-second retry interval is expected behavior, not a guarantee of instant collection.

    Command, configuration or input

    Terminal A:
    practice_log=$(mktemp /tmp/sorlavit-tail.XXXXXX)
    printf "%s\n" "$practice_log"
    
    Terminal B, using the printed path:
    tail -n 0 -F /tmp/sorlavit-tail.REPLACE_ME
    Expected result · ผลที่ควรเห็น

    Terminal B waits without displaying earlier content. Its target is the newly created temporary file.

    If it fails · เมื่อไม่ผ่าน

    If tail reports a missing file, compare the complete temporary filename. Do not create a guessed production log path.

  2. Append a recognizable event and test rotation

    In terminal A append the first event. Then move this synthetic log to a .1 name and create a new file at the original path with a second event. Follow-by-name mode should eventually reopen the new file and show the second event. These writes are only for the temporary fixture.

    Command, configuration or input

    printf "%s\n" "2026-11-04T09:00:00Z request=r1 outcome=ok" >> "$practice_log"
    mv -- "$practice_log" "$practice_log.1"
    printf "%s\n" "2026-11-04T09:01:00Z request=r2 outcome=denied" > "$practice_log"
    Expected result · ผลที่ควรเห็น

    Terminal B displays both r1 and, after reopening, r2. It may also report that the file was replaced.

    If it fails · เมื่อไม่ผ่าน

    If the new event is not visible, verify -F rather than only -f, the actual path and directory permissions. Check whether the application uses copy-truncate rotation, which has different timing and loss considerations.

  3. Collect the actual incident evidence without modifying it

    For the real service, obtain its documented log path and use tail -n 100 for a bounded recent excerpt or tail -n 0 -F for a live observation interval. Record the start and end times and request IDs. Use the application or journal source if the service writes to stdout rather than a file.

    Command, configuration or input

    tail -n 100 -- /approved/application/log/path
    tail -n 0 -F -- /approved/application/log/path
    Expected result · ผลที่ควรเห็น

    The incident excerpt includes a known time window and can be correlated with the application request; no log clearing or restart is needed.

    If it fails · เมื่อไม่ผ่าน

    If expected events are missing, check the configured log destination and collector retention. An empty file is not evidence that the application processed no requests.

Check the result before marking this passed

Both synthetic events are observed across the filename replacement, and the actual diagnostic uses a verified log destination with a bounded observation record.

Record the observed result and evidence location in the downloaded worksheet. Mark unresolved or untested conditions explicitly.

Recovery and cleanup

Stop tail with Ctrl+C. Delete only the two temporary files whose exact paths you recorded after the fixture; never remove the real log as cleanup. No production log needs restoration.

Apply to actual work and known limits

Use follow-by-name only when it matches the application’s rotation method. A local tail session is an observation tool, not a durable collector or a guarantee against log loss.

Authored against the cited documentation. Execution on the stated vendor product or physical equipment remains to be verified.

Background, explanations and original notes

When to use it

An intermittent error is easier to trace when the log is observed during a controlled reproduction. Read a limited recent window before following new entries.

Try the diagnostic command

Use the stated shell and platform. Replace sample domains, addresses, services and paths with values from the system you are authorized to support.

tail -n 100 /var/log/app/app.log
tail -F /var/log/app/app.log

How to read the result

The first command displays the last 100 lines. -F follows the filename and retries, which is useful when the application rotates its log. Press Ctrl+C to stop following.

What to do next

Replace the path and reproduce one user action while noting its time. Capture the error and surrounding request context, then compare with the service's own status.

Before you make a change

Logs may contain tokens or personal data. Following a high-volume log can overwhelm a terminal; narrow the scope or time window when possible.

Source & further reading

GNU tail

Independently written summary reviewed on 2026-11-04. The example illustrates a possible application; it is not a client case study.

Share this article

Back to results