{"id":136,"date":"2024-05-16T03:35:50","date_gmt":"2024-05-16T02:35:50","guid":{"rendered":"https:\/\/thevadasan.com\/?p=136"},"modified":"2024-05-07T03:59:36","modified_gmt":"2024-05-07T02:59:36","slug":"linux-commands-for-the-advanced-user-mastery-and-automation","status":"publish","type":"post","link":"https:\/\/thevadasan.com\/?p=136","title":{"rendered":"Linux Commands for the Advanced User: Mastery and Automation"},"content":{"rendered":"\n<p>Advanced Linux users are often involved in system administration, scripting, and automation. Their command line usage involves a deep understanding of the system&#8217;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.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. <code>systemctl<\/code> &#8211; Control the systemd system and service manager<\/h4>\n\n\n\n<ul>\n<li><strong>What it does:<\/strong> Manages services, daemons, and other system components under systemd, which is the default init system for many Linux distributions.<\/li>\n\n\n\n<li><strong>Usage:<\/strong> <code>systemctl [command] [service]<\/code> to start, stop, enable, disable, or check the status of services.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">systemctl status nginx\nsystemctl enable nginx<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2. <code>journalctl<\/code> &#8211; Query and display messages from the journal<\/h4>\n\n\n\n<ul>\n<li><strong>What it does:<\/strong> Retrieves logs managed by systemd, providing powerful filtering options for troubleshooting and system analysis.<\/li>\n\n\n\n<li><strong>Usage:<\/strong> <code>journalctl [options]<\/code> to view logs from the system&#8217;s journal.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">journalctl -u nginx.service --since yesterday\njournalctl --disk-usage<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3. <code>iptables<\/code> &#8211; Administration tool for IPv4 packet filtering and NAT<\/h4>\n\n\n\n<ul>\n<li><strong>What it does:<\/strong> Manages the rules in the network packet filtering table provided by the Linux kernel.<\/li>\n\n\n\n<li><strong>Usage:<\/strong> <code>iptables [options]<\/code> to set up, maintain, or inspect the tables of IP packet filter rules.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">iptables -L\niptables -A INPUT -p tcp --dport ssh -j ACCEPT<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">4. <code>tcpdump<\/code> &#8211; Command-line packet analyzer<\/h4>\n\n\n\n<ul>\n<li><strong>What it does:<\/strong> Captures and displays the packets being transmitted or received over a network to which the computer is attached.<\/li>\n\n\n\n<li><strong>Usage:<\/strong> <code>tcpdump [options]<\/code> to analyze network traffic.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">tcpdump -i eth0 -c 10 -w network_traffic.pcap<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">5. <code>strace<\/code> &#8211; Trace system calls and signals<\/h4>\n\n\n\n<ul>\n<li><strong>What it does:<\/strong> Monitors the system calls used by a program and all the signals it receives, useful for debugging and understanding internal operations.<\/li>\n\n\n\n<li><strong>Usage:<\/strong> <code>strace [options] [program]<\/code> to trace system calls executed by a program.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">strace -c ls<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">6. <code>lsof<\/code> &#8211; List open files<\/h4>\n\n\n\n<ul>\n<li><strong>What it does:<\/strong> Lists information about files opened by processes, useful for troubleshooting and security checks.<\/li>\n\n\n\n<li><strong>Usage:<\/strong> <code>lsof [options]<\/code> to list all open files and the processes that opened them.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">lsof -i :22\nlsof +D \/usr\/bin<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">7. <code>rsync<\/code> &#8211; Remote file copy tool<\/h4>\n\n\n\n<ul>\n<li><strong>What it does:<\/strong> Provides a fast, versatile, and reliable way of synchronizing files locally and remotely.<\/li>\n\n\n\n<li><strong>Usage:<\/strong> <code>rsync [options] source destination<\/code> to synchronize files\/directories between the source and the destination.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">rsync -avz \/local\/dir user@remotehost:\/remote\/dir<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">8. <code>perf<\/code> &#8211; Performance analysis tools for Linux<\/h4>\n\n\n\n<ul>\n<li><strong>What it does:<\/strong> Offers a rich set of commands to collect and analyze performance and trace data.<\/li>\n\n\n\n<li><strong>Usage:<\/strong> <code>perf [command] [options]<\/code> to analyze system and application performance.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">perf stat -a\nperf record -F 99 -a -g -- sleep 10<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">9. <code>vmstat<\/code> &#8211; Report virtual memory statistics<\/h4>\n\n\n\n<ul>\n<li><strong>What it does:<\/strong> Reports information about processes, memory, paging, block IO, traps, and CPU activity.<\/li>\n\n\n\n<li><strong>Usage:<\/strong> <code>vmstat [options] [delay [count]]<\/code> to get a snapshot of system resource usage.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">vmstat 1 10<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">10. <code>ss<\/code> &#8211; Utility to investigate sockets<\/h4>\n\n\n\n<ul>\n<li><strong>What it does:<\/strong> Displays information about network connections, listening ports, and socket statistics.<\/li>\n\n\n\n<li><strong>Usage:<\/strong> <code>ss [options]<\/code> to replace older tools like <code>netstat<\/code> with more information and faster execution.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">ss -tulpn<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">11. <code>sar<\/code> &#8211; System activity report<\/h4>\n\n\n\n<ul>\n<li><strong>What it does:<\/strong> Collects and reports system activity information; part of the sysstat package.<\/li>\n\n\n\n<li><strong>Usage:<\/strong> <code>sar [options]<\/code> to collect, report, or save system activity information.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sar -u 5 5\nsar -n DEV 1 3<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">12. <code>nc (netcat)<\/code> &#8211; Networking utility for reading from and writing to network connections<\/h4>\n\n\n\n<ul>\n<li><strong>What it does:<\/strong> A versatile tool that can create almost any type of connection you would need and serves as a powerful network debugger and exploration tool.<\/li>\n\n\n\n<li><strong>Usage:<\/strong> <code>nc [options] [hostname] [port]<\/code> to read and write data across network connections.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">nc -l 1234\nnc example.com 80<\/code><\/pre>\n\n\n\n<p>Mastering these advanced commands not only enhances your capability to perform complex tasks but also provides a deeper understanding of the system&#8217;s operation, contributing to better troubleshooting, system management, and performance tuning skills.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Advanced Linux users are often involved in system administration, scripting, and automation. Their command line usage involves a deep understanding of the system&#8217;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 &#8211; Control [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":138,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18,34],"tags":[],"_links":{"self":[{"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/posts\/136"}],"collection":[{"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thevadasan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=136"}],"version-history":[{"count":1,"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/posts\/136\/revisions"}],"predecessor-version":[{"id":137,"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/posts\/136\/revisions\/137"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/media\/138"}],"wp:attachment":[{"href":"https:\/\/thevadasan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thevadasan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thevadasan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}