Skip to content

Unix Commands

  • > redirects output to a file, replacing its contents; >> appends instead.
    • cat file1 >> file2 appends file1 to the end of file2.
  • cat /etc/os-release — the distribution name and version.
  • Full manual for a command: man firewall-cmd
  • Short usage summary, paged: firewall-cmd -h | less
  • List listening sockets: ss -tulpn | grep LISTEN. -t TCP, -u UDP, -l listening, -p the owning process, -n numeric ports. The older netstat -tulpn prints the same information where it is still installed, but its own manual page states that “this program is mostly obsolete” and names ss as the replacement.
  • Check that a TCP port is reachable: nc -vz localhost 2128. telnet localhost 2128 does the same thing and is often the only tool present on a minimal image — but as a reachability probe only. Telnet carries credentials and session data in clear text and must never be used to log into a host; SSH replaced it for remote administration, and scp, rsync -e ssh or sftp for copying files between machines.
  • DNS lookups: nslookup -type=A auth.docker.io for IPv4 records, nslookup -type=AAAA auth.docker.io for IPv6. dig auth.docker.io A gives more detail, including which server answered.
  • nmcli connection show (or nmcli c s) lists NetworkManager connection profiles, with active ones highlighted.
  • nmcli device status lists every device and its state, including devices NetworkManager does not manage.
  • grep -- -P file-- marks the end of the options, so the next argument is read as the pattern even though it begins with a hyphen. grep -e -P file does the same thing.
  • grep -r pattern . searches recursively from the current directory; add -n for line numbers and -i to ignore case.
find . -name "FILE-TO-FIND" -exec rm -rf {} \;

find prints the matches without -exec, which is worth doing first: -exec rm -rf is unrecoverable.

locate searches a prebuilt database rather than walking directories, which makes it far faster than find but only as current as its last index. Refresh the index, then search:

sudo updatedb
locate FILE_NAME

A process’s console output can be read through the /proc filesystem, which is useful when a program was started without redirecting its output anywhere:

tail -f /proc/<pid>/fd/1

File descriptor 1 is stdout and 2 is stderr.

  • netstat(8) — the manual page whose NOTES section reads “This program is mostly obsolete. Replacement for netstat is ss.”
  • ss(8) — the socket statistics utility that replaced it.