ktrilaksono.dev
ProgrammingFebruary 23, 2020·2 views

Top 10 Linux Commands

linuxsrecli

Basic operations like mkdir, cat, ls, and rm are common knowledge. This is a compilation of the more sophisticated commands that come up frequently in job interview assessments.

1. head and tail

Use head to print the first 10 lines of a file, and specify how many lines with -n (e.g. cat file.txt | head -n 5). tail displays the final lines, and -f enables real-time file monitoring. Neither can retrieve file size information.

2. top

Displays CPU and memory consumption of active processes, plus free memory, user sessions, process count, and system uptime. KiB Swap represents disk memory functioning as temporary storage, distinct from RAM.

3. netstat

Displays network information: ports in use and their status, incoming connections, and which process uses which port. It cannot show CPU/RAM usage or the total number of system ports.

4. lsof

Lists open files and their associated processes — an "open file" here includes regular files, directories, block/character special files, libraries, streams, and network files.

5. Preserving environment variables across sessions

  • Add export statements to $HOME/.bashrc or $HOME/.bash_profile.
  • Write to /etc/.profile (though reading isn't guaranteed).
  • Source environment variables from a separate file at startup.

6. wc, grep, and cat for counting lines

  • wc: line count, character count, byte count — wc -l file.txt
  • grep: pattern search — grep "" -c file.txt
  • cat: concatenate and print — cat -n file.txt

7. stat

Displays comprehensive file information: name, size in bytes, permissions, inode number, and modification timestamp.

8. du and df

du shows disk usage in human-readable form; df shows free disk space, total size, used space, inode usage, and mount points. Neither retrieves CPU or RAM usage.

9. vmstat and free

vmstat reports processes, memory, paging, block IO, traps, disks, and CPU activity. free details memory usage — used, free, shared, buffer, cache. Both cover CPU, RAM, and disk.

10. dig

Resolves a DNS name via a DNS resolver, which answers with an IP address and other record information — DNS name, TTL, resource class, record type, and IP address.

Closing

top and lsof tend to feel the most complex due to their extensive built-in options — worth spending the most practice time on those two.

© 2026 Kurnianto Trilaksono Sutjipto. Built with Next.js.