Introduction

The Linux command line provides direct control over files, processes, services, logs, storage, and networking. Run each command deliberately, verify the target path or service first, and use sudo only when elevated access is actually required.

Prerequisites

  • A Linux shell account and, only where required, approved sudo access.
  • A terminal session with access to the intended server or lab system.
  • A current backup or snapshot before changing production files, ownership, permissions, or services.

01 — Navigation and file operations

Start by identifying the current directory and inspecting its contents. Use interactive deletion for uncertain targets; never run a destructive command until the path has been checked.

Terminal
pwd
ls -lah
cd /var/log
cp -a source destination
mv old new
rm -i file
mkdir -p /data/backup
  • pwd prints the current directory; ls -lah lists entries with human-readable sizes and hidden files.
  • cp -a preserves attributes when copying; mv renames or moves; mkdir -p creates missing parent directories.

02 — Storage and system state

Terminal
df -h
du -sh /*
free -h
uptime
ps aux
top

df -h reports filesystem capacity, while du -sh /* estimates usage below top-level paths and can produce permission errors for an unprivileged user. free -h, uptime, ps aux, and top provide memory, load, process, and live system information.

03 — Services and logs

Terminal
systemctl status nginx
journalctl -u nginx

systemctl status shows the state of a systemd service. journalctl -u narrows the system journal to a unit; add an appropriate time filter when investigating a specific incident. Replace nginx with the actual service name.

04 — Network diagnostics

Terminal
ip addr
ip route
ss -tulpn
ping -c 4 8.8.8.8
curl -I https://example.com

ip addr shows interfaces and addresses; ip route shows routing decisions; ss -tulpn displays listening sockets and may need sudo to show process details. Test the local gateway before testing an external IP, then use curl to test HTTP response headers.

05 — Permissions, ownership, and access

Linux permissions apply read, write, and execute access to the owner, group, and others. chmod changes mode bits; chown changes ownership. Always inspect the current owner and mode with ls -l before making a change.

Terminal
ls -l /path/to/file
chmod 640 /path/to/file
chown user:group /path/to/file

Avoid broad modes such as 777. Grant only the minimum permissions required by the intended user, service, or group.

06 — Search, pipes, and redirects

grep searches text, find locates filesystem entries, a pipe (|) sends one command’s output to another command, and redirects write output to a file. Use > only when replacement is intentional; use >> when appending is intended.

Terminal
grep -R "error" /var/log
find /var/log -type f -name "*.log"
journalctl -u nginx | grep -i "error"
echo "check completed" >> /tmp/check.log

07 — Safe verification routine

  1. Use pwd and ls -lah before copying, moving, or removing a file.
  2. Check df -h before writing a large backup and verify the result with ls -lh after completion.
  3. For a network issue, work from interface and route checks to gateway, external IP, DNS, and application-layer testing.

Troubleshooting

  • Permission denied: inspect ls -l, the parent-directory execute permission, ownership, and whether sudo is actually approved for the task.
  • Command not found: verify spelling, package installation, and the PATH of the current shell.
  • Service is inactive: inspect systemctl status and journalctl output before restarting it; preserve the reported error for investigation.

Best Practices

  • Use absolute paths for administrative commands and quote paths that contain spaces.
  • Prefer read-only inspection before an operation that changes data or service state.
  • Keep a command history or change record for production work, without storing passwords or secrets in it.

Frequently Asked Questions

What is the difference between df and du?

df reports filesystem capacity; du estimates the space consumed by files and directories.

Should every administrative command use sudo?

No. Use sudo only for the specific command that needs elevated rights, after verifying its purpose and target.

Conclusion

A small set of well-understood Linux CLI commands is more valuable than a long unverified command list. Inspect first, change deliberately, restrict elevated access, and verify the outcome after each production operation.

Official references

Share