Advanced Linux users are often involved in system administration, scripting, and automation. Their command line usage involves a deep understanding of the system’s internals, security, and performance tuning. This article introduces several powerful Linux commands and tools that are essential for advanced users who need to manage complex systems and networks.
1. systemctl
– Control the systemd system and service manager
- What it does: Manages services, daemons, and other system components under systemd, which is the default init system for many Linux distributions.
- Usage:
systemctl [command] [service]
to start, stop, enable, disable, or check the status of services.
systemctl status nginx
systemctl enable nginx
2. journalctl
– Query and display messages from the journal
- What it does: Retrieves logs managed by systemd, providing powerful filtering options for troubleshooting and system analysis.
- Usage:
journalctl [options]
to view logs from the system’s journal.
journalctl -u nginx.service --since yesterday
journalctl --disk-usage
3. iptables
– Administration tool for IPv4 packet filtering and NAT
- What it does: Manages the rules in the network packet filtering table provided by the Linux kernel.
- Usage:
iptables [options]
to set up, maintain, or inspect the tables of IP packet filter rules.
iptables -L
iptables -A INPUT -p tcp --dport ssh -j ACCEPT
4. tcpdump
– Command-line packet analyzer
- What it does: Captures and displays the packets being transmitted or received over a network to which the computer is attached.
- Usage:
tcpdump [options]
to analyze network traffic.
tcpdump -i eth0 -c 10 -w network_traffic.pcap
5. strace
– Trace system calls and signals
- What it does: Monitors the system calls used by a program and all the signals it receives, useful for debugging and understanding internal operations.
- Usage:
strace [options] [program]
to trace system calls executed by a program.
strace -c ls
6. lsof
– List open files
- What it does: Lists information about files opened by processes, useful for troubleshooting and security checks.
- Usage:
lsof [options]
to list all open files and the processes that opened them.
lsof -i :22
lsof +D /usr/bin
7. rsync
– Remote file copy tool
- What it does: Provides a fast, versatile, and reliable way of synchronizing files locally and remotely.
- Usage:
rsync [options] source destination
to synchronize files/directories between the source and the destination.
rsync -avz /local/dir user@remotehost:/remote/dir
8. perf
– Performance analysis tools for Linux
- What it does: Offers a rich set of commands to collect and analyze performance and trace data.
- Usage:
perf [command] [options]
to analyze system and application performance.
perf stat -a
perf record -F 99 -a -g -- sleep 10
9. vmstat
– Report virtual memory statistics
- What it does: Reports information about processes, memory, paging, block IO, traps, and CPU activity.
- Usage:
vmstat [options] [delay [count]]
to get a snapshot of system resource usage.
vmstat 1 10
10. ss
– Utility to investigate sockets
- What it does: Displays information about network connections, listening ports, and socket statistics.
- Usage:
ss [options]
to replace older tools likenetstat
with more information and faster execution.
ss -tulpn
11. sar
– System activity report
- What it does: Collects and reports system activity information; part of the sysstat package.
- Usage:
sar [options]
to collect, report, or save system activity information.
sar -u 5 5
sar -n DEV 1 3
12. nc (netcat)
– Networking utility for reading from and writing to network connections
- What it does: A versatile tool that can create almost any type of connection you would need and serves as a powerful network debugger and exploration tool.
- Usage:
nc [options] [hostname] [port]
to read and write data across network connections.
nc -l 1234
nc example.com 80
Mastering these advanced commands not only enhances your capability to perform complex tasks but also provides a deeper understanding of the system’s operation, contributing to better troubleshooting, system management, and performance tuning skills.