Unix Commands
File commands
Section titled “File commands”>redirects output to a file, replacing its contents;>>appends instead.cat file1 >> file2appendsfile1to the end offile2.
System information
Section titled “System information”cat /etc/os-release— the distribution name and version.
Manual pages
Section titled “Manual pages”- Full manual for a command:
man firewall-cmd - Short usage summary, paged:
firewall-cmd -h | less
Network commands
Section titled “Network commands”- List listening sockets:
ss -tulpn | grep LISTEN.-tTCP,-uUDP,-llistening,-pthe owning process,-nnumeric ports. The oldernetstat -tulpnprints the same information where it is still installed, but its own manual page states that “this program is mostly obsolete” and namesssas the replacement. - Check that a TCP port is reachable:
nc -vz localhost 2128.telnet localhost 2128does 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, andscp,rsync -e sshorsftpfor copying files between machines. - DNS lookups:
nslookup -type=A auth.docker.iofor IPv4 records,nslookup -type=AAAA auth.docker.iofor IPv6.dig auth.docker.io Agives more detail, including which server answered. nmcli connection show(ornmcli c s) lists NetworkManager connection profiles, with active ones highlighted.nmcli device statuslists every device and its state, including devices NetworkManager does not manage.
Searching
Section titled “Searching”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 filedoes the same thing.grep -r pattern .searches recursively from the current directory; add-nfor line numbers and-ito ignore case.
Find and remove folders
Section titled “Find and remove folders”find . -name "FILE-TO-FIND" -exec rm -rf {} \;find prints the matches without -exec, which is worth doing first: -exec rm -rf is
unrecoverable.
Locating files by name
Section titled “Locating files by name”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 updatedblocate FILE_NAMEWatching a running process
Section titled “Watching a running process”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/1File descriptor 1 is stdout and 2 is stderr.
Reference
Section titled “Reference”- 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.