From 7d9171c85445b994b40630f9cd64fd69973cbdb1 Mon Sep 17 00:00:00 2001 From: Software Shinobi Date: Thu, 19 Jun 2025 10:03:08 -0400 Subject: [PATCH] reworking content --- landing/{docs/commands/system => }/cmatrix.md | 0 .../.Bash-Scripting/002-bash-structure.md | 32 -- .../.Bash-Scripting/003-bash-hello-world.md | 41 --- .../.Bash-Scripting/004-bash-variables.md | 131 -------- .../.Bash-Scripting/005-bash-user-input.md | 54 ---- .../docs/.Bash-Scripting/006-bash-comments.md | 27 -- .../.Bash-Scripting/007-bash-arguments.md | 81 ----- .../docs/.Bash-Scripting/008-bash-arrays.md | 112 ------- .../009-bash-conditional-expressions.md | 186 ----------- .../.Bash-Scripting/010-bash-conditionals.md | 187 ----------- .../docs/.Bash-Scripting/011-bash-loops.md | 197 ----------- .../.Bash-Scripting/012-bash-functions.md | 66 ---- .../013-debugging-and-testing.md | 83 ----- .../014-creating-custom-bash-commands.md | 83 ----- .../015-writing-your-first-bash-script.md | 180 ----------- ...16-creating-an-interactive-menu-in-bash.md | 305 ------------------ ...g-bash-script-on-multiple-remote-server.md | 129 -------- .../018-working-with-json-in-bash-using-jq.md | 225 ------------- .../.Bash-Scripting/023-bash-redirection.md | 228 ------------- .../.recycle2}/008-the-cal-command.md | 0 .../.recycle2}/009-the-bc-command.md | 0 .../.recycle2}/011-the-help-command.md | 0 .../.recycle2}/012-the-factor-command.md | 0 .../.recycle2}/016-the-whatis-command.md | 0 .../.recycle2}/017-the-who-command.md | 0 .../.recycle2}/018-the-free-command.md | 0 .../.recycle2}/020-the-sl-command.md | 0 .../.recycle2}/022-the-finger-command.md | 0 .../.recycle2}/026-the-w-command.md | 0 .../.recycle2}/029-the-login-command.md | 0 .../.recycle2}/030-the-lscpu-command.md | 0 .../.recycle2}/037-the-printenv-command.md | 0 .../.recycle2}/042-the-ip-command.md | 0 .../.recycle2}/048-the-last-command.md | 0 .../.recycle2}/049-the-locate-command.md | 0 .../.recycle2}/050-the-iostat-command.md | 0 .../.recycle2}/059-the-sort-command.md | 0 .../.recycle2}/060-the-paste-command.md | 0 .../.recycle2}/066-the-iptable-command.md | 0 .../.recycle2}/068-the-lsof-command.md | 0 .../.recycle2}/069-the-bzip2-command.md | 0 .../.recycle2}/070-the-service-command.md | 0 .../.recycle2}/071-the-vmstat-command.md | 0 .../.recycle2}/072-the-mpstat-command.md | 0 .../.recycle2}/073-the-ncdu-command.md | 0 .../.recycle2}/074-the-uniq-command.md | 0 .../.recycle2}/075-the-rpm-command.md | 0 .../.recycle2}/076-the-scp-command.md | 0 .../.recycle2}/078-the-split-command.md | 0 .../.recycle2}/079-the-stat-command.md | 0 .../.recycle2}/083-the-ionice-command.md | 0 .../.recycle2}/086-the-rsync-command.md | 0 .../.recycle2}/087-the-dig-command.md | 0 .../.recycle2}/088-the-whois-command.md | 0 .../.recycle2}/090-the-awk-command.md | 0 .../.recycle2}/094-the-pstree-command.md | 0 .../.recycle2}/095-the-tree-command.md | 0 .../.recycle2}/097-the-printf-command.md | 0 .../.recycle2}/098-the-cut-command.md | 0 .../.recycle2}/099-the-sed-command.md | 0 .../.recycle2}/103-the-rmdir-command.md | 0 .../.recycle2}/108-the-screen-command.md | 0 .../.recycle2}/109-the-nc-command.md | 0 .../.recycle2}/110-the-make-command.md | 0 .../.recycle2}/111-the-basename-command.md | 0 .../.recycle2}/112-the-banner-command.md | 0 .../.recycle2}/114-the-which-command.md | 0 .../.recycle2}/117-the-nice-command.md | 0 .../.recycle2}/118-the-wc-command.md | 0 .../.recycle2}/119-the-tr-command.md | 0 .../.recycle2}/121-the-wait-command.md | 0 .../.recycle2}/122-the-zcat-command.md | 0 .../.recycle2}/123-the-fold-command.md | 0 .../.recycle2}/124-the-quota-command.md | 0 .../.recycle2}/125-the-aplay-command.md | 0 .../.recycle2}/126-the-spd-say-command.md | 0 .../.recycle2}/127-the-xeyes-command.md | 0 .../.recycle2}/129-the-nl-command.md | 0 .../.recycle2}/130-the-pidof-command.md | 0 .../.recycle2}/131-the-shuf-command.md | 0 .../.recycle2}/134-the-cmp-command.md | 0 .../.recycle2}/135-the-expr-command.md | 0 .../trash/000-the-introduction-command.md | 0 .../.recycle2}/trash/999-wrap-up.md | 0 landing/docs/{ => .recycle}/assets/cover.jpg | Bin .../docs/{ => .recycle}/assets/cover.jpg-bak | Bin landing/docs/{ => .recycle}/assets/cover.png | Bin .../assets/styling (copy 1).css | 0 .../assets/styling (copy 2).css | 0 .../docs/{ => .recycle}/assets/styling.css | 0 .../.recycle}/000-about-the-author.md | 0 .../.recycle}/001-introduction-to-bash.md | 0 ...9-working-with-cloudflare-api-with-bash.md | 0 .../020-nginx-and-apache-log-parser.md | 0 .../021-how-to-send-emails-with-bash.md | 0 .../.recycle}/022-bash-password-generator.md | 0 ...024-automating-wordpress-lamp-with-bash.md | 0 .../.recycle}/100-bash-wrap-up.md | 0 .../docs/Bash-Scripts/002-bash-structure.md | 23 ++ .../docs/Bash-Scripts/003-bash-hello-world.md | 45 +++ .../docs/Bash-Scripts/004-bash-variables.md | 121 +++++++ .../docs/Bash-Scripts/005-bash-user-input.md | 64 ++++ .../docs/Bash-Scripts/006-bash-comments.md | 40 +++ .../docs/Bash-Scripts/007-bash-arguments.md | 101 ++++++ landing/docs/Bash-Scripts/008-bash-arrays.md | 97 ++++++ .../009-bash-conditional-expressions.md | 110 +++++++ .../Bash-Scripts/010-bash-conditionals.md | 237 ++++++++++++++ landing/docs/Bash-Scripts/011-bash-loops.md | 232 +++++++++++++ .../docs/Bash-Scripts/012-bash-functions.md | 87 +++++ landing/docs/Bash-Scripts/013-debugging.md | 42 +++ landing/docs/Bash-Scripts/0131-debugging.md | 44 +++ .../014-creating-custom-bash-commands.md | 82 +++++ .../015-writing-your-first-bash-script.md | 142 ++++++++ ...16-creating-an-interactive-menu-in-bash.md | 265 +++++++++++++++ ...g-bash-script-on-multiple-remote-server.md | 113 +++++++ .../018-working-with-json-in-bash-using-jq.md | 134 ++++++++ .../docs/Bash-Scripts/023-bash-redirection.md | 217 +++++++++++++ .../archives => Commands/archive}/gunzip.md | 0 .../archives => Commands/archive}/gzip.md | 0 .../archives => Commands/archive}/tar.md | 0 .../archives => Commands/archive}/unzip.md | 0 .../archives => Commands/archive}/zip.md | 0 .../terminal => Commands/core}/alias.md | 0 .../terminal => Commands/core}/cd.md | 0 .../terminal => Commands/core}/clear.md | 0 .../terminal => Commands/core}/echo.md | 0 .../{commands/system => Commands/core}/env.md | 0 .../terminal => Commands/core}/exit.md | 0 .../terminal => Commands/core}/history.md | 0 .../terminal => Commands/core}/less.md | 0 .../{commands/system => Commands/core}/man.md | 0 .../terminal => Commands/core}/pwd.md | 0 .../terminal => Commands/core}/sleep.md | 0 .../system => Commands/core}/whereis.md | 0 .../terminal => Commands/core}/yes.md | 0 .../docs/{commands => Commands}/disk/fdisk.md | 0 .../docs/{commands => Commands}/disk/mount.md | 0 .../{commands => Commands}/disk/parted.md | 0 .../docs/{commands => Commands}/files/cat.md | 0 .../docs/{commands => Commands}/files/cp.md | 0 .../docs/{commands => Commands}/files/diff.md | 0 .../docs/{commands => Commands}/files/dir.md | 0 .../{commands/disk => Commands/files}/du.md | 0 .../docs/{commands => Commands}/files/find.md | 0 .../terminal => Commands/files}/grep.md | 0 .../terminal => Commands/files}/head.md | 0 .../docs/{commands => Commands}/files/ls.md | 0 .../{commands => Commands}/files/mkdir.md | 0 .../docs/{commands => Commands}/files/mv.md | 0 .../docs/{commands => Commands}/files/nano.md | 0 .../docs/{commands => Commands}/files/rm.md | 0 .../terminal => Commands/files}/tail.md | 0 .../{commands => Commands}/files/touch.md | 0 .../docs/{commands => Commands}/files/vim.md | 0 .../terminal => Commands/files}/xargs.md | 0 landing/docs/Commands/index.md | 37 +++ .../{commands/disk => Commands/monitor}/df.md | 0 .../terminal => Commands/monitor}/htop.md | 0 .../disk => Commands/monitor}/lsblk.md | 0 .../monitor}/netstat.md | 0 .../processes => Commands/monitor}/ps.md | 0 .../terminal => Commands/monitor}/top.md | 0 .../networking => Commands/network}/curl.md | 0 .../network}/ifconfig.md | 0 .../network}/nslookup.md | 0 .../networking => Commands/network}/ping.md | 0 .../networking => Commands/network}/ssh.md | 0 .../networking => Commands/network}/wget.md | 0 .../processes => Commands/process}/kill.md | 0 .../processes => Commands/process}/killall.md | 0 .../processes => Commands/process}/nohup.md | 0 .../system => Commands/software}/apt.md | 0 .../system => Commands/software}/yum.md | 0 .../{commands => Commands}/system/crontab.md | 0 .../{commands => Commands}/system/date.md | 0 .../{commands => Commands}/system/hostname.md | 0 .../system/hostnamectl.md | 0 .../{commands => Commands}/system/reboot.md | 0 .../{commands => Commands}/system/shutdown.md | 0 .../docs/{commands => Commands}/system/su.md | 0 .../{commands => Commands}/system/sudo.md | 0 .../{commands => Commands}/system/uname.md | 0 .../access => Commands/users}/chmod.md | 0 .../access => Commands/users}/chown.md | 0 .../access => Commands/users}/deluser.md | 0 .../access => Commands/users}/groups.md | 0 .../access => Commands/users}/passwd.md | 0 .../access => Commands/users}/useradd.md | 0 .../access => Commands/users}/usermod.md | 0 .../access => Commands/users}/whoami.md | 0 landing/docs/commands/index.md | 15 - landing/docs/gemini | 1 + 192 files changed, 2234 insertions(+), 2362 deletions(-) rename landing/{docs/commands/system => }/cmatrix.md (100%) delete mode 100644 landing/docs/.Bash-Scripting/002-bash-structure.md delete mode 100644 landing/docs/.Bash-Scripting/003-bash-hello-world.md delete mode 100644 landing/docs/.Bash-Scripting/004-bash-variables.md delete mode 100644 landing/docs/.Bash-Scripting/005-bash-user-input.md delete mode 100644 landing/docs/.Bash-Scripting/006-bash-comments.md delete mode 100644 landing/docs/.Bash-Scripting/007-bash-arguments.md delete mode 100644 landing/docs/.Bash-Scripting/008-bash-arrays.md delete mode 100644 landing/docs/.Bash-Scripting/009-bash-conditional-expressions.md delete mode 100644 landing/docs/.Bash-Scripting/010-bash-conditionals.md delete mode 100644 landing/docs/.Bash-Scripting/011-bash-loops.md delete mode 100644 landing/docs/.Bash-Scripting/012-bash-functions.md delete mode 100644 landing/docs/.Bash-Scripting/013-debugging-and-testing.md delete mode 100644 landing/docs/.Bash-Scripting/014-creating-custom-bash-commands.md delete mode 100644 landing/docs/.Bash-Scripting/015-writing-your-first-bash-script.md delete mode 100644 landing/docs/.Bash-Scripting/016-creating-an-interactive-menu-in-bash.md delete mode 100644 landing/docs/.Bash-Scripting/017-executing-bash-script-on-multiple-remote-server.md delete mode 100644 landing/docs/.Bash-Scripting/018-working-with-json-in-bash-using-jq.md delete mode 100644 landing/docs/.Bash-Scripting/023-bash-redirection.md rename landing/docs/{commands/.recycle => .recycle/.recycle2}/008-the-cal-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/009-the-bc-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/011-the-help-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/012-the-factor-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/016-the-whatis-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/017-the-who-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/018-the-free-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/020-the-sl-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/022-the-finger-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/026-the-w-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/029-the-login-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/030-the-lscpu-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/037-the-printenv-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/042-the-ip-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/048-the-last-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/049-the-locate-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/050-the-iostat-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/059-the-sort-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/060-the-paste-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/066-the-iptable-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/068-the-lsof-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/069-the-bzip2-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/070-the-service-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/071-the-vmstat-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/072-the-mpstat-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/073-the-ncdu-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/074-the-uniq-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/075-the-rpm-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/076-the-scp-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/078-the-split-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/079-the-stat-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/083-the-ionice-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/086-the-rsync-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/087-the-dig-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/088-the-whois-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/090-the-awk-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/094-the-pstree-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/095-the-tree-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/097-the-printf-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/098-the-cut-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/099-the-sed-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/103-the-rmdir-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/108-the-screen-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/109-the-nc-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/110-the-make-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/111-the-basename-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/112-the-banner-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/114-the-which-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/117-the-nice-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/118-the-wc-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/119-the-tr-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/121-the-wait-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/122-the-zcat-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/123-the-fold-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/124-the-quota-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/125-the-aplay-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/126-the-spd-say-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/127-the-xeyes-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/129-the-nl-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/130-the-pidof-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/131-the-shuf-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/134-the-cmp-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/135-the-expr-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/trash/000-the-introduction-command.md (100%) rename landing/docs/{commands/.recycle => .recycle/.recycle2}/trash/999-wrap-up.md (100%) rename landing/docs/{ => .recycle}/assets/cover.jpg (100%) rename landing/docs/{ => .recycle}/assets/cover.jpg-bak (100%) rename landing/docs/{ => .recycle}/assets/cover.png (100%) rename landing/docs/{ => .recycle}/assets/styling (copy 1).css (100%) rename landing/docs/{ => .recycle}/assets/styling (copy 2).css (100%) rename landing/docs/{ => .recycle}/assets/styling.css (100%) rename landing/docs/{.Bash-Scripting => Bash-Scripts/.recycle}/000-about-the-author.md (100%) rename landing/docs/{.Bash-Scripting => Bash-Scripts/.recycle}/001-introduction-to-bash.md (100%) rename landing/docs/{.Bash-Scripting => Bash-Scripts/.recycle}/019-working-with-cloudflare-api-with-bash.md (100%) rename landing/docs/{.Bash-Scripting => Bash-Scripts/.recycle}/020-nginx-and-apache-log-parser.md (100%) rename landing/docs/{.Bash-Scripting => Bash-Scripts/.recycle}/021-how-to-send-emails-with-bash.md (100%) rename landing/docs/{.Bash-Scripting => Bash-Scripts/.recycle}/022-bash-password-generator.md (100%) rename landing/docs/{.Bash-Scripting => Bash-Scripts/.recycle}/024-automating-wordpress-lamp-with-bash.md (100%) rename landing/docs/{.Bash-Scripting => Bash-Scripts/.recycle}/100-bash-wrap-up.md (100%) create mode 100644 landing/docs/Bash-Scripts/002-bash-structure.md create mode 100644 landing/docs/Bash-Scripts/003-bash-hello-world.md create mode 100644 landing/docs/Bash-Scripts/004-bash-variables.md create mode 100644 landing/docs/Bash-Scripts/005-bash-user-input.md create mode 100644 landing/docs/Bash-Scripts/006-bash-comments.md create mode 100644 landing/docs/Bash-Scripts/007-bash-arguments.md create mode 100644 landing/docs/Bash-Scripts/008-bash-arrays.md create mode 100644 landing/docs/Bash-Scripts/009-bash-conditional-expressions.md create mode 100644 landing/docs/Bash-Scripts/010-bash-conditionals.md create mode 100644 landing/docs/Bash-Scripts/011-bash-loops.md create mode 100644 landing/docs/Bash-Scripts/012-bash-functions.md create mode 100644 landing/docs/Bash-Scripts/013-debugging.md create mode 100644 landing/docs/Bash-Scripts/0131-debugging.md create mode 100644 landing/docs/Bash-Scripts/014-creating-custom-bash-commands.md create mode 100644 landing/docs/Bash-Scripts/015-writing-your-first-bash-script.md create mode 100644 landing/docs/Bash-Scripts/016-creating-an-interactive-menu-in-bash.md create mode 100644 landing/docs/Bash-Scripts/017-executing-bash-script-on-multiple-remote-server.md create mode 100644 landing/docs/Bash-Scripts/018-working-with-json-in-bash-using-jq.md create mode 100644 landing/docs/Bash-Scripts/023-bash-redirection.md rename landing/docs/{commands/archives => Commands/archive}/gunzip.md (100%) rename landing/docs/{commands/archives => Commands/archive}/gzip.md (100%) rename landing/docs/{commands/archives => Commands/archive}/tar.md (100%) rename landing/docs/{commands/archives => Commands/archive}/unzip.md (100%) rename landing/docs/{commands/archives => Commands/archive}/zip.md (100%) rename landing/docs/{commands/terminal => Commands/core}/alias.md (100%) rename landing/docs/{commands/terminal => Commands/core}/cd.md (100%) rename landing/docs/{commands/terminal => Commands/core}/clear.md (100%) rename landing/docs/{commands/terminal => Commands/core}/echo.md (100%) rename landing/docs/{commands/system => Commands/core}/env.md (100%) rename landing/docs/{commands/terminal => Commands/core}/exit.md (100%) rename landing/docs/{commands/terminal => Commands/core}/history.md (100%) rename landing/docs/{commands/terminal => Commands/core}/less.md (100%) rename landing/docs/{commands/system => Commands/core}/man.md (100%) rename landing/docs/{commands/terminal => Commands/core}/pwd.md (100%) rename landing/docs/{commands/terminal => Commands/core}/sleep.md (100%) rename landing/docs/{commands/system => Commands/core}/whereis.md (100%) rename landing/docs/{commands/terminal => Commands/core}/yes.md (100%) rename landing/docs/{commands => Commands}/disk/fdisk.md (100%) rename landing/docs/{commands => Commands}/disk/mount.md (100%) rename landing/docs/{commands => Commands}/disk/parted.md (100%) rename landing/docs/{commands => Commands}/files/cat.md (100%) rename landing/docs/{commands => Commands}/files/cp.md (100%) rename landing/docs/{commands => Commands}/files/diff.md (100%) rename landing/docs/{commands => Commands}/files/dir.md (100%) rename landing/docs/{commands/disk => Commands/files}/du.md (100%) rename landing/docs/{commands => Commands}/files/find.md (100%) rename landing/docs/{commands/terminal => Commands/files}/grep.md (100%) rename landing/docs/{commands/terminal => Commands/files}/head.md (100%) rename landing/docs/{commands => Commands}/files/ls.md (100%) rename landing/docs/{commands => Commands}/files/mkdir.md (100%) rename landing/docs/{commands => Commands}/files/mv.md (100%) rename landing/docs/{commands => Commands}/files/nano.md (100%) rename landing/docs/{commands => Commands}/files/rm.md (100%) rename landing/docs/{commands/terminal => Commands/files}/tail.md (100%) rename landing/docs/{commands => Commands}/files/touch.md (100%) rename landing/docs/{commands => Commands}/files/vim.md (100%) rename landing/docs/{commands/terminal => Commands/files}/xargs.md (100%) create mode 100644 landing/docs/Commands/index.md rename landing/docs/{commands/disk => Commands/monitor}/df.md (100%) rename landing/docs/{commands/terminal => Commands/monitor}/htop.md (100%) rename landing/docs/{commands/disk => Commands/monitor}/lsblk.md (100%) rename landing/docs/{commands/networking => Commands/monitor}/netstat.md (100%) rename landing/docs/{commands/processes => Commands/monitor}/ps.md (100%) rename landing/docs/{commands/terminal => Commands/monitor}/top.md (100%) rename landing/docs/{commands/networking => Commands/network}/curl.md (100%) rename landing/docs/{commands/networking => Commands/network}/ifconfig.md (100%) rename landing/docs/{commands/networking => Commands/network}/nslookup.md (100%) rename landing/docs/{commands/networking => Commands/network}/ping.md (100%) rename landing/docs/{commands/networking => Commands/network}/ssh.md (100%) rename landing/docs/{commands/networking => Commands/network}/wget.md (100%) rename landing/docs/{commands/processes => Commands/process}/kill.md (100%) rename landing/docs/{commands/processes => Commands/process}/killall.md (100%) rename landing/docs/{commands/processes => Commands/process}/nohup.md (100%) rename landing/docs/{commands/system => Commands/software}/apt.md (100%) rename landing/docs/{commands/system => Commands/software}/yum.md (100%) rename landing/docs/{commands => Commands}/system/crontab.md (100%) rename landing/docs/{commands => Commands}/system/date.md (100%) rename landing/docs/{commands => Commands}/system/hostname.md (100%) rename landing/docs/{commands => Commands}/system/hostnamectl.md (100%) rename landing/docs/{commands => Commands}/system/reboot.md (100%) rename landing/docs/{commands => Commands}/system/shutdown.md (100%) rename landing/docs/{commands => Commands}/system/su.md (100%) rename landing/docs/{commands => Commands}/system/sudo.md (100%) rename landing/docs/{commands => Commands}/system/uname.md (100%) rename landing/docs/{commands/access => Commands/users}/chmod.md (100%) rename landing/docs/{commands/access => Commands/users}/chown.md (100%) rename landing/docs/{commands/access => Commands/users}/deluser.md (100%) rename landing/docs/{commands/access => Commands/users}/groups.md (100%) rename landing/docs/{commands/access => Commands/users}/passwd.md (100%) rename landing/docs/{commands/access => Commands/users}/useradd.md (100%) rename landing/docs/{commands/access => Commands/users}/usermod.md (100%) rename landing/docs/{commands/access => Commands/users}/whoami.md (100%) delete mode 100644 landing/docs/commands/index.md create mode 100644 landing/docs/gemini diff --git a/landing/docs/commands/system/cmatrix.md b/landing/cmatrix.md similarity index 100% rename from landing/docs/commands/system/cmatrix.md rename to landing/cmatrix.md diff --git a/landing/docs/.Bash-Scripting/002-bash-structure.md b/landing/docs/.Bash-Scripting/002-bash-structure.md deleted file mode 100644 index 9cc7d59..0000000 --- a/landing/docs/.Bash-Scripting/002-bash-structure.md +++ /dev/null @@ -1,32 +0,0 @@ -# Bash Structure - -Let's start by creating a new file with a `.sh` extension. As an example, we could create a file called `devdojo.sh`. - -To create that file, you can use the `touch` command: - -```bash -touch devdojo.sh -``` - -Or you can use your text editor instead: - -```bash -nano devdojo.sh -``` - -In order to execute/run a bash script file with the bash shell interpreter, the first line of a script file must indicate the absolute path to the bash executable: - -```bash -#!/bin/bash -``` - -This is also called a [Shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)). - -All that the shebang does is to instruct the operating system to run the script with the `/bin/bash` executable. - -However, bash is not always in `/bin/bash` directory, particularly on non-Linux systems or due to installation as an optional package. Thus, you may want to use: - -```bash -#!/usr/bin/env bash -``` -It searches for bash executable in directories, listed in PATH environmental variable. diff --git a/landing/docs/.Bash-Scripting/003-bash-hello-world.md b/landing/docs/.Bash-Scripting/003-bash-hello-world.md deleted file mode 100644 index 82b8066..0000000 --- a/landing/docs/.Bash-Scripting/003-bash-hello-world.md +++ /dev/null @@ -1,41 +0,0 @@ -# Bash Hello World - -Once we have our `devdojo.sh` file created and we've specified the bash shebang on the very first line, we are ready to create our first `Hello World` bash script. - -To do that, open the `devdojo.sh` file again and add the following after the `#!/bin/bash` line: - -```bash -#!/bin/bash - -echo "Hello World!" -``` - -Save the file and exit. - -After that make the script executable by running: - -```bash -chmod +x devdojo.sh -``` - -After that execute the file: - -```bash -./devdojo.sh -``` - -You will see a "Hello World" message on the screen. - -Another way to run the script would be: - -```bash -bash devdojo.sh -``` - -As bash can be used interactively, you could run the following command directly in your terminal and you would get the same result: - -```bash -echo "Hello DevDojo!" -``` - -Putting a script together is useful once you have to combine multiple commands together. diff --git a/landing/docs/.Bash-Scripting/004-bash-variables.md b/landing/docs/.Bash-Scripting/004-bash-variables.md deleted file mode 100644 index df01e3d..0000000 --- a/landing/docs/.Bash-Scripting/004-bash-variables.md +++ /dev/null @@ -1,131 +0,0 @@ -# Bash Variables - -As in any other programming language, you can use variables in Bash Scripting as well. However, there are no data types, and a variable in Bash can contain numbers as well as characters. - -To assign a value to a variable, all you need to do is use the `=` sign: - -```bash -name="DevDojo" -``` - ->{notice} as an important note, you can not have spaces before and after the `=` sign. - -After that, to access the variable, you have to use the `$` and reference it as shown below: - -```bash -echo $name -``` - -Wrapping the variable name between curly brackets is not required, but is considered a good practice, and I would advise you to use them whenever you can: - -```bash -echo ${name} -``` - -The above code would output: `DevDojo` as this is the value of our `name` variable. - -Next, let's update our `devdojo.sh` script and include a variable in it. - -Again, you can open the file `devdojo.sh` with your favorite text editor, I'm using nano here to open the file: - -```bash -nano devdojo.sh -``` - -Adding our `name` variable here in the file, with a welcome message. Our file now looks like this: - -```bash -#!/bin/bash - -name="DevDojo" - -echo "Hi there $name" -``` - -Save it and run the file using the command below: - -```bash -./devdojo.sh -``` - -You would see the following output on your screen: - -```bash -Hi there DevDojo -``` - -Here is a rundown of the script written in the file: - -* `#!/bin/bash` - At first, we specified our shebang. -* `name=DevDojo` - Then, we defined a variable called `name` and assigned a value to it. -* `echo "Hi there $name"` - Finally, we output the content of the variable on the screen as a welcome message by using `echo` - -You can also add multiple variables in the file as shown below: - -```bash -#!/bin/bash - -name="DevDojo" -greeting="Hello" - -echo "$greeting $name" -``` - -Save the file and run it again: - -```bash -./devdojo.sh -``` - -You would see the following output on your screen: - -```bash -Hello DevDojo -``` -Note that you don't necessarily need to add semicolon `;` at the end of each line. It works both ways, a bit like other programming language such as JavaScript! - - -You can also add variables in the Command Line outside the Bash script and they can be read as parameters: - -```bash -./devdojo.sh Bobby buddy! -``` -This script takes in two parameters `Bobby`and `buddy!` separated by space. In the `devdojo.sh` file we have the following: - -```bash -#!/bin/bash - -echo "Hello there" $1 - -``` -`$1` is the first input (`Bobby`) in the Command Line. Similarly, there could be more inputs and they are all referenced to by the `$` sign and their respective order of input. This means that `buddy!` is referenced to using `$2`. Another useful method for reading variables is the `$@` which reads all inputs. - -So now let's change the `devdojo.sh` file to better understand: - -```bash -#!/bin/bash - -echo "Hello there" $1 - -# $1 : first parameter - -echo "Hello there" $2 - -# $2 : second parameter - -echo "Hello there" $@ - -# $@ : all -``` -The output for: - -```bash -./devdojo.sh Bobby buddy! -``` -Would be the following: - -```bash -Hello there Bobby -Hello there buddy! -Hello there Bobby buddy! -``` diff --git a/landing/docs/.Bash-Scripting/005-bash-user-input.md b/landing/docs/.Bash-Scripting/005-bash-user-input.md deleted file mode 100644 index c0ed6d7..0000000 --- a/landing/docs/.Bash-Scripting/005-bash-user-input.md +++ /dev/null @@ -1,54 +0,0 @@ -# Bash User Input - -With the previous script, we defined a variable, and we output the value of the variable on the screen with the `echo $name`. - -Now let's go ahead and ask the user for input instead. To do that again, open the file with your favorite text editor and update the script as follows: - -```bash -#!/bin/bash - -echo "What is your name?" -read name - -echo "Hi there $name" -echo "Welcome to DevDojo!" -``` - -The above will prompt the user for input and then store that input as a string/text in a variable. - -We can then use the variable and print a message back to them. - -The output of the above script would be: - -* First run the script: - -```bash -./devdojo.sh -``` - -* Then, you would be prompted to enter your name: - -``` -What is your name? -Bobby -``` - -* Once you've typed your name, just hit enter, and you will get the following output: - -``` -Hi there Bobby -Welcome to DevDojo! -``` - -To reduce the code, we could change the first `echo` statement with the `read -p`, the `read` command used with `-p` flag will print a message before prompting the user for their input: - -```bash -#!/bin/bash - -read -p "What is your name? " name - -echo "Hi there $name" -echo "Welcome to DevDojo!" -``` - -Make sure to test this out yourself as well! \ No newline at end of file diff --git a/landing/docs/.Bash-Scripting/006-bash-comments.md b/landing/docs/.Bash-Scripting/006-bash-comments.md deleted file mode 100644 index 4851007..0000000 --- a/landing/docs/.Bash-Scripting/006-bash-comments.md +++ /dev/null @@ -1,27 +0,0 @@ -# Bash Comments - -As with any other programming language, you can add comments to your script. Comments are used to leave yourself notes through your code. - -To do that in Bash, you need to add the `#` symbol at the beginning of the line. Comments will never be rendered on the screen. - -Here is an example of a comment: - -```bash -# This is a comment and will not be rendered on the screen -``` - -Let's go ahead and add some comments to our script: - -```bash -#!/bin/bash - -# Ask the user for their name - -read -p "What is your name? " name - -# Greet the user -echo "Hi there $name" -echo "Welcome to DevDojo!" -``` - -Comments are a great way to describe some of the more complex functionality directly in your scripts so that other people could find their way around your code with ease. \ No newline at end of file diff --git a/landing/docs/.Bash-Scripting/007-bash-arguments.md b/landing/docs/.Bash-Scripting/007-bash-arguments.md deleted file mode 100644 index 87fe90c..0000000 --- a/landing/docs/.Bash-Scripting/007-bash-arguments.md +++ /dev/null @@ -1,81 +0,0 @@ -# Bash Arguments - -You can pass arguments to your shell script when you execute it. To pass an argument, you just need to write it right after the name of your script. For example: - -```bash -./devdojo.com your_argument -``` - -In the script, we can then use `$1` in order to reference the first argument that we specified. - -If we pass a second argument, it would be available as `$2` and so on. - -Let's create a short script called `arguments.sh` as an example: - -```bash -#!/bin/bash - -echo "Argument one is $1" -echo "Argument two is $2" -echo "Argument three is $3" -``` - -Save the file and make it executable: - -```bash -chmod +x arguments.sh -``` - -Then run the file and pass **3** arguments: - -```bash -./arguments.sh dog cat bird -``` - -The output that you would get would be: - -```bash -Argument one is dog -Argument two is cat -Argument three is bird -``` - -To reference all arguments, you can use `$@`: - -```bash -#!/bin/bash - -echo "All arguments: $@" -``` - -If you run the script again: - -```bash -./arguments.sh dog cat bird -``` - -You will get the following output: - -``` -All arguments: dog cat bird -``` - -Another thing that you need to keep in mind is that `$0` is used to reference the script itself. - -This is an excellent way to create self destruct the file if you need to or just get the name of the script. - -For example, let's create a script that prints out the name of the file and deletes the file after that: - -```bash -#!/bin/bash - -echo "The name of the file is: $0 and it is going to be self-deleted." - -rm -f $0 -``` - -You need to be careful with the self deletion and ensure that you have your script backed up before you self-delete it. - - - - diff --git a/landing/docs/.Bash-Scripting/008-bash-arrays.md b/landing/docs/.Bash-Scripting/008-bash-arrays.md deleted file mode 100644 index 568bc6d..0000000 --- a/landing/docs/.Bash-Scripting/008-bash-arrays.md +++ /dev/null @@ -1,112 +0,0 @@ -# Bash Arrays - -If you have ever done any programming, you are probably already familiar with arrays. - -But just in case you are not a developer, the main thing that you need to know is that unlike variables, arrays can hold several values under one name. - -You can initialize an array by assigning values divided by space and enclosed in `()`. Example: - -```bash -my_array=("value 1" "value 2" "value 3" "value 4") -``` - -To access the elements in the array, you need to reference them by their numeric index. - ->{notice} keep in mind that you need to use curly brackets. - -* Access a single element, this would output: `value 2` - -```bash -echo ${my_array[1]} -``` - -* This would return the last element: `value 4` - -```bash -echo ${my_array[-1]} -``` - -* As with command line arguments using `@` will return all arguments in the array, as follows: `value 1 value 2 value 3 value 4` - -```bash -echo ${my_array[@]} -``` - -* Prepending the array with a hash sign (`#`) would output the total number of elements in the array, in our case it is `4`: - -```bash -echo ${#my_array[@]} -``` - -Make sure to test this and practice it at your end with different values. - -## Substring in Bash :: Slicing - -Let's review the following example of slicing in a string in Bash: - -```bash -#!/bin/bash - -letters=( "A""B""C""D""E" ) -echo ${letters[@]} -``` - -This command will print all the elements of an array. - -Output: - -```bash -$ ABCDE -``` - - -Let's see a few more examples: - -- Example 1 - -```bash -#!/bin/bash - -letters=( "A""B""C""D""E" ) -b=${letters:0:2} -echo "${b}" -``` - -This command will print array from starting index 0 to 2 where 2 is exclusive. - -```bash -$ AB -``` - - - Example 2 - -```bash -#!/bin/bash - -letters=( "A""B""C""D""E" ) -b=${letters::5} -echo "${b}" -``` - -This command will print from base index 0 to 5, where 5 is exclusive and starting index is default set to 0 . - -```bash -$ ABCDE -``` - -- Example 3 - -```bash -#!/bin/bash - -letters=( "A""B""C""D""E" ) -b=${letters:3} -echo "${b}" -``` - -This command will print from starting index - 3 to end of array inclusive . - - ```bash - $ DE - ``` diff --git a/landing/docs/.Bash-Scripting/009-bash-conditional-expressions.md b/landing/docs/.Bash-Scripting/009-bash-conditional-expressions.md deleted file mode 100644 index 5a96980..0000000 --- a/landing/docs/.Bash-Scripting/009-bash-conditional-expressions.md +++ /dev/null @@ -1,186 +0,0 @@ -# Bash Conditional Expressions - -In computer science, conditional statements, conditional expressions, and conditional constructs are features of a programming language, which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false. - -In Bash, conditional expressions are used by the `[[` compound command and the `[`built-in commands to test file attributes and perform string and arithmetic comparisons. - -Here is a list of the most popular Bash conditional expressions. You do not have to memorize them by heart. You can simply refer back to this list whenever you need it! - -## File expressions - -* True if file exists. - -```bash -[[ -a ${file} ]] -``` - -* True if file exists and is a block special file. - -```bash -[[ -b ${file} ]] -``` - -* True if file exists and is a character special file. - -```bash -[[ -c ${file} ]] -``` - -* True if file exists and is a directory. - -```bash -[[ -d ${file} ]] -``` - -* True if file exists. - -```bash -[[ -e ${file} ]] -``` - -* True if file exists and is a regular file. - -```bash -[[ -f ${file} ]] -``` - -* True if file exists and is a symbolic link. - -```bash -[[ -h ${file} ]] -``` - -* True if file exists and is readable. - -```bash -[[ -r ${file} ]] -``` - -* True if file exists and has a size greater than zero. - -```bash -[[ -s ${file} ]] -``` - -* True if file exists and is writable. - -```bash -[[ -w ${file} ]] -``` - -* True if file exists and is executable. - -```bash -[[ -x ${file} ]] -``` - -* True if file exists and is a symbolic link. - -```bash -[[ -L ${file} ]] -``` - -## String expressions - -* True if the shell variable varname is set (has been assigned a value). - -```bash -[[ -v ${varname} ]] -``` - -True if the length of the string is zero. - -```bash -[[ -z ${string} ]] -``` - -True if the length of the string is non-zero. - -```bash -[[ -n ${string} ]] -``` - -* True if the strings are equal. `=` should be used with the test command for POSIX conformance. When used with the `[[` command, this performs pattern matching as described above (Compound Commands). - -```bash -[[ ${string1} == ${string2} ]] -``` - -* True if the strings are not equal. - -```bash -[[ ${string1} != ${string2} ]] -``` - -* True if string1 sorts before string2 lexicographically. - -```bash -[[ ${string1} < ${string2} ]] -``` - -* True if string1 sorts after string2 lexicographically. - -```bash -[[ ${string1} > ${string2} ]] -``` - -## Arithmetic operators - -* Returns true if the numbers are **equal** - -```bash -[[ ${arg1} -eq ${arg2} ]] -``` - -* Returns true if the numbers are **not equal** - -```bash -[[ ${arg1} -ne ${arg2} ]] -``` - -* Returns true if arg1 is **less than** arg2 - -```bash -[[ ${arg1} -lt ${arg2} ]] -``` - -* Returns true if arg1 is **less than or equal** arg2 - -```bash -[[ ${arg1} -le ${arg2} ]] -``` - -* Returns true if arg1 is **greater than** arg2 - -```bash -[[ ${arg1} -gt ${arg2} ]] -``` - -* Returns true if arg1 is **greater than or equal** arg2 - -```bash -[[ ${arg1} -ge ${arg2} ]] -``` - -As a side note, arg1 and arg2 may be positive or negative integers. - -As with other programming languages you can use `AND` & `OR` conditions: - -```bash -[[ test_case_1 ]] && [[ test_case_2 ]] # And -[[ test_case_1 ]] || [[ test_case_2 ]] # Or -``` - -## Exit status operators - -* returns true if the command was successful without any errors - -```bash -[[ $? -eq 0 ]] -``` - -* returns true if the command was not successful or had errors - -```bash -[[ $? -gt 0 ]] -``` diff --git a/landing/docs/.Bash-Scripting/010-bash-conditionals.md b/landing/docs/.Bash-Scripting/010-bash-conditionals.md deleted file mode 100644 index f6f5e93..0000000 --- a/landing/docs/.Bash-Scripting/010-bash-conditionals.md +++ /dev/null @@ -1,187 +0,0 @@ -# Bash Conditionals - -In the last section, we covered some of the most popular conditional expressions. We can now use them with standard conditional statements like `if`, `if-else` and `switch case` statements. - -## If statement - -The format of an `if` statement in Bash is as follows: - -```bash -if [[ some_test ]] -then - -fi -``` - -Here is a quick example which would ask you to enter your name in case that you've left it empty: - -```bash -#!/bin/bash - -# Bash if statement example - -read -p "What is your name? " name - -if [[ -z ${name} ]] -then - echo "Please enter your name!" -fi -``` - -## If Else statement - -With an `if-else` statement, you can specify an action in case that the condition in the `if` statement does not match. We can combine this with the conditional expressions from the previous section as follows: - -```bash -#!/bin/bash - -# Bash if statement example - -read -p "What is your name? " name - -if [[ -z ${name} ]] -then - echo "Please enter your name!" -else - echo "Hi there ${name}" -fi -``` - -You can use the above if statement with all of the conditional expressions from the previous chapters: - -```bash -#!/bin/bash - -admin="devdojo" - -read -p "Enter your username? " username - -# Check if the username provided is the admin - -if [[ "${username}" == "${admin}" ]] ; then - echo "You are the admin user!" -else - echo "You are NOT the admin user!" -fi -``` - -Here is another example of an `if` statement which would check your current `User ID` and would not allow you to run the script as the `root` user: - -```bash -#!/bin/bash - -if (( $EUID == 0 )); then - echo "Please do not run as root" - exit -fi -``` - -If you put this on top of your script it would exit in case that the EUID is 0 and would not execute the rest of the script. This was discussed on [the DigitalOcean community forum](https://www.digitalocean.com/community/questions/how-to-check-if-running-as-root-in-a-bash-script). - -You can also test multiple conditions with an `if` statement. In this example we want to make sure that the user is neither the admin user nor the root user to ensure the script is incapable of causing too much damage. We'll use the `or` operator in this example, noted by `||`. This means that either of the conditions needs to be true. If we used the `and` operator of `&&` then both conditions would need to be true. - -```bash -#!/bin/bash - -admin="devdojo" - -read -p "Enter your username? " username - -# Check if the username provided is the admin - -if [[ "${username}" != "${admin}" ]] || [[ $EUID != 0 ]] ; then - echo "You are not the admin or root user, but please be safe!" -else - echo "You are the admin user! This could be very destructive!" -fi -``` - -If you have multiple conditions and scenarios, then can use `elif` statement with `if` and `else` statements. - -```bash -#!/bin/bash - -read -p "Enter a number: " num - -if [[ $num -gt 0 ]] ; then - echo "The number is positive" -elif [[ $num -lt 0 ]] ; then - echo "The number is negative" -else - echo "The number is 0" -fi -``` - -## Switch case statements - -As in other programming languages, you can use a `case` statement to simplify complex conditionals when there are multiple different choices. So rather than using a few `if`, and `if-else` statements, you could use a single `case` statement. - -The Bash `case` statement syntax looks like this: - -```bash -case $some_variable in - - pattern_1) - commands - ;; - - pattern_2| pattern_3) - commands - ;; - - *) - default commands - ;; -esac -``` - -A quick rundown of the structure: - -* All `case` statements start with the `case` keyword. -* On the same line as the `case` keyword, you need to specify a variable or an expression followed by the `in` keyword. -* After that, you have your `case` patterns, where you need to use `)` to identify the end of the pattern. -* You can specify multiple patterns divided by a pipe: `|`. -* After the pattern, you specify the commands that you would like to be executed in case that the pattern matches the variable or the expression that you've specified. -* All clauses have to be terminated by adding `;;` at the end. -* You can have a default statement by adding a `*` as the pattern. -* To close the `case` statement, use the `esac` (case typed backwards) keyword. - -Here is an example of a Bash `case` statement: - -```bash -#!/bin/bash - -read -p "Enter the name of your car brand: " car - -case $car in - - Tesla) - echo -n "${car}'s car factory is in the USA." - ;; - - BMW | Mercedes | Audi | Porsche) - echo -n "${car}'s car factory is in Germany." - ;; - - Toyota | Mazda | Mitsubishi | Subaru) - echo -n "${car}'s car factory is in Japan." - ;; - - *) - echo -n "${car} is an unknown car brand" - ;; - -esac -``` - -With this script, we are asking the user to input a name of a car brand like Telsa, BMW, Mercedes and etc. - -Then with a `case` statement, we check the brand name and if it matches any of our patterns, and if so, we print out the factory's location. - -If the brand name does not match any of our `case` statements, we print out a default message: `an unknown car brand`. - -## Conclusion - -I would advise you to try and modify the script and play with it a bit so that you could practice what you've just learned in the last two chapters! - -For more examples of Bash `case` statements, make sure to check chapter 16, where we would create an interactive menu in Bash using a `cases` statement to process the user input. diff --git a/landing/docs/.Bash-Scripting/011-bash-loops.md b/landing/docs/.Bash-Scripting/011-bash-loops.md deleted file mode 100644 index 37defdd..0000000 --- a/landing/docs/.Bash-Scripting/011-bash-loops.md +++ /dev/null @@ -1,197 +0,0 @@ -# Bash Loops - -As with any other language, loops are very convenient. With Bash you can use `for` loops, `while` loops, and `until` loops. - -## For loops - -Here is the structure of a for loop: - -```bash -for var in ${list} -do - your_commands -done -``` - -Example: - -```bash -#!/bin/bash - -users="devdojo bobby tony" - -for user in ${users} -do - echo "${user}" -done -``` - -A quick rundown of the example: - -* First, we specify a list of users and store the value in a variable called `$users`. -* After that, we start our `for` loop with the `for` keyword. -* Then we define a new variable which would represent each item from the list that we give. In our case, we define a variable called `user`, which would represent each user from the `$users` variable. -* Then we specify the `in` keyword followed by our list that we will loop through. -* On the next line, we use the `do` keyword, which indicates what we will do for each iteration of the loop. -* Then we specify the commands that we want to run. -* Finally, we close the loop with the `done` keyword. - -You can also use `for` to process a series of numbers. For example here is one way to loop through from 1 to 10: - -```bash -#!/bin/bash - -for num in {1..10} -do - echo ${num} -done -``` - -## While loops - -The structure of a while loop is quite similar to the `for` loop: - -```bash -while [ your_condition ] -do - your_commands -done -``` - -Here is an example of a `while` loop: - -```bash -#!/bin/bash - -counter=1 -while [[ $counter -le 10 ]] -do - echo $counter - ((counter++)) -done -``` - -First, we specified a counter variable and set it to `1`, then inside the loop, we added counter by using this statement here: `((counter++))`. That way, we make sure that the loop will run 10 times only and would not run forever. The loop will complete as soon as the counter becomes 10, as this is what we've set as the condition: `while [[ $counter -le 10 ]]`. - -Let's create a script that asks the user for their name and not allow an empty input: - -```bash -#!/bin/bash - -read -p "What is your name? " name - -while [[ -z ${name} ]] -do - echo "Your name can not be blank. Please enter a valid name!" - read -p "Enter your name again? " name -done - -echo "Hi there ${name}" -``` - -Now, if you run the above and just press enter without providing input, the loop would run again and ask you for your name again and again until you actually provide some input. - -## Until Loops - -The difference between `until` and `while` loops is that the `until` loop will run the commands within the loop until the condition becomes true. - -Structure: - -```bash -until [[ your_condition ]] -do - your_commands -done -``` - -Example: - -```bash -#!/bin/bash - -count=1 -until [[ $count -gt 10 ]] -do - echo $count - ((count++)) -done -``` - -## Continue and Break -As with other languages, you can use `continue` and `break` with your bash scripts as well: - -* `continue` tells your bash script to stop the current iteration of the loop and start the next iteration. - -The syntax of the continue statement is as follows: - -```bash -continue [n] -``` - -The [n] argument is optional and can be greater than or equal to 1. When [n] is given, the n-th enclosing loop is resumed. continue 1 is equivalent to continue. - -```bash -#!/bin/bash - -for i in 1 2 3 4 5 -do - if [[ $i –eq 2 ]] - then - echo "skipping number 2" - continue - fi - echo "i is equal to $i" -done -``` - -We can also use continue command in similar way to break command for controlling multiple loops. - -* `break` tells your bash script to end the loop straight away. - -The syntax of the break statement takes the following form: - -```bash -break [n] -``` -[n] is an optional argument and must be greater than or equal to 1. When [n] is provided, the n-th enclosing loop is exited. break 1 is equivalent to break. - -Example: - -```bash -#!/bin/bash - -num=1 -while [[ $num –lt 10 ]] -do - if [[ $num –eq 5 ]] - then - break - fi - ((num++)) -done -echo "Loop completed" -``` - -We can also use break command with multiple loops. If we want to exit out of current working loop whether inner or outer loop, we simply use break but if we are in inner loop & want to exit out of outer loop, we use break 2. - -Example: - -```bash -#!/bin/bash - -for (( a = 1; a < 10; a++ )) -do - echo "outer loop: $a" - for (( b = 1; b < 100; b++ )) - do - if [[ $b –gt 5 ]] - then - break 2 - fi - echo "Inner loop: $b " - done -done -``` - -The bash script will begin with a=1 & will move to inner loop and when it reaches b=5, it will break the outer loop. -We can use break only instead of break 2, to break inner loop & see how it affects the output. diff --git a/landing/docs/.Bash-Scripting/012-bash-functions.md b/landing/docs/.Bash-Scripting/012-bash-functions.md deleted file mode 100644 index 1154962..0000000 --- a/landing/docs/.Bash-Scripting/012-bash-functions.md +++ /dev/null @@ -1,66 +0,0 @@ -# Bash Functions - -Functions are a great way to reuse code. The structure of a function in bash is quite similar to most languages: - -```bash -function function_name() { - your_commands -} -``` - -You can also omit the `function` keyword at the beginning, which would also work: - -```bash -function_name() { - your_commands -} -``` - -I prefer putting it there for better readability. But it is a matter of personal preference. - -Example of a "Hello World!" function: - -```bash -#!/bin/bash - -function hello() { - echo "Hello World Function!" -} - -hello -``` - ->{notice} One thing to keep in mind is that you should not add the parenthesis when you call the function. - -Passing arguments to a function work in the same way as passing arguments to a script: - -```bash -#!/bin/bash - -function hello() { - echo "Hello $1!" -} - -hello DevDojo -``` - -Functions should have comments mentioning description, global variables, arguments, outputs, and returned values, if applicable - -```bash -####################################### -# Description: Hello function -# Globals: -# None -# Arguments: -# Single input argument -# Outputs: -# Value of input argument -# Returns: -# 0 if successful, non-zero on error. -####################################### -function hello() { - echo "Hello $1!" -} -``` - -In the next few chapters we will be using functions a lot! diff --git a/landing/docs/.Bash-Scripting/013-debugging-and-testing.md b/landing/docs/.Bash-Scripting/013-debugging-and-testing.md deleted file mode 100644 index 06455fc..0000000 --- a/landing/docs/.Bash-Scripting/013-debugging-and-testing.md +++ /dev/null @@ -1,83 +0,0 @@ -# Debugging, testing and shortcuts - -In order to debug your bash scripts, you can use `-x` when executing your scripts: - -```bash -bash -x ./your_script.sh -``` - -Or you can add `set -x` before the specific line that you want to debug, `set -x` enables a mode of the shell where all executed commands are printed to the terminal. - -Another way to test your scripts is to use this fantastic tool here: - -[https://www.shellcheck.net/](https://www.shellcheck.net/) - -Just copy and paste your code into the textbox, and the tool will give you some suggestions on how you can improve your script. - -You can also run the tool directly in your terminal: - -[https://github.com/koalaman/shellcheck](https://github.com/koalaman/shellcheck) - -If you like the tool, make sure to star it on GitHub and contribute! - -As a SysAdmin/DevOps, I spend a lot of my day in the terminal. Here are my favorite shortcuts that help me do tasks quicker while writing Bash scripts or just while working in the terminal. - -The below two are particularly useful if you have a very long command. - -* Delete everything from the cursor to the end of the line: - -``` -Ctrl + k -``` - -* Delete everything from the cursor to the start of the line: - -``` -Ctrl + u -``` - -* Delete one word backward from cursor: - -``` -Ctrl + w -``` - -* Search your history backward. This is probably the one that I use the most. It is really handy and speeds up my work-flow a lot: - -``` -Ctrl + r -``` - -* Clear the screen, I use this instead of typing the `clear` command: - -``` -Ctrl + l -``` - -* Stops the output to the screen: - -``` -Ctrl + s -``` - -* Enable the output to the screen in case that previously stopped by `Ctrl + s`: - -``` -Ctrl + q -``` - -* Terminate the current command - -``` -Ctrl + c -``` - -* Throw the current command to background: - -``` -Ctrl + z -``` - -I use those regularly every day, and it saves me a lot of time. - -If you think that I've missed any feel free to join the discussion on [the DigitalOcean community forum](https://www.digitalocean.com/community/questions/what-are-your-favorite-bash-shortcuts)! \ No newline at end of file diff --git a/landing/docs/.Bash-Scripting/014-creating-custom-bash-commands.md b/landing/docs/.Bash-Scripting/014-creating-custom-bash-commands.md deleted file mode 100644 index 762b713..0000000 --- a/landing/docs/.Bash-Scripting/014-creating-custom-bash-commands.md +++ /dev/null @@ -1,83 +0,0 @@ -# Creating custom bash commands - -As a developer or system administrator, you might have to spend a lot of time in your terminal. I always try to look for ways to optimize any repetitive tasks. - -One way to do that is to either write short bash scripts or create custom commands also known as aliases. For example, rather than typing a really long command every time you could just create a shortcut for it. - -## Example - -Let's start with the following scenario, as a system admin, you might have to check the connections to your web server quite often, so I will use the `netstat` command as an example. - -What I would usually do when I access a server that is having issues with the connections to port 80 or 443 is to check if there are any services listening on those ports and the number of connections to the ports. - -The following `netstat` command would show us how many TCP connections on port 80 and 443 we currently have: - -```bash -netstat -plant | grep '80\|443' | grep -v LISTEN | wc -l -``` -This is quite a lengthy command so typing it every time might be time-consuming in the long run especially when you want to get that information quickly. - -To avoid that, we can create an alias, so rather than typing the whole command, we could just type a short command instead. For example, lets say that we wanted to be able to type `conn` (short for connections) and get the same information. All we need to do in this case is to run the following command: - -```bash -alias conn="netstat -plant | grep '80\|443' | grep -v LISTEN | wc -l" -``` - -That way we are creating an alias called `conn` which would essentially be a 'shortcut' for our long `netstat` command. Now if you run just `conn`: - -```bash -conn -``` - -You would get the same output as the long `netstat` command. -You can get even more creative and add some info messages like this one here: - -```bash -alias conn="echo 'Total connections on port 80 and 443:' ; netstat -plant | grep '80\|443' | grep -v LISTEN | wc -l" -``` - -Now if you run `conn` you would get the following output: - -```bash -Total connections on port 80 and 443: -12 -``` -Now if you log out and log back in, your alias would be lost. In the next step you will see how to make this persistent. - -## Making the change persistent - -In order to make the change persistent, we need to add the `alias` command in our shell profile file. - -By default on Ubuntu this would be the `~/.bashrc` file, for other operating systems this might be the `~/.bash_profle`. With your favorite text editor open the file: - -```bash -nano ~/.bashrc -``` - -Go to the bottom and add the following: - -```bash -alias conn="echo 'Total connections on port 80 and 443:' ; netstat -plant | grep '80\|443' | grep -v LISTEN | wc -l" -``` - -Save and then exit. - -That way now even if you log out and log back in again your change would be persisted and you would be able to run your custom bash command. - -## Listing all of the available aliases - -To list all of the available aliases for your current shell, you have to just run the following command: - -```bash -alias -``` - -This would be handy in case that you are seeing some weird behavior with some commands. - -## Conclusion - -This is one way of creating custom bash commands or bash aliases. - -Of course, you could actually write a bash script and add the script inside your `/usr/bin` folder, but this would not work if you don't have root or sudo access, whereas with aliases you can do it without the need of root access. - ->{notice} This was initially posted on [DevDojo.com](https://devdojo.com/bobbyiliev/how-to-create-custom-bash-commands) diff --git a/landing/docs/.Bash-Scripting/015-writing-your-first-bash-script.md b/landing/docs/.Bash-Scripting/015-writing-your-first-bash-script.md deleted file mode 100644 index 5077b66..0000000 --- a/landing/docs/.Bash-Scripting/015-writing-your-first-bash-script.md +++ /dev/null @@ -1,180 +0,0 @@ -# Write your first Bash script - -Let's try to put together what we've learned so far and create our first Bash script! - -## Planning the script - -As an example, we will write a script that would gather some useful information about our server like: - -* Current Disk usage -* Current CPU usage -* Current RAM usage -* Check the exact Kernel version - -Feel free to adjust the script by adding or removing functionality so that it matches your needs. - -## Writing the script - -The first thing that you need to do is to create a new file with a `.sh` extension. I will create a file called `status.sh` as the script that we will create would give us the status of our server. - -Once you've created the file, open it with your favorite text editor. - -As we've learned in chapter 1, on the very first line of our Bash script we need to specify the so-called [Shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)): - -```bash -#!/bin/bash -``` - -All that the shebang does is to instruct the operating system to run the script with the /bin/bash executable. - -## Adding comments - -Next, as discussed in chapter 6, let's start by adding some comments so that people could easily figure out what the script is used for. To do that right after the shebang you can just add the following: - -```bash -#!/bin/bash - -# Script that returns the current server status -``` - -## Adding your first variable - -Then let's go ahead and apply what we've learned in chapter 4 and add some variables which we might want to use throughout the script. - -To assign a value to a variable in bash, you just have to use the `=` sign. For example, let's store the hostname of our server in a variable so that we could use it later: - -```bash -server_name=$(hostname) -``` - -By using `$()` we tell bash to actually interpret the command and then assign the value to our variable. - -Now if we were to echo out the variable we would see the current hostname: - -```bash -echo $server_name -``` - -## Adding your first function - -As you already know after reading chapter 12, in order to create a function in bash you need to use the following structure: - -```bash -function function_name() { - your_commands -} -``` - -Let's create a function that returns the current memory usage on our server: - -```bash -function memory_check() { - echo "" - echo "The current memory usage on ${server_name} is: " - free -h - echo "" -} -``` - -Quick run down of the function: - -* `function memory_check() {` - this is how we define the function -* `echo ""` - here we just print a new line -* `echo "The current memory usage on ${server_name} is: "` - here we print a small message and the `$server_name` variable -* `}` - finally this is how we close the function - -Then once the function has been defined, in order to call it, just use the name of the function: - -```bash -# Define the function -function memory_check() { - echo "" - echo "The current memory usage on ${server_name} is: " - free -h - echo "" -} - -# Call the function -memory_check -``` - -## Adding more functions challenge - -Before checking out the solution, I would challenge you to use the function from above and write a few functions by yourself. - -The functions should do the following: - -* Current Disk usage -* Current CPU usage -* Current RAM usage -* Check the exact Kernel version - -Feel free to use google if you are not sure what commands you need to use in order to get that information. - -Once you are ready, feel free to scroll down and check how we've done it and compare the results! - -Note that there are multiple correct ways of doing it! - -## The sample script - -Here's what the end result would look like: - -```bash -#!/bin/bash - -## -# BASH script that checks: -# - Memory usage -# - CPU load -# - Number of TCP connections -# - Kernel version -## - -server_name=$(hostname) - -function memory_check() { - echo "" - echo "Memory usage on ${server_name} is: " - free -h - echo "" -} - -function cpu_check() { - echo "" - echo "CPU load on ${server_name} is: " - echo "" - uptime - echo "" -} - -function tcp_check() { - echo "" - echo "TCP connections on ${server_name}: " - echo "" - cat /proc/net/tcp | wc -l - echo "" -} - -function kernel_check() { - echo "" - echo "Kernel version on ${server_name} is: " - echo "" - uname -r - echo "" -} - -function all_checks() { - memory_check - cpu_check - tcp_check - kernel_check -} - -all_checks -``` - -## Conclusion - -Bash scripting is awesome! No matter if you are a DevOps/SysOps engineer, developer, or just a Linux enthusiast, you can use Bash scripts to combine different Linux commands and automate boring and repetitive daily tasks, so that you can focus on more productive and fun things! - ->{notice} This was initially posted on [DevDojo.com](https://devdojo.com/bobbyiliev/introduction-to-bash-scripting) diff --git a/landing/docs/.Bash-Scripting/016-creating-an-interactive-menu-in-bash.md b/landing/docs/.Bash-Scripting/016-creating-an-interactive-menu-in-bash.md deleted file mode 100644 index 6666eb5..0000000 --- a/landing/docs/.Bash-Scripting/016-creating-an-interactive-menu-in-bash.md +++ /dev/null @@ -1,305 +0,0 @@ -# Creating an interactive menu in Bash - -In this tutorial, I will show you how to create a multiple-choice menu in Bash so that your users could choose between what action should be executed! - -We would reuse some of the code from the previous chapter, so if you have not read it yet make sure to do so. - -## Planning the functionality - -Let's start again by going over the main functionality of the script: - -* Checks the current Disk usage -* Checks the current CPU usage -* Checks the current RAM usage -* Checks the check the exact Kernel version - -In case that you don't have it on hand, here is the script itself: - -```bash -#!/bin/bash - -## -# BASH menu script that checks: -# - Memory usage -# - CPU load -# - Number of TCP connections -# - Kernel version -## - -server_name=$(hostname) - -function memory_check() { - echo "" - echo "Memory usage on ${server_name} is: " - free -h - echo "" -} - -function cpu_check() { - echo "" - echo "CPU load on ${server_name} is: " - echo "" - uptime - echo "" -} - -function tcp_check() { - echo "" - echo "TCP connections on ${server_name}: " - echo "" - cat /proc/net/tcp | wc -l - echo "" -} - -function kernel_check() { - echo "" - echo "Kernel version on ${server_name} is: " - echo "" - uname -r - echo "" -} - -function all_checks() { - memory_check - cpu_check - tcp_check - kernel_check -} -``` - -We will then build a menu that allows the user to choose which function to be executed. - -Of course, you can adjust the function or add new ones depending on your needs. - -## Adding some colors - -In order to make the menu a bit more 'readable' and easy to grasp at first glance, we will add some color functions. - -At the beginning of your script add the following color functions: - -```bash -## -# Color Variables -## -green='\e[32m' -blue='\e[34m' -clear='\e[0m' - -## -# Color Functions -## - -ColorGreen(){ - echo -ne $green$1$clear -} -ColorBlue(){ - echo -ne $blue$1$clear -} -``` - -You can use the color functions as follows: - -```bash -echo -ne $(ColorBlue 'Some text here') -``` - -The above would output the `Some text here` string and it would be blue! - -# Adding the menu - -Finally, to add our menu, we will create a separate function with a case switch for our menu options: - -```bash -menu(){ -echo -ne " -My First Menu -$(ColorGreen '1)') Memory usage -$(ColorGreen '2)') CPU load -$(ColorGreen '3)') Number of TCP connections -$(ColorGreen '4)') Kernel version -$(ColorGreen '5)') Check All -$(ColorGreen '0)') Exit -$(ColorBlue 'Choose an option:') " - read a - case $a in - 1) memory_check ; menu ;; - 2) cpu_check ; menu ;; - 3) tcp_check ; menu ;; - 4) kernel_check ; menu ;; - 5) all_checks ; menu ;; - 0) exit 0 ;; - *) echo -e $red"Wrong option."$clear; WrongCommand;; - esac -} -``` - -### A quick rundown of the code - -First we just echo out the menu options with some color: - -``` -echo -ne " -My First Menu -$(ColorGreen '1)') Memory usage -$(ColorGreen '2)') CPU load -$(ColorGreen '3)') Number of TCP connections -$(ColorGreen '4)') Kernel version -$(ColorGreen '5)') Check All -$(ColorGreen '0)') Exit -$(ColorBlue 'Choose an option:') " -``` - -Then we read the answer of the user and store it in a variable called `$a`: - -```bash - read a -``` - -Finally, we have a switch case which triggers a different function depending on the value of `$a`: - -```bash - case $a in - 1) memory_check ; menu ;; - 2) cpu_check ; menu ;; - 3) tcp_check ; menu ;; - 4) kernel_check ; menu ;; - 5) all_checks ; menu ;; - 0) exit 0 ;; - *) echo -e $red"Wrong option."$clear; WrongCommand;; - esac -``` - -At the end we need to call the menu function to actually print out the menu: - -```bash -# Call the menu function -menu -``` - -## Testing the script - -In the end, your script will look like this: - -```bash -#!/bin/bash - -## -# BASH menu script that checks: -# - Memory usage -# - CPU load -# - Number of TCP connections -# - Kernel version -## - -server_name=$(hostname) - -function memory_check() { - echo "" - echo "Memory usage on ${server_name} is: " - free -h - echo "" -} - -function cpu_check() { - echo "" - echo "CPU load on ${server_name} is: " - echo "" - uptime - echo "" -} - -function tcp_check() { - echo "" - echo "TCP connections on ${server_name}: " - echo "" - cat /proc/net/tcp | wc -l - echo "" -} - -function kernel_check() { - echo "" - echo "Kernel version on ${server_name} is: " - echo "" - uname -r - echo "" -} - -function all_checks() { - memory_check - cpu_check - tcp_check - kernel_check -} - -## -# Color Variables -## -green='\e[32m' -blue='\e[34m' -clear='\e[0m' - -## -# Color Functions -## - -ColorGreen(){ - echo -ne $green$1$clear -} -ColorBlue(){ - echo -ne $blue$1$clear -} - -menu(){ -echo -ne " -My First Menu -$(ColorGreen '1)') Memory usage -$(ColorGreen '2)') CPU load -$(ColorGreen '3)') Number of TCP connections -$(ColorGreen '4)') Kernel version -$(ColorGreen '5)') Check All -$(ColorGreen '0)') Exit -$(ColorBlue 'Choose an option:') " - read a - case $a in - 1) memory_check ; menu ;; - 2) cpu_check ; menu ;; - 3) tcp_check ; menu ;; - 4) kernel_check ; menu ;; - 5) all_checks ; menu ;; - 0) exit 0 ;; - *) echo -e $red"Wrong option."$clear; WrongCommand;; - esac -} - -# Call the menu function -menu -``` - -To test the script, create a new filed with a `.sh` extension, for example: `menu.sh` and then run it: - -```bash -bash menu.sh -``` - -The output that you would get will look like this: - -```bash -My First Menu -1) Memory usage -2) CPU load -3) Number of TCP connections -4) Kernel version -5) Check All -0) Exit -Choose an option: -``` - -You will be able to choose a different option from the list and each number will call a different function from the script: - -![Nice Bash interactive menu](https://imgur.com/8EgxX4m.png) - -## Conclusion - -You now know how to create a Bash menu and implement it in your scripts so that users could select different values! - ->{notice} This content was initially posted on [DevDojo.com](https://devdojo.com/bobbyiliev/how-to-work-with-json-in-bash-using-jq) diff --git a/landing/docs/.Bash-Scripting/017-executing-bash-script-on-multiple-remote-server.md b/landing/docs/.Bash-Scripting/017-executing-bash-script-on-multiple-remote-server.md deleted file mode 100644 index a4f0d47..0000000 --- a/landing/docs/.Bash-Scripting/017-executing-bash-script-on-multiple-remote-server.md +++ /dev/null @@ -1,129 +0,0 @@ -# Executing BASH scripts on Multiple Remote Servers - -Any command that you can run from the command line can be used in a bash script. Scripts are used to run a series of commands. Bash is available by default on Linux and macOS operating systems. - -Let's have a hypothetical scenario where you need to execute a BASH script on multiple remote servers, but you don't want to manually copy the script to each server, then again login to each server individually and only then execute the script. - -Of course you could use a tool like Ansible but let's learn how to do that with Bash! - -## Prerequisites - -For this example I will use 3 remote Ubuntu servers deployed on DigitalOcean. If you don't have a Digital Ocean account yet, you can sign up for DigitalOcean and get $100 free credit via this referral link here: - -[https://m.do.co/c/2a9bba940f39](https://m.do.co/c/2a9bba940f39) - -Once you have your Digital Ocean account ready go ahead and deploy 3 droplets. - -I've gone ahead and created 3 Ubuntu servers: - -![DigitalOcean Ubuntu servers](https://imgur.com/09xmq41.png) - -I'll put a those servers IP's in a `servers.txt` file which I would use to loop though with our Bash script. - -If you are new to DigitalOcean you can follow the steps on how to create a Droplet here: - -* [How to Create a Droplet from the DigitalOcean Control Panel](https://www.digitalocean.com/docs/droplets/how-to/create/) - -You can also follow the steps from this video here on how to do your initial server setup: - -* [How to do your Initial Server Setup with Ubuntu](https://youtu.be/7NL2_4HIgKU) - -Or even better, you can follow this article here on how to automate your initial server setup with Bash: - -[Automating Initial Server Setup with Ubuntu 18.04 with Bash](https://www.digitalocean.com/community/tutorials/automating-initial-server-setup-with-ubuntu-18-04) - -With the 3 new servers in place, we can go ahead and focus on running our Bash script on all of them with a single command! - -## The BASH Script - -I will reuse the demo script from the previous chapter with some slight changes. It simply executes a few checks like the current memory usage, the current CPU usage, the number of TCP connections and the version of the kernel. - -```bash -#!/bin/bash - -## -# BASH script that checks the following: -# - Memory usage -# - CPU load -# - Number of TCP connections -# - Kernel version -## - -## -# Memory check -## -server_name=$(hostname) - -function memory_check() { - echo "#######" - echo "The current memory usage on ${server_name} is: " - free -h - echo "#######" -} - - -function cpu_check() { - echo "#######" - echo "The current CPU load on ${server_name} is: " - echo "" - uptime - echo "#######" -} - -function tcp_check() { - echo "#######" - echo "Total TCP connections on ${server_name}: " - echo "" - cat /proc/net/tcp | wc -l - echo "#######" -} - -function kernel_check() { - echo "#######" - echo "The exact Kernel version on ${server_name} is: " - echo "" - uname -r - echo "#######" -} - -function all_checks() { - memory_check - cpu_check - tcp_check - kernel_check -} - -all_checks -``` - -Copy the code bellow and add this in a file called `remote_check.sh`. You can also get the script from [here](https://devdojo.com/bobbyiliev/executing-bash-script-on-multiple-remote-server). - -## Running the Script on all Servers - -Now that we have the script and the servers ready and that we've added those servers in our servers.txt file we can run the following command to loop though all servers and execute the script remotely without having to copy the script to each server and individually connect to each server. - -```bash -for server in $(cat servers.txt) ; do ssh your_user@${server} 'bash -s' < ./remote_check.sh ; done -``` - -What this for loop does is, it goes through each server in the servers.txt file and then it runs the following command for each item in the list: - -```bash -ssh your_user@the_server_ip 'bash -s' < ./remote_check.sh -``` - -You would get the following output: - -![Running bash script on multiple remote servers](https://imgur.com/B1AmhUP.png) - -## Conclusion - -This is just a really simple example on how to execute a simple script on multiple servers without having to copy the script to each server and without having to access the servers individually. - -Of course you could run a much more complex script and on many more servers. - -If you are interested in automation, I would recommend checking out the Ansible resources page on the DigitalOcean website: - -[Ansible Resources](https://www.digitalocean.com/community/tags/ansible) - ->{notice} This content was initially posted on [DevDojo](https://devdojo.com/bobbyiliev/bash-script-to-summarize-your-nginx-and-apache-access-logs) diff --git a/landing/docs/.Bash-Scripting/018-working-with-json-in-bash-using-jq.md b/landing/docs/.Bash-Scripting/018-working-with-json-in-bash-using-jq.md deleted file mode 100644 index 8a9e521..0000000 --- a/landing/docs/.Bash-Scripting/018-working-with-json-in-bash-using-jq.md +++ /dev/null @@ -1,225 +0,0 @@ -# Work with JSON in BASH using jq - -The `jq` command-line tool is a lightweight and flexible command-line **JSON** processor. It is great for parsing JSON output in BASH. - -One of the great things about `jq` is that it is written in portable C, and it has zero runtime dependencies. All you need to do is to download a single binary or use a package manager like apt and install it with a single command. - -## Planning the script - -For the demo in this tutorial, I would use an external REST API that returns a simple JSON output called the [QuizAPI](https://quizapi.io/): - -> [https://quizapi.io/](https://quizapi.io/) - -If you want to follow along make sure to get a free API key here: - -> [https://quizapi.io/clientarea/settings/token](https://quizapi.io/clientarea/settings/token) - -The QuizAPI is free for developers. - -## Installing jq - -There are many ways to install `jq` on your system. One of the most straight forward ways to do so is to use the package manager depending on your OS. - -Here is a list of the commands that you would need to use depending on your OS: - -* Install jq on Ubuntu/Debian: - -```bash -sudo apt-get install jq -``` - -* Install jq on Fedora: - -```bash -sudo dnf install jq -``` - -* Install jq on openSUSE: - -```bash -sudo zypper install jq -``` - -- Install jq on Arch: - -```bash -sudo pacman -S jq -``` - -* Installing on Mac with Homebrew: - -```bash -brew install jq -``` - -* Install on Mac with MacPort: - -```bash -port install jq -``` - -If you are using other OS, I would recommend taking a look at the official documentation here for more information: - -> [https://stedolan.github.io/jq/download/](https://stedolan.github.io/jq/download/) - -Once you have jq installed you can check your current version by running this command: - -```bash -jq --version -``` - -## Parsing JSON with jq - -Once you have `jq` installed and your QuizAPI API Key, you can parse the JSON output of the QuizAPI directly in your terminal. - -First, create a variable that stores your API Key: - -```bash -API_KEY=YOUR_API_KEY_HERE -``` - -In order to get some output from one of the endpoints of the QuizAPI you can use the curl command: - -```bash -curl "https://quizapi.io/api/v1/questions?apiKey=${API_KEY}&limit=10" -``` - -For a more specific output, you can use the QuizAPI URL Generator here: - -> [https://quizapi.io/api-config](https://quizapi.io/api-config) - -After running the curl command, the output which you would get would look like this: - -![Raw Json output](https://imgur.com/KghOfzj.png) - -This could be quite hard to read, but thanks to the jq command-line tool, all we need to do is pipe the curl command to jq and we would see a nice formatted JSON output: - -```bash -curl "https://quizapi.io/api/v1/questions?apiKey=${API_KEY}&limit=10" | jq -``` - -> Note the `| jq` at the end. - -In this case the output that you would get would look something like this: - -![bash jq formatting](https://imgur.com/ebdTtVf.png) - -Now, this looks much nicer! The jq command-line tool formatted the output for us and added some nice coloring! - -## Getting the first element with jq - -Let's say that we only wanted to get the first element from the JSON output, in order to do that we have to just specify the index that we want to see with the following syntax: - -```bash -jq .[0] -``` - -Now, if we run the curl command again and pipe the output to jq .[0] like this: - -```bash -curl "https://quizapi.io/api/v1/questions?apiKey=${API_KEY}&limit=10" | jq.[0] -``` - -You will only get the first element and the output will look like this: - -![jq get first element only](https://imgur.com/h9bFMAL.png) - -## Getting a value only for specific key - -Sometimes you might want to get only the value of a specific key only, let's say in our example the QuizAPI returns a list of questions along with the answers, description and etc. but what if you wanted to get the Questions only without the additional information? - -This is going to be quite straight forward with `jq`, all you need to do is add the key after jq command, so it would look something like this: - -```bash -jq .[].question -``` - -We have to add the `.[]` as the QuizAPI returns an array and by specifying `.[]` we tell jq that we want to get the .question value for all of the elements in the array. - -The output that you would get would look like this: - -![jq get a value only for specific key](https://imgur.com/0701wHD.png) - -As you can see we now only get the questions without the rest of the values. - -## Using jq in a BASH script - -Let's go ahead and create a small bash script which should output the following information for us: - -* Get only the first question from the output -* Get all of the answers for that question -* Assign the answers to variables -* Print the question and the answers -* To do that I've put together the following script: - ->{notice} make sure to change the API_KEY part with your actual QuizAPI key: - -```bash -#!/bin/bash - -## -# Make an API call to QuizAPI and store the output in a variable -## -output=$(curl 'https://quizapi.io/api/v1/questions?apiKey=API_KEY&limit=10' 2>/dev/null) - -## -# Get only the first question -## -output=$(echo $output | jq .[0]) - -## -# Get the question -## -question=$(echo $output | jq .question) - -## -# Get the answers -## - -answer_a=$(echo $output | jq .answers.answer_a) -answer_b=$(echo $output | jq .answers.answer_b) -answer_c=$(echo $output | jq .answers.answer_c) -answer_d=$(echo $output | jq .answers.answer_d) - -## -# Output the question -## - -echo " -Question: ${question} - -A) ${answer_a} -B) ${answer_b} -C) ${answer_c} -D) ${answer_d} - -" -``` - -If you run the script you would get the following output: - -![Using jq in a bash script](https://imgur.com/LKEsrbq.png) - -We can even go further by making this interactive so that we could actually choose the answer directly in our terminal. - -There is already a bash script that does this by using the QuizAPI and `jq`: - -You can take a look at that script here: - -* [https://github.com/QuizApi/QuizAPI-BASH/blob/master/quiz.sh](https://github.com/QuizApi/QuizAPI-BASH/blob/master/quiz.sh) - -## Conclusion - -The `jq` command-line tool is an amazing tool that gives you the power to work with JSON directly in your BASH terminal. - -That way you can easily interact with all kinds of different REST APIs with BASH. - -For more information, you could take a look at the official documentation here: - -* [https://stedolan.github.io/jq/manual/](https://stedolan.github.io/jq/manual/) - -And for more information on the **QuizAPI**, you could take a look at the official documentation here: - -* [https://quizapi.io/docs/1.0/overview](https://quizapi.io/docs/1.0/overview) - ->{notice} This content was initially posted on [DevDojo.com](https://devdojo.com/bobbyiliev/how-to-work-with-json-in-bash-using-jq) diff --git a/landing/docs/.Bash-Scripting/023-bash-redirection.md b/landing/docs/.Bash-Scripting/023-bash-redirection.md deleted file mode 100644 index 7339e26..0000000 --- a/landing/docs/.Bash-Scripting/023-bash-redirection.md +++ /dev/null @@ -1,228 +0,0 @@ -# Redirection in Bash - -A Linux superuser must have a good knowledge of pipes and redirection in Bash. It is an essential component of the system and is often helpful in the field of Linux System Administration. - -When you run a command like ``ls``, ``cat``, etc, you get some output on the terminal. If you write a wrong command, pass a wrong flag or a wrong command-line argument, you get error output on the terminal. -In both the cases, you are given some text. It may seem like "just text" to you, but the system treats this text differently. This identifier is known as a File Descriptor (fd). - -In Linux, there are 3 File Descriptors, **STDIN** (0); **STDOUT** (1) and **STDERR** (2). - -* **STDIN** (fd: 0): Manages the input in the terminal. -* **STDOUT** (fd: 1): Manages the output text in the terminal. -* **STDERR** (fd: 2): Manages the error text in the terminal. - -# Difference between Pipes and Redirections - -Both *pipes* and *redidertions* redirect streams `(file descriptor)` of process being executed. The main difference is that *redirections* deal with `files stream`, sending the output stream to a file or sending the content of a given file to the input stream of the process. - -On the other hand a pipe connects two commands by sending the output stream of the first one to the input stream of the second one. without any redidertions specified. - -# Redirection in Bash - -## STDIN (Standard Input) -When you enter some input text for a command that asks for it, you are actually entering the text to the **STDIN** file descriptor. Run the ``cat`` command without any command-line arguments. -It may seem that the process has paused but in fact it's ``cat`` asking for **STDIN**. ``cat`` is a simple program and will print the text passed to **STDIN**. However, you can extend the use case by redirecting the input to the commands that take **STDIN**. - -Example with ``cat``: -``` -cat << EOF -Hello World! -How are you? -EOF -``` -This will simply print the provided text on the terminal screen: -``` -Hello World! -How are you? -``` - -The same can be done with other commands that take input via STDIN. Like, ``wc``: -``` -wc -l << EOF -Hello World! -How are you? -EOF -``` -The ``-l`` flag with ``wc`` counts the number of lines. -This block of bash code will print the number of lines to the terminal screen: -``` -2 -``` - -## STDOUT (Standard Output) -The normal non-error text on your terminal screen is printed via the **STDOUT** file descriptor. The **STDOUT** of a command can be redirected into a file, in such a way that the output of the command is written to a file instead of being printed on the terminal screen. -This is done simply with the help of ``>`` and ``>>`` operators. - -Example: -``` -echo "Hello World!" > file.txt -``` -The above command will not print "Hello World" on the terminal screen, it will instead create a file called ``file.txt`` and will write the "Hello World" string to it. -This can be verified by running the ``cat`` command on the ``file.txt`` file. -``` -cat file.txt -``` - -However, everytime you redirect the **STDOUT** of any command multiple times to the same file, it will remove the existing contents of the file to write the new ones. - -Example: -``` -echo "Hello World!" > file.txt -echo "How are you?" > file.txt -``` - -On running ``cat`` on ``file.txt`` file: -``` -cat file.txt -``` - -You will only get the "How are you?" string printed. -``` -How are you? -``` - -This is because the "Hello World" string has been overwritten. -This behaviour can be avoided using the ``>>`` operator. - -The above example can be written as: -``` -echo "Hello World!" > file.txt -echo "How are you?" >> file.txt -``` - -On running ``cat`` on the ``file.txt`` file, you will get the desired result. -``` -Hello World! -How are you? -``` - -Alternatively, the redirection operator for **STDOUT** can also be written as ``1>``. Like, -``` -echo "Hello World!" 1> file.txt -``` - -## STDERR (Standard Error) - -The error text on the terminal screen is printed via the **STDERR** of the command. For example: -``` -ls --hello -``` -would give an error messages. This error message is the **STDERR** of the command. - -**STDERR** can be redirected using the ``2>`` operator. - -``` -ls --hello 2> error.txt -``` - -This command will redirect the error message to the ``error.txt`` file and write it to it. This can be verified by running the ``cat`` command on the ``error.txt`` file. - -You can also use the ``2>>`` operator for **STDERR** just like you used ``>>`` for **STDOUT**. - -Error messages in Bash Scripts can be undesirable sometimes. You can choose to ignore them by redirecting the error message to the ``/dev/null`` file. -``/dev/null`` is pseudo-device that takes in text and then immediately discards it. - -The above example can be written follows to ignore the error text completely: -``` -ls --hello 2> /dev/null -``` - -Of course, you can redirect both **STDOUT** and **STDERR** for the same command or script. -``` -./install_package.sh > output.txt 2> error.txt -``` - -Both of them can be redirected to the same file as well. -``` -./install_package.sh > file.txt 2> file.txt -``` - -There is also a shorter way to do this. -``` -./install_package.sh > file.txt 2>&1 -``` - -# Piping - -So far we have seen how to redirect the **STDOUT**, **STDIN** and **STDOUT** to and from a file. -To concatenate the output of program *(command)* as the input of another program *(command)* you can use a vertical bar `|`. - -Example: -``` -ls | grep ".txt" -``` -This command will list the files in the current directory and pass output to *`grep`* command which then filter the output to only show the files that contain the string ".txt". - -Syntax: -``` -[time [-p]] [!] command1 [ | or |& command2 ] … -``` - -You can also build arbitrary chains of commands by piping them together to achieve a powerful result. - -This example creates a listing of every user which owns a file in a given directory as well as how many files and directories they own: -``` -ls -l /projects/bash_scripts | tail -n +2 | sed 's/\s\s*/ /g' | cut -d ' ' -f 3 | sort | uniq -c -``` -Output: -``` -8 anne -34 harry -37 tina -18 ryan -``` - -# HereDocument - -The symbol `<<` can be used to create a temporary file [heredoc] and redirect from it at the command line. -``` -COMMAND << EOF - ContentOfDocument - ... - ... -EOF -``` -Note here that `EOF` represents the delimiter (end of file) of the heredoc. In fact, we can use any alphanumeric word in its place to signify the start and the end of the file. For instance, this is a valid heredoc: -``` -cat << randomword1 - This script will print these lines on the terminal. - Note that cat can read from standard input. Using this heredoc, we can - create a temporary file with these lines as it's content and pipe that - into cat. -randomword1 -``` - -Effectively it will appear as if the contents of the heredoc are piped into the command. This can make the script very clean if multiple lines need to be piped into a program. - -Further, we can attach more pipes as shown: -``` -cat << randomword1 | wc - This script will print these lines on the terminal. - Note that cat can read from standard input. Using this heredoc, we can - create a temporary file with these lines as it's content and pipe that - into cat. -randomword1 -``` - -Also, pre-defined variables can be used inside the heredocs. - -# HereString - -Herestrings are quite similar to heredocs but use `<<<`. These are used for single line strings that have to be piped into some program. This looks cleaner that heredocs as we don't have to specify the delimiter. - -``` -wc <<<"this is an easy way of passing strings to the stdin of a program (here wc)" -``` - -Just like heredocs, herestrings can contain variables. - -## Summary -|**Operator** |**Description** | -|:---|:---| -|`>`|`Save output to a file`| -|`>>`|`Append output to a file`| -|`<`|`Read input from a file`| -|`2>`|`Redirect error messages`| -|`\|`|`Send the output from one program as input to another program`| -|`<<`|`Pipe multiple lines into a program cleanly`| -|`<<<`|`Pipe a single line into a program cleanly`| diff --git a/landing/docs/commands/.recycle/008-the-cal-command.md b/landing/docs/.recycle/.recycle2/008-the-cal-command.md similarity index 100% rename from landing/docs/commands/.recycle/008-the-cal-command.md rename to landing/docs/.recycle/.recycle2/008-the-cal-command.md diff --git a/landing/docs/commands/.recycle/009-the-bc-command.md b/landing/docs/.recycle/.recycle2/009-the-bc-command.md similarity index 100% rename from landing/docs/commands/.recycle/009-the-bc-command.md rename to landing/docs/.recycle/.recycle2/009-the-bc-command.md diff --git a/landing/docs/commands/.recycle/011-the-help-command.md b/landing/docs/.recycle/.recycle2/011-the-help-command.md similarity index 100% rename from landing/docs/commands/.recycle/011-the-help-command.md rename to landing/docs/.recycle/.recycle2/011-the-help-command.md diff --git a/landing/docs/commands/.recycle/012-the-factor-command.md b/landing/docs/.recycle/.recycle2/012-the-factor-command.md similarity index 100% rename from landing/docs/commands/.recycle/012-the-factor-command.md rename to landing/docs/.recycle/.recycle2/012-the-factor-command.md diff --git a/landing/docs/commands/.recycle/016-the-whatis-command.md b/landing/docs/.recycle/.recycle2/016-the-whatis-command.md similarity index 100% rename from landing/docs/commands/.recycle/016-the-whatis-command.md rename to landing/docs/.recycle/.recycle2/016-the-whatis-command.md diff --git a/landing/docs/commands/.recycle/017-the-who-command.md b/landing/docs/.recycle/.recycle2/017-the-who-command.md similarity index 100% rename from landing/docs/commands/.recycle/017-the-who-command.md rename to landing/docs/.recycle/.recycle2/017-the-who-command.md diff --git a/landing/docs/commands/.recycle/018-the-free-command.md b/landing/docs/.recycle/.recycle2/018-the-free-command.md similarity index 100% rename from landing/docs/commands/.recycle/018-the-free-command.md rename to landing/docs/.recycle/.recycle2/018-the-free-command.md diff --git a/landing/docs/commands/.recycle/020-the-sl-command.md b/landing/docs/.recycle/.recycle2/020-the-sl-command.md similarity index 100% rename from landing/docs/commands/.recycle/020-the-sl-command.md rename to landing/docs/.recycle/.recycle2/020-the-sl-command.md diff --git a/landing/docs/commands/.recycle/022-the-finger-command.md b/landing/docs/.recycle/.recycle2/022-the-finger-command.md similarity index 100% rename from landing/docs/commands/.recycle/022-the-finger-command.md rename to landing/docs/.recycle/.recycle2/022-the-finger-command.md diff --git a/landing/docs/commands/.recycle/026-the-w-command.md b/landing/docs/.recycle/.recycle2/026-the-w-command.md similarity index 100% rename from landing/docs/commands/.recycle/026-the-w-command.md rename to landing/docs/.recycle/.recycle2/026-the-w-command.md diff --git a/landing/docs/commands/.recycle/029-the-login-command.md b/landing/docs/.recycle/.recycle2/029-the-login-command.md similarity index 100% rename from landing/docs/commands/.recycle/029-the-login-command.md rename to landing/docs/.recycle/.recycle2/029-the-login-command.md diff --git a/landing/docs/commands/.recycle/030-the-lscpu-command.md b/landing/docs/.recycle/.recycle2/030-the-lscpu-command.md similarity index 100% rename from landing/docs/commands/.recycle/030-the-lscpu-command.md rename to landing/docs/.recycle/.recycle2/030-the-lscpu-command.md diff --git a/landing/docs/commands/.recycle/037-the-printenv-command.md b/landing/docs/.recycle/.recycle2/037-the-printenv-command.md similarity index 100% rename from landing/docs/commands/.recycle/037-the-printenv-command.md rename to landing/docs/.recycle/.recycle2/037-the-printenv-command.md diff --git a/landing/docs/commands/.recycle/042-the-ip-command.md b/landing/docs/.recycle/.recycle2/042-the-ip-command.md similarity index 100% rename from landing/docs/commands/.recycle/042-the-ip-command.md rename to landing/docs/.recycle/.recycle2/042-the-ip-command.md diff --git a/landing/docs/commands/.recycle/048-the-last-command.md b/landing/docs/.recycle/.recycle2/048-the-last-command.md similarity index 100% rename from landing/docs/commands/.recycle/048-the-last-command.md rename to landing/docs/.recycle/.recycle2/048-the-last-command.md diff --git a/landing/docs/commands/.recycle/049-the-locate-command.md b/landing/docs/.recycle/.recycle2/049-the-locate-command.md similarity index 100% rename from landing/docs/commands/.recycle/049-the-locate-command.md rename to landing/docs/.recycle/.recycle2/049-the-locate-command.md diff --git a/landing/docs/commands/.recycle/050-the-iostat-command.md b/landing/docs/.recycle/.recycle2/050-the-iostat-command.md similarity index 100% rename from landing/docs/commands/.recycle/050-the-iostat-command.md rename to landing/docs/.recycle/.recycle2/050-the-iostat-command.md diff --git a/landing/docs/commands/.recycle/059-the-sort-command.md b/landing/docs/.recycle/.recycle2/059-the-sort-command.md similarity index 100% rename from landing/docs/commands/.recycle/059-the-sort-command.md rename to landing/docs/.recycle/.recycle2/059-the-sort-command.md diff --git a/landing/docs/commands/.recycle/060-the-paste-command.md b/landing/docs/.recycle/.recycle2/060-the-paste-command.md similarity index 100% rename from landing/docs/commands/.recycle/060-the-paste-command.md rename to landing/docs/.recycle/.recycle2/060-the-paste-command.md diff --git a/landing/docs/commands/.recycle/066-the-iptable-command.md b/landing/docs/.recycle/.recycle2/066-the-iptable-command.md similarity index 100% rename from landing/docs/commands/.recycle/066-the-iptable-command.md rename to landing/docs/.recycle/.recycle2/066-the-iptable-command.md diff --git a/landing/docs/commands/.recycle/068-the-lsof-command.md b/landing/docs/.recycle/.recycle2/068-the-lsof-command.md similarity index 100% rename from landing/docs/commands/.recycle/068-the-lsof-command.md rename to landing/docs/.recycle/.recycle2/068-the-lsof-command.md diff --git a/landing/docs/commands/.recycle/069-the-bzip2-command.md b/landing/docs/.recycle/.recycle2/069-the-bzip2-command.md similarity index 100% rename from landing/docs/commands/.recycle/069-the-bzip2-command.md rename to landing/docs/.recycle/.recycle2/069-the-bzip2-command.md diff --git a/landing/docs/commands/.recycle/070-the-service-command.md b/landing/docs/.recycle/.recycle2/070-the-service-command.md similarity index 100% rename from landing/docs/commands/.recycle/070-the-service-command.md rename to landing/docs/.recycle/.recycle2/070-the-service-command.md diff --git a/landing/docs/commands/.recycle/071-the-vmstat-command.md b/landing/docs/.recycle/.recycle2/071-the-vmstat-command.md similarity index 100% rename from landing/docs/commands/.recycle/071-the-vmstat-command.md rename to landing/docs/.recycle/.recycle2/071-the-vmstat-command.md diff --git a/landing/docs/commands/.recycle/072-the-mpstat-command.md b/landing/docs/.recycle/.recycle2/072-the-mpstat-command.md similarity index 100% rename from landing/docs/commands/.recycle/072-the-mpstat-command.md rename to landing/docs/.recycle/.recycle2/072-the-mpstat-command.md diff --git a/landing/docs/commands/.recycle/073-the-ncdu-command.md b/landing/docs/.recycle/.recycle2/073-the-ncdu-command.md similarity index 100% rename from landing/docs/commands/.recycle/073-the-ncdu-command.md rename to landing/docs/.recycle/.recycle2/073-the-ncdu-command.md diff --git a/landing/docs/commands/.recycle/074-the-uniq-command.md b/landing/docs/.recycle/.recycle2/074-the-uniq-command.md similarity index 100% rename from landing/docs/commands/.recycle/074-the-uniq-command.md rename to landing/docs/.recycle/.recycle2/074-the-uniq-command.md diff --git a/landing/docs/commands/.recycle/075-the-rpm-command.md b/landing/docs/.recycle/.recycle2/075-the-rpm-command.md similarity index 100% rename from landing/docs/commands/.recycle/075-the-rpm-command.md rename to landing/docs/.recycle/.recycle2/075-the-rpm-command.md diff --git a/landing/docs/commands/.recycle/076-the-scp-command.md b/landing/docs/.recycle/.recycle2/076-the-scp-command.md similarity index 100% rename from landing/docs/commands/.recycle/076-the-scp-command.md rename to landing/docs/.recycle/.recycle2/076-the-scp-command.md diff --git a/landing/docs/commands/.recycle/078-the-split-command.md b/landing/docs/.recycle/.recycle2/078-the-split-command.md similarity index 100% rename from landing/docs/commands/.recycle/078-the-split-command.md rename to landing/docs/.recycle/.recycle2/078-the-split-command.md diff --git a/landing/docs/commands/.recycle/079-the-stat-command.md b/landing/docs/.recycle/.recycle2/079-the-stat-command.md similarity index 100% rename from landing/docs/commands/.recycle/079-the-stat-command.md rename to landing/docs/.recycle/.recycle2/079-the-stat-command.md diff --git a/landing/docs/commands/.recycle/083-the-ionice-command.md b/landing/docs/.recycle/.recycle2/083-the-ionice-command.md similarity index 100% rename from landing/docs/commands/.recycle/083-the-ionice-command.md rename to landing/docs/.recycle/.recycle2/083-the-ionice-command.md diff --git a/landing/docs/commands/.recycle/086-the-rsync-command.md b/landing/docs/.recycle/.recycle2/086-the-rsync-command.md similarity index 100% rename from landing/docs/commands/.recycle/086-the-rsync-command.md rename to landing/docs/.recycle/.recycle2/086-the-rsync-command.md diff --git a/landing/docs/commands/.recycle/087-the-dig-command.md b/landing/docs/.recycle/.recycle2/087-the-dig-command.md similarity index 100% rename from landing/docs/commands/.recycle/087-the-dig-command.md rename to landing/docs/.recycle/.recycle2/087-the-dig-command.md diff --git a/landing/docs/commands/.recycle/088-the-whois-command.md b/landing/docs/.recycle/.recycle2/088-the-whois-command.md similarity index 100% rename from landing/docs/commands/.recycle/088-the-whois-command.md rename to landing/docs/.recycle/.recycle2/088-the-whois-command.md diff --git a/landing/docs/commands/.recycle/090-the-awk-command.md b/landing/docs/.recycle/.recycle2/090-the-awk-command.md similarity index 100% rename from landing/docs/commands/.recycle/090-the-awk-command.md rename to landing/docs/.recycle/.recycle2/090-the-awk-command.md diff --git a/landing/docs/commands/.recycle/094-the-pstree-command.md b/landing/docs/.recycle/.recycle2/094-the-pstree-command.md similarity index 100% rename from landing/docs/commands/.recycle/094-the-pstree-command.md rename to landing/docs/.recycle/.recycle2/094-the-pstree-command.md diff --git a/landing/docs/commands/.recycle/095-the-tree-command.md b/landing/docs/.recycle/.recycle2/095-the-tree-command.md similarity index 100% rename from landing/docs/commands/.recycle/095-the-tree-command.md rename to landing/docs/.recycle/.recycle2/095-the-tree-command.md diff --git a/landing/docs/commands/.recycle/097-the-printf-command.md b/landing/docs/.recycle/.recycle2/097-the-printf-command.md similarity index 100% rename from landing/docs/commands/.recycle/097-the-printf-command.md rename to landing/docs/.recycle/.recycle2/097-the-printf-command.md diff --git a/landing/docs/commands/.recycle/098-the-cut-command.md b/landing/docs/.recycle/.recycle2/098-the-cut-command.md similarity index 100% rename from landing/docs/commands/.recycle/098-the-cut-command.md rename to landing/docs/.recycle/.recycle2/098-the-cut-command.md diff --git a/landing/docs/commands/.recycle/099-the-sed-command.md b/landing/docs/.recycle/.recycle2/099-the-sed-command.md similarity index 100% rename from landing/docs/commands/.recycle/099-the-sed-command.md rename to landing/docs/.recycle/.recycle2/099-the-sed-command.md diff --git a/landing/docs/commands/.recycle/103-the-rmdir-command.md b/landing/docs/.recycle/.recycle2/103-the-rmdir-command.md similarity index 100% rename from landing/docs/commands/.recycle/103-the-rmdir-command.md rename to landing/docs/.recycle/.recycle2/103-the-rmdir-command.md diff --git a/landing/docs/commands/.recycle/108-the-screen-command.md b/landing/docs/.recycle/.recycle2/108-the-screen-command.md similarity index 100% rename from landing/docs/commands/.recycle/108-the-screen-command.md rename to landing/docs/.recycle/.recycle2/108-the-screen-command.md diff --git a/landing/docs/commands/.recycle/109-the-nc-command.md b/landing/docs/.recycle/.recycle2/109-the-nc-command.md similarity index 100% rename from landing/docs/commands/.recycle/109-the-nc-command.md rename to landing/docs/.recycle/.recycle2/109-the-nc-command.md diff --git a/landing/docs/commands/.recycle/110-the-make-command.md b/landing/docs/.recycle/.recycle2/110-the-make-command.md similarity index 100% rename from landing/docs/commands/.recycle/110-the-make-command.md rename to landing/docs/.recycle/.recycle2/110-the-make-command.md diff --git a/landing/docs/commands/.recycle/111-the-basename-command.md b/landing/docs/.recycle/.recycle2/111-the-basename-command.md similarity index 100% rename from landing/docs/commands/.recycle/111-the-basename-command.md rename to landing/docs/.recycle/.recycle2/111-the-basename-command.md diff --git a/landing/docs/commands/.recycle/112-the-banner-command.md b/landing/docs/.recycle/.recycle2/112-the-banner-command.md similarity index 100% rename from landing/docs/commands/.recycle/112-the-banner-command.md rename to landing/docs/.recycle/.recycle2/112-the-banner-command.md diff --git a/landing/docs/commands/.recycle/114-the-which-command.md b/landing/docs/.recycle/.recycle2/114-the-which-command.md similarity index 100% rename from landing/docs/commands/.recycle/114-the-which-command.md rename to landing/docs/.recycle/.recycle2/114-the-which-command.md diff --git a/landing/docs/commands/.recycle/117-the-nice-command.md b/landing/docs/.recycle/.recycle2/117-the-nice-command.md similarity index 100% rename from landing/docs/commands/.recycle/117-the-nice-command.md rename to landing/docs/.recycle/.recycle2/117-the-nice-command.md diff --git a/landing/docs/commands/.recycle/118-the-wc-command.md b/landing/docs/.recycle/.recycle2/118-the-wc-command.md similarity index 100% rename from landing/docs/commands/.recycle/118-the-wc-command.md rename to landing/docs/.recycle/.recycle2/118-the-wc-command.md diff --git a/landing/docs/commands/.recycle/119-the-tr-command.md b/landing/docs/.recycle/.recycle2/119-the-tr-command.md similarity index 100% rename from landing/docs/commands/.recycle/119-the-tr-command.md rename to landing/docs/.recycle/.recycle2/119-the-tr-command.md diff --git a/landing/docs/commands/.recycle/121-the-wait-command.md b/landing/docs/.recycle/.recycle2/121-the-wait-command.md similarity index 100% rename from landing/docs/commands/.recycle/121-the-wait-command.md rename to landing/docs/.recycle/.recycle2/121-the-wait-command.md diff --git a/landing/docs/commands/.recycle/122-the-zcat-command.md b/landing/docs/.recycle/.recycle2/122-the-zcat-command.md similarity index 100% rename from landing/docs/commands/.recycle/122-the-zcat-command.md rename to landing/docs/.recycle/.recycle2/122-the-zcat-command.md diff --git a/landing/docs/commands/.recycle/123-the-fold-command.md b/landing/docs/.recycle/.recycle2/123-the-fold-command.md similarity index 100% rename from landing/docs/commands/.recycle/123-the-fold-command.md rename to landing/docs/.recycle/.recycle2/123-the-fold-command.md diff --git a/landing/docs/commands/.recycle/124-the-quota-command.md b/landing/docs/.recycle/.recycle2/124-the-quota-command.md similarity index 100% rename from landing/docs/commands/.recycle/124-the-quota-command.md rename to landing/docs/.recycle/.recycle2/124-the-quota-command.md diff --git a/landing/docs/commands/.recycle/125-the-aplay-command.md b/landing/docs/.recycle/.recycle2/125-the-aplay-command.md similarity index 100% rename from landing/docs/commands/.recycle/125-the-aplay-command.md rename to landing/docs/.recycle/.recycle2/125-the-aplay-command.md diff --git a/landing/docs/commands/.recycle/126-the-spd-say-command.md b/landing/docs/.recycle/.recycle2/126-the-spd-say-command.md similarity index 100% rename from landing/docs/commands/.recycle/126-the-spd-say-command.md rename to landing/docs/.recycle/.recycle2/126-the-spd-say-command.md diff --git a/landing/docs/commands/.recycle/127-the-xeyes-command.md b/landing/docs/.recycle/.recycle2/127-the-xeyes-command.md similarity index 100% rename from landing/docs/commands/.recycle/127-the-xeyes-command.md rename to landing/docs/.recycle/.recycle2/127-the-xeyes-command.md diff --git a/landing/docs/commands/.recycle/129-the-nl-command.md b/landing/docs/.recycle/.recycle2/129-the-nl-command.md similarity index 100% rename from landing/docs/commands/.recycle/129-the-nl-command.md rename to landing/docs/.recycle/.recycle2/129-the-nl-command.md diff --git a/landing/docs/commands/.recycle/130-the-pidof-command.md b/landing/docs/.recycle/.recycle2/130-the-pidof-command.md similarity index 100% rename from landing/docs/commands/.recycle/130-the-pidof-command.md rename to landing/docs/.recycle/.recycle2/130-the-pidof-command.md diff --git a/landing/docs/commands/.recycle/131-the-shuf-command.md b/landing/docs/.recycle/.recycle2/131-the-shuf-command.md similarity index 100% rename from landing/docs/commands/.recycle/131-the-shuf-command.md rename to landing/docs/.recycle/.recycle2/131-the-shuf-command.md diff --git a/landing/docs/commands/.recycle/134-the-cmp-command.md b/landing/docs/.recycle/.recycle2/134-the-cmp-command.md similarity index 100% rename from landing/docs/commands/.recycle/134-the-cmp-command.md rename to landing/docs/.recycle/.recycle2/134-the-cmp-command.md diff --git a/landing/docs/commands/.recycle/135-the-expr-command.md b/landing/docs/.recycle/.recycle2/135-the-expr-command.md similarity index 100% rename from landing/docs/commands/.recycle/135-the-expr-command.md rename to landing/docs/.recycle/.recycle2/135-the-expr-command.md diff --git a/landing/docs/commands/.recycle/trash/000-the-introduction-command.md b/landing/docs/.recycle/.recycle2/trash/000-the-introduction-command.md similarity index 100% rename from landing/docs/commands/.recycle/trash/000-the-introduction-command.md rename to landing/docs/.recycle/.recycle2/trash/000-the-introduction-command.md diff --git a/landing/docs/commands/.recycle/trash/999-wrap-up.md b/landing/docs/.recycle/.recycle2/trash/999-wrap-up.md similarity index 100% rename from landing/docs/commands/.recycle/trash/999-wrap-up.md rename to landing/docs/.recycle/.recycle2/trash/999-wrap-up.md diff --git a/landing/docs/assets/cover.jpg b/landing/docs/.recycle/assets/cover.jpg similarity index 100% rename from landing/docs/assets/cover.jpg rename to landing/docs/.recycle/assets/cover.jpg diff --git a/landing/docs/assets/cover.jpg-bak b/landing/docs/.recycle/assets/cover.jpg-bak similarity index 100% rename from landing/docs/assets/cover.jpg-bak rename to landing/docs/.recycle/assets/cover.jpg-bak diff --git a/landing/docs/assets/cover.png b/landing/docs/.recycle/assets/cover.png similarity index 100% rename from landing/docs/assets/cover.png rename to landing/docs/.recycle/assets/cover.png diff --git a/landing/docs/assets/styling (copy 1).css b/landing/docs/.recycle/assets/styling (copy 1).css similarity index 100% rename from landing/docs/assets/styling (copy 1).css rename to landing/docs/.recycle/assets/styling (copy 1).css diff --git a/landing/docs/assets/styling (copy 2).css b/landing/docs/.recycle/assets/styling (copy 2).css similarity index 100% rename from landing/docs/assets/styling (copy 2).css rename to landing/docs/.recycle/assets/styling (copy 2).css diff --git a/landing/docs/assets/styling.css b/landing/docs/.recycle/assets/styling.css similarity index 100% rename from landing/docs/assets/styling.css rename to landing/docs/.recycle/assets/styling.css diff --git a/landing/docs/.Bash-Scripting/000-about-the-author.md b/landing/docs/Bash-Scripts/.recycle/000-about-the-author.md similarity index 100% rename from landing/docs/.Bash-Scripting/000-about-the-author.md rename to landing/docs/Bash-Scripts/.recycle/000-about-the-author.md diff --git a/landing/docs/.Bash-Scripting/001-introduction-to-bash.md b/landing/docs/Bash-Scripts/.recycle/001-introduction-to-bash.md similarity index 100% rename from landing/docs/.Bash-Scripting/001-introduction-to-bash.md rename to landing/docs/Bash-Scripts/.recycle/001-introduction-to-bash.md diff --git a/landing/docs/.Bash-Scripting/019-working-with-cloudflare-api-with-bash.md b/landing/docs/Bash-Scripts/.recycle/019-working-with-cloudflare-api-with-bash.md similarity index 100% rename from landing/docs/.Bash-Scripting/019-working-with-cloudflare-api-with-bash.md rename to landing/docs/Bash-Scripts/.recycle/019-working-with-cloudflare-api-with-bash.md diff --git a/landing/docs/.Bash-Scripting/020-nginx-and-apache-log-parser.md b/landing/docs/Bash-Scripts/.recycle/020-nginx-and-apache-log-parser.md similarity index 100% rename from landing/docs/.Bash-Scripting/020-nginx-and-apache-log-parser.md rename to landing/docs/Bash-Scripts/.recycle/020-nginx-and-apache-log-parser.md diff --git a/landing/docs/.Bash-Scripting/021-how-to-send-emails-with-bash.md b/landing/docs/Bash-Scripts/.recycle/021-how-to-send-emails-with-bash.md similarity index 100% rename from landing/docs/.Bash-Scripting/021-how-to-send-emails-with-bash.md rename to landing/docs/Bash-Scripts/.recycle/021-how-to-send-emails-with-bash.md diff --git a/landing/docs/.Bash-Scripting/022-bash-password-generator.md b/landing/docs/Bash-Scripts/.recycle/022-bash-password-generator.md similarity index 100% rename from landing/docs/.Bash-Scripting/022-bash-password-generator.md rename to landing/docs/Bash-Scripts/.recycle/022-bash-password-generator.md diff --git a/landing/docs/.Bash-Scripting/024-automating-wordpress-lamp-with-bash.md b/landing/docs/Bash-Scripts/.recycle/024-automating-wordpress-lamp-with-bash.md similarity index 100% rename from landing/docs/.Bash-Scripting/024-automating-wordpress-lamp-with-bash.md rename to landing/docs/Bash-Scripts/.recycle/024-automating-wordpress-lamp-with-bash.md diff --git a/landing/docs/.Bash-Scripting/100-bash-wrap-up.md b/landing/docs/Bash-Scripts/.recycle/100-bash-wrap-up.md similarity index 100% rename from landing/docs/.Bash-Scripting/100-bash-wrap-up.md rename to landing/docs/Bash-Scripts/.recycle/100-bash-wrap-up.md diff --git a/landing/docs/Bash-Scripts/002-bash-structure.md b/landing/docs/Bash-Scripts/002-bash-structure.md new file mode 100644 index 0000000..8117ed6 --- /dev/null +++ b/landing/docs/Bash-Scripts/002-bash-structure.md @@ -0,0 +1,23 @@ +# Bash Basics + +To begin, create a new file with a `.sh` extension. We'll use `shinobi.sh` as our example. + +You can create it instantly with `touch`: + +```bash +touch shinobi.sh +``` + +Or, open it directly in your text editor: + +```bash +nano shinobi.sh +``` + +For your script to execute, the very first line must specify the interpreter. This is called the Shebang. While `#!/bin/bash` instructs the operating system to use `/bin/bash`, its location can vary. For wider compatibility, use this: + +```bash +#!/usr/bin/env bash +``` + +This tells the system to find `bash` within your `PATH` environment variable, ensuring your script runs consistently across different systems. diff --git a/landing/docs/Bash-Scripts/003-bash-hello-world.md b/landing/docs/Bash-Scripts/003-bash-hello-world.md new file mode 100644 index 0000000..6ebd25d --- /dev/null +++ b/landing/docs/Bash-Scripts/003-bash-hello-world.md @@ -0,0 +1,45 @@ +# Hello World Bash + +Let's build your first script. Create `shinobi.sh` and add the essential shebang, followed by your `Hello World` message: + +```bash +touch shinobi.sh +``` + +Now, open `shinobi.sh` and add this content: + +```bash +#!/usr/bin/env bash + +echo "Hello World!" +``` + +Save and close the file. + +Next, make your script executable: + +```bash +chmod +x shinobi.sh +``` + +Execute your script directly: + +```bash +./shinobi.sh +``` + +You'll see "Hello World!" printed. + +Alternatively, you can run the script by explicitly calling the `bash` interpreter: + +```bash +bash shinobi.sh +``` + +For quick tests, `echo` works directly in your terminal: + +```bash +echo "Hello Shinobi!" +``` + +Scripts become powerful when combining multiple commands for automated tasks. This is your first step. diff --git a/landing/docs/Bash-Scripts/004-bash-variables.md b/landing/docs/Bash-Scripts/004-bash-variables.md new file mode 100644 index 0000000..7645537 --- /dev/null +++ b/landing/docs/Bash-Scripts/004-bash-variables.md @@ -0,0 +1,121 @@ +# Variables + +Like any language, Bash uses variables. No strict data types here; a variable holds numbers or characters. + +Assign a value: + +```bash +name="Shinobi" +``` + +> **Note:** No spaces around the `=` sign. This is critical. + +Access the value using `$` before the variable name: + +```bash +echo $name +``` + +While optional, wrapping the name in curly braces is good practice for clarity: + +```bash +echo ${name} +``` + +Both would output: `Shinobi`. + +Now, let's build a script. + +First, create the file: + +```bash +touch shinobi.sh +``` + +Then, open `shinobi.sh` and add this content to include a variable: + +```bash +#!/usr/bin/env bash + +name="Shinobi" + +echo "Hi there $name" +``` + +Save and exit. + +Make it executable: + +```bash +chmod +x shinobi.sh +``` + +Run your script: + +```bash +./shinobi.sh +``` + +You'll see: + +```bash +Hi there Shinobi +``` + +This script: +* `#!/usr/bin/env bash`: Sets the interpreter. +* `name="Shinobi"`: Defines `name` with its value. +* `echo "Hi there $name"`: Outputs the welcome message using the variable. + +You can use multiple variables: + +```bash +#!/usr/bin/env bash + +name="Shinobi" +greeting="Hello" + +echo "$greeting $name" +``` + +Save and run `shinobi.sh` again: + +```bash +./shinobi.sh +``` + +Output: + +```bash +Hello Shinobi +``` + +No semicolons needed at line ends. + +### Command Line Parameters + +Bash scripts also read variables passed directly from the command line. These are called parameters. + +Run your script with inputs like this: + +```bash +./shinobi.sh Troy buddy! +``` + +Now, modify your `shinobi.sh` file to access these parameters: + +```bash +#!/usr/bin/env bash + +echo "Hello there" $1 # $1: first parameter +echo "Hello there" $2 # $2: second parameter +echo "Hello there" $@ # $@: all parameters +``` + +The output for `./shinobi.sh Troy buddy!` will be: + +```bash +Hello there Troy +Hello there buddy! +Hello there Troy buddy! +``` diff --git a/landing/docs/Bash-Scripts/005-bash-user-input.md b/landing/docs/Bash-Scripts/005-bash-user-input.md new file mode 100644 index 0000000..6b72b0a --- /dev/null +++ b/landing/docs/Bash-Scripts/005-bash-user-input.md @@ -0,0 +1,64 @@ +# User Input + +You've outputted variable values. Now, let's get input from the user. + +First, create your script file: + +```bash +touch shinobi.sh +``` + +Next, open `shinobi.sh` and add this: + +```bash +#!/usr/bin/env bash + +echo "What is your name?" +read name + +echo "Hi there $name" +echo "Welcome to Shinobi!" +``` + +Save and exit the file. + +Make it executable: + +```bash +chmod +x shinobi.sh +``` + +Run your script: + +```bash +./shinobi.sh +``` + +The script will prompt you: + +``` +What is your name? +Troy +``` + +Enter a name (e.g., `Troy`) and hit Enter. You'll see: + +``` +Hi there Troy +Welcome to Shinobi! +``` + +This script prompts the user, stores their input in the `name` variable, then uses it to print a personalized message. + +### Streamlined Input + +To reduce lines, use `read` with the `-p` flag. This prints a prompt before waiting for input: + +```bash +#!/usr/bin/env bash + +read -p "What is your name? " name + +echo "Hi there $name" +echo "Welcome to Shinobi!" +``` diff --git a/landing/docs/Bash-Scripts/006-bash-comments.md b/landing/docs/Bash-Scripts/006-bash-comments.md new file mode 100644 index 0000000..484a05d --- /dev/null +++ b/landing/docs/Bash-Scripts/006-bash-comments.md @@ -0,0 +1,40 @@ +# Comments + +Add comments to your Bash scripts for notes and clarity. Lines starting with `#` are ignored by the interpreter. + +```bash +# This is a comment. It will not run. +``` + +Let's create a new script, `shinobi.sh`, and include comments: + +```bash +touch shinobi.sh +``` + +Now, open `shinobi.sh` and add this: + +```bash +#!/usr/bin/env bash + +# Ask the user for their name + +read -p "What is your name? " name + +# Greet the user + +echo "Hi there $name" + +echo "Welcome to Dev Team Six!" +``` + +Save and exit. + +Make your script executable and run it: + +```bash +chmod +x shinobi.sh +./shinobi.sh +``` + +Comments are essential. They make your code readable, for yourself and for anyone else who works on it. Clarity drives efficiency. diff --git a/landing/docs/Bash-Scripts/007-bash-arguments.md b/landing/docs/Bash-Scripts/007-bash-arguments.md new file mode 100644 index 0000000..499f4db --- /dev/null +++ b/landing/docs/Bash-Scripts/007-bash-arguments.md @@ -0,0 +1,101 @@ +# Runtime Arguments + +Pass data into your script at execution. Arguments follow the script name: + +```bash +./your_script.sh first_argument +``` + +Inside the script, `$1` references the first argument, `$2` the second, and so on. + +Let's see this in `arguments.sh`: + +```bash +touch arguments.sh +``` + +Open `arguments.sh` and add: + +```bash +#!/usr/bin/env bash + +echo "Arg 1: $1" +echo "Arg 2: $2" +echo "Arg 3: $3" +``` + +Save and exit. Make it executable: + +```bash +chmod +x arguments.sh +``` + +Run with three arguments: + +```bash +./arguments.sh dog cat bird +``` + +Output: + +```bash +Arg 1: dog +Arg 2: cat +Arg 3: bird +``` + +To access *all* arguments, use `$@`. Update `arguments.sh`: + +```bash +#!/usr/bin/env bash + +echo "All arguments: $@" +``` + +Save. Run again with arguments: + +```bash +./arguments.sh dog cat bird +``` + +Output: + +```bash +All arguments: dog cat bird +``` + +### Script Name (`$0`) + +`$0` references the script itself. This is useful for logging or unique operations. + +You can even use `$0` for self-deletion. **Handle with extreme caution!** + +Create `self_destruct.sh`: + +```bash +touch self_destruct.sh +``` + +Open `self_destruct.sh` and add: + +```bash +#!/usr/bin/env bash + +echo "This script: $0 is self-destructing." + +rm -f $0 +``` + +Save and exit. Make it executable: + +```bash +chmod +x self_destruct.sh +``` + +Run it: + +```bash +./self_destruct.sh +``` + +The script will print its name, then delete itself. **This is irreversible. No second chances.** Always back up before testing self-deletion. diff --git a/landing/docs/Bash-Scripts/008-bash-arrays.md b/landing/docs/Bash-Scripts/008-bash-arrays.md new file mode 100644 index 0000000..3a71ae3 --- /dev/null +++ b/landing/docs/Bash-Scripts/008-bash-arrays.md @@ -0,0 +1,97 @@ +# Arrays + +Arrays are essential. They let a single variable hold multiple values. Initialize them by listing values, separated by spaces, inside parentheses: + +```bash +# Example initialization: +my_array=("value 1" "value 2" "value 3" "value 4") +``` + +Access array elements using their numeric index. **Always use curly brackets.** + +Let's create `arrays.sh` to demonstrate: + +```bash +touch arrays.sh +``` + +Now, open `arrays.sh` and add: + +```bash +#!/usr/bin/env bash + +my_array=("value 1" "value 2" "value 3" "value 4") + +echo "Second element (index 1): ${my_array[1]}" +echo "Last element (index -1): ${my_array[-1]}" +echo "All elements: ${my_array[@]}" +echo "Total elements: ${#my_array[@]}" +``` + +Save and exit. Make it executable: + +```bash +chmod +x arrays.sh +``` + +Run your script: + +```bash +./arrays.sh +``` + +Output: + +``` +value 2 +value 4 +value 1 value 2 value 3 value 4 +4 +``` + +### Slicing + +Extract specific portions of an array or string using slicing notation. + +Create `slicing.sh`: + +```bash +touch slicing.sh +``` + +Open `slicing.sh` and add these examples: + +```bash +#!/usr/bin/env bash + +letters=("A" "B" "C" "D" "E") + +echo "Original array: ${letters[@]}" + +echo "Example 1 (start 0, length 2): ${letters:0:2}" # Prints AB +echo "Example 2 (start 0, all elements): ${letters::5}" # Prints ABCDE +echo "Example 3 (start 3, to end): ${letters:3}" # Prints DE +``` + +Save and exit. Make it executable: + +```bash +chmod +x slicing.sh +``` + +Run `slicing.sh`: + +```bash +./slicing.sh +``` + +Output: + +``` +A B C D E +AB +ABCDE +DE +``` + +Mastering arrays and slicing gives you precise control over your data structures. diff --git a/landing/docs/Bash-Scripts/009-bash-conditional-expressions.md b/landing/docs/Bash-Scripts/009-bash-conditional-expressions.md new file mode 100644 index 0000000..2a6528e --- /dev/null +++ b/landing/docs/Bash-Scripts/009-bash-conditional-expressions.md @@ -0,0 +1,110 @@ +# Conditional Expressions + +Conditionals are how your scripts make decisions: run different code based on a true/false outcome. + +In Bash, `[[` is your go-to for testing files, strings, and numbers. + +Let's start with a basic example: + +```bash +touch conditional_test.sh +``` + +Open `conditional_test.sh` and add: + +```bash +#!/usr/bin/env bash + +my_var="data" + +if [[ -n "$my_var" ]]; then # If variable is not empty + echo "Variable contains data." +fi +``` + +Save, make executable, and run: + +```bash +chmod +x conditional_test.sh +./conditional_test.sh +``` + +Output: `Variable contains data.` + +Now, for your full reference: + +## File Tests + +These check file attributes. Use `"${file}"` to handle spaces in names. + +* `[[ -e "${file}" ]]` - True if `file` exists. +* `[[ -f "${file}" ]]` - True if `file` exists and is a regular file. +* `[[ -d "${file}" ]]` - True if `file` exists and is a directory. +* `[[ -s "${file}" ]]` - True if `file` exists and is not empty (size > 0). +* `[[ -r "${file}" ]]` - True if `file` exists and is readable. +* `[[ -w "${file}" ]]` - True if `file` exists and is writable. +* `[[ -x "${file}" ]]` - True if `file` exists and is executable. +* `[[ -L "${file}" ]]` - True if `file` is a symbolic link (`-h` is also used). +* `[[ -b "${file}" ]]` - True if `file` exists and is a block device. +* `[[ -c "${file}" ]]` - True if `file` exists and is a character device. + +## String Tests + +Compare string properties and values. + +* `[[ -v "${varname}" ]]` - True if `varname` is set (has a value). +* `[[ -z "${string}" ]]` - True if `string` has zero length (empty). +* `[[ -n "${string}" ]]` - True if `string` has non-zero length (not empty). +* `[[ "${string1}" == "${string2}" ]]` - True if strings are equal. (`==` allows pattern matching inside `[[`.) +* `[[ "${string1}" != "${string2}" ]]` - True if strings are not equal. +* `[[ "${string1}" < "${string2}" ]]` - True if `string1` sorts before `string2` lexicographically. +* `[[ "${string1}" > "${string2}" ]]` - True if `string1` sorts after `string2` lexicographically. + +## Numeric Comparisons + +Compare integer values. + +* `[[ ${arg1} -eq ${arg2} ]]` - True if `arg1` equals `arg2`. +* `[[ ${arg1} -ne ${arg2} ]]` - True if `arg1` not equals `arg2`. +* `[[ ${arg1} -lt ${arg2} ]]` - True if `arg1` less than `arg2`. +* `[[ ${arg1} -le ${arg2} ]]` - True if `arg1` less than or equal to `arg2`. +* `[[ ${arg1} -gt ${arg2} ]]` - True if `arg1` greater than `arg2`. +* `[[ ${arg1} -ge ${arg2} ]]` - True if `arg1` greater than or equal to `arg2`. + +## Logical Operators + +Combine multiple conditions. + +* **AND (`&&`)**: Both conditions must be true. + ```bash + # Example: file exists AND is not empty + if [[ -f "my_file.txt" && -s "my_file.txt" ]]; then + echo "File is present and has content." + fi + ``` +* **OR (`||`)**: At least one condition must be true. + ```bash + # Example: either file or directory exists + if [[ -f "another_file.txt" || -d "another_dir" ]]; then + echo "Found a file or a directory." + fi + ``` + +## Exit Status Checks + +`$?:` The exit status of the *last* executed command. `0` means success. Any non-zero value indicates an error. + +* **Success:** + ```bash + command_to_run + if [[ $? -eq 0 ]]; then + echo "Command succeeded." + fi + ``` +* **Failure:** + ```bash + command_to_run + if [[ $? -ne 0 ]]; then + echo "Command failed." + fi + ``` diff --git a/landing/docs/Bash-Scripts/010-bash-conditionals.md b/landing/docs/Bash-Scripts/010-bash-conditionals.md new file mode 100644 index 0000000..6e7a817 --- /dev/null +++ b/landing/docs/Bash-Scripts/010-bash-conditionals.md @@ -0,0 +1,237 @@ +# Conditionals + +You've mastered conditional expressions. Now, let's put them to work using `if`, `if-else`, `elif`, and `case` statements to control your script's flow. + +--- + +### If Statements + +The `if` statement executes commands only if a condition is true. + +```bash +if [[ some_test ]] +then + +fi +``` + +Example: Prompt for a name, then check if it's empty. + +```bash +touch if_example.sh +``` + +Open `if_example.sh` and add: + +```bash +#!/usr/bin/env bash + +read -p "What is your name? " name + +if [[ -z "${name}" ]]; then # Check if name is empty + echo "Please enter your name!" +fi +``` + +Save and exit. Make it executable and run: + +```bash +chmod +x if_example.sh +./if_example.sh +``` + +### If-Else Statements + +Use `else` to define actions when the `if` condition is false. + +Create `if_else_example.sh`: + +```bash +touch if_else_example.sh +``` + +Open `if_else_example.sh` and add: + +```bash +#!/usr/bin/env bash + +read -p "What is your name? " name + +if [[ -z "${name}" ]]; then + echo "Please enter your name!" +else + echo "Hi there ${name}!" +fi +``` + +Save, make executable, and run. + +### Admin/Root Checks + +Check user roles. For admin verification: + +Create `admin_check.sh`: + +```bash +touch admin_check.sh +``` + +Open `admin_check.sh` and add: + +```bash +#!/usr/bin/env bash + +admin="Dev Team Six" + +read -p "Enter your username: " username + +if [[ "${username}" == "${admin}" ]]; then + echo "You are the admin user!" +else + echo "You are NOT the admin user!" +fi +``` + +Save, make executable, and run. + +To prevent a script from running as `root` (`EUID` is 0 for root): + +Create `root_check.sh`: + +```bash +touch root_check.sh +``` + +Open `root_check.sh` and add: + +```bash +#!/usr/bin/env bash + +if [[ $EUID -eq 0 ]]; then # Check if current user ID is 0 (root) + echo "This script should not be run as root. Exiting." + exit 1 # Exit with error code +fi +echo "Script running as non-root user." +``` + +Save, make executable, and run (test as root and non-root). + +Combine conditions for stricter control. This example ensures the user is neither `admin` nor `root`. + +Create `combined_check.sh`: + +```bash +touch combined_check.sh +``` + +Open `combined_check.sh` and add: + +```bash +#!/usr/bin/env bash + +admin_user="Dev Team Six" + +read -p "Enter your username: " username + +if [[ "${username}" != "${admin_user}" || $EUID -ne 0 ]]; then # OR operator + echo "You are not the admin or root user. Proceeding safely." +else + echo "You are an admin or root user. Exercise caution." +fi +``` + +Save, make executable, and run. + +### Elif Statements + +For multiple, mutually exclusive conditions, use `elif`. + +Create `elif_example.sh`: + +```bash +touch elif_example.sh +``` + +Open `elif_example.sh` and add: + +```bash +#!/usr/bin/env bash + +read -p "Enter a number: " num + +if [[ $num -gt 0 ]]; then + echo "The number is positive." +elif [[ $num -lt 0 ]]; then + echo "The number is negative." +else + echo "The number is 0." +fi +``` + +Save, make executable, and run. + +### Case Statements + +Simplify complex conditionals with `case` when you have multiple choices. + +The `case` syntax: + +```bash +case $variable_to_test in + pattern_1) + commands_for_pattern_1 + ;; + pattern_2|pattern_3) # Multiple patterns with | + commands_for_pattern_2_or_3 + ;; + *) # Default case (catch-all) + default_commands + ;; +esac +``` + +Key points: `case` starts the statement, `in` follows the variable. Patterns end with `)`. Commands are terminated by `;;`. `*` is the default. `esac` closes the statement. + +Example: Check car brand and factory location. + +Create `car_brand_case.sh`: + +```bash +touch car_brand_case.sh +``` + +Open `car_brand_case.sh` and add: + +```bash +#!/usr/bin/env bash + +read -p "Enter the name of your car brand: " car + +case $car in + + Tesla) + echo "${car}'s factory is in the USA." + ;; + + BMW | Mercedes | Audi | Porsche) + echo "${car}'s factory is in Germany." + ;; + + Toyota | Mazda | Mitsubishi | Subaru) + echo "${car}'s factory is in Japan." + ;; + + *) + echo "${car} is an unknown car brand." + ;; + +esac +``` + +Save, make executable, and run. + +--- + +### Conclusion + +Practice these conditional structures. Modify the examples. Mastering flow control is critical for effective scripting. diff --git a/landing/docs/Bash-Scripts/011-bash-loops.md b/landing/docs/Bash-Scripts/011-bash-loops.md new file mode 100644 index 0000000..e0a2af6 --- /dev/null +++ b/landing/docs/Bash-Scripts/011-bash-loops.md @@ -0,0 +1,232 @@ +# Loops + +Loops are fundamental for automation. Bash provides `for`, `while`, and `until` loops to repeat commands efficiently. + +--- + +### For Loops + +The `for` loop iterates through a list of items. + +```bash +for var in ${list} +do + your_commands +done +``` + +Example: Loop through a list of users. + +```bash +touch for_users.sh +``` + +Open `for_users.sh` and add: + +```bash +#!/usr/bin/env bash + +users="Dev Team Six softwareshinobi troy" + +for user in ${users} +do + echo "${user}" +done +``` + +Save and exit. Make it executable and run: + +```bash +chmod +x for_users.sh +./for_users.sh +``` + +Output: +``` +Dev Team Six +softwareshinobi +troy +``` + +Loop through a range of numbers: + +```bash +touch for_numbers.sh +``` + +Open `for_numbers.sh` and add: + +```bash +#!/usr/bin/env bash + +for num in {1..10} +do + echo ${num} +done +``` + +Save, make executable, and run. + +### While Loops + +A `while` loop continues as long as its condition remains true. + +```bash +while [[ your_condition ]] +do + your_commands +done +``` + +Example: Counter from 1 to 10. + +```bash +touch while_counter.sh +``` + +Open `while_counter.sh` and add: + +```bash +#!/usr/bin/env bash + +counter=1 +while [[ $counter -le 10 ]] +do + echo $counter + ((counter++)) # Increment counter +done +``` + +Save, make executable, run. + +Example: Require user input. Loop until a non-empty name is provided. + +```bash +touch while_input.sh +``` + +Open `while_input.sh` and add: + +```bash +#!/usr/bin/env bash + +read -p "What is your name? " name + +while [[ -z "${name}" ]] +do + echo "Name cannot be blank. Please enter a valid name!" + read -p "Enter your name again: " name +done + +echo "Hi there ${name}!" +``` + +Save, make executable, run (test with empty and valid input). + +### Until Loops + +An `until` loop runs *until* its condition becomes true. + +```bash +until [[ your_condition ]] +do + your_commands +done +``` + +Example: Counter from 1 to 10. + +```bash +touch until_loop.sh +``` + +Open `until_loop.sh` and add: + +```bash +#!/usr/bin/env bash + +count=1 +until [[ $count -gt 10 ]] +do + echo $count + ((count++)) +done +``` + +Save, make executable, run. + +### Continue and Break + +Control loop flow with `continue` (skip current iteration) and `break` (exit loop entirely). + +#### `continue` + +```bash +touch continue_example.sh +``` + +Open `continue_example.sh` and add: + +```bash +#!/usr/bin/env bash + +for i in 1 2 3 4 5 +do + if [[ $i -eq 2 ]]; then + echo "Skipping number 2" + continue # Skip to next iteration + fi + echo "i is equal to $i" +done +``` + +Save, make executable, run. + +#### `break` + +```bash +touch break_example.sh +``` + +Open `break_example.sh` and add: + +```bash +#!/usr/bin/env bash + +num=1 +while [[ $num -lt 10 ]]; do + if [[ $num -eq 5 ]]; then + break # Exit loop + fi + ((num++)) +done +echo "Loop completed. Num stopped at: $num" +``` + +Save, make executable, run. + +For nested loops, `break N` exits `N` levels of loops. `break 2` exits the current and the parent loop. + +```bash +touch nested_break_example.sh +``` + +Open `nested_break_example.sh` and add: + +```bash +#!/usr/bin/env bash + +for (( a = 1; a < 3; a++ )); do # Outer loop + echo "Outer loop: $a" + for (( b = 1; b < 5; b++ )); do # Inner loop + if [[ $b -gt 2 ]]; then + echo " Breaking inner and outer loop at b=$b" + break 2 # Exits both loops + fi + echo " Inner loop: $b" + done +done +echo "All loops finished." +``` + +Save, make executable, run. diff --git a/landing/docs/Bash-Scripts/012-bash-functions.md b/landing/docs/Bash-Scripts/012-bash-functions.md new file mode 100644 index 0000000..cdaad48 --- /dev/null +++ b/landing/docs/Bash-Scripts/012-bash-functions.md @@ -0,0 +1,87 @@ +# Functions + +Functions organize your code for reuse. Here's the structure: + +```bash +function_name() { + your_commands +} +``` + +You can also use the `function` keyword for clarity, though it's optional: + +```bash +function function_name() { + your_commands +} +``` + +Example: A simple 'Hello World!' function. + +```bash +touch hello_function.sh +``` + +Open `hello_function.sh` and add: + +```bash +#!/usr/bin/env bash + +function hello() { + echo "Hello World Function!" +} + +hello # Call the function (no parentheses) +``` + +Save and exit. Make it executable and run: + +```bash +chmod +x hello_function.sh +./hello_function.sh +``` + +Functions accept arguments just like scripts. + +```bash +touch function_args.sh +``` + +Open `function_args.sh` and add: + +```bash +#!/usr/bin/env bash + +function greet_team() { + echo "Hello $1!" +} + +greet_team "Dev Team Six" # Pass argument when calling +``` + +Save and exit. Make it executable and run: + +```bash +chmod +x function_args.sh +./function_args.sh +``` + +Document your functions clearly. Include a description, arguments, and expected output/return values. + +```bash +####################################### +# Description: Greets a single argument. +# Globals: None +# Arguments: +# $1 - Name/value to greet. +# Outputs: +# Prints a greeting to stdout. +# Returns: +# 0 on success. +####################################### +function greet_example() { + echo "Greeting: $1" +} +``` + +Functions are key to building organized and reusable Bash scripts. Master them for efficient automation. diff --git a/landing/docs/Bash-Scripts/013-debugging.md b/landing/docs/Bash-Scripts/013-debugging.md new file mode 100644 index 0000000..39ff778 --- /dev/null +++ b/landing/docs/Bash-Scripts/013-debugging.md @@ -0,0 +1,42 @@ +# Debugging + +Debugging is vital for efficient Bash scripting. + +### Debugging Your Scripts + +Troubleshoot your Bash scripts by tracing execution. Use `-x` directly or `set -x` for specific sections. + +Run your script with `bash -x` to see every command executed: + +```bash +bash -x ./your_script.sh +``` + +For targeted debugging, use `set -x` where you want to start tracing, and `set +x` to stop. + +Create `debug_example.sh`: + +```bash +touch debug_example.sh +``` + +Open `debug_example.sh` and add: + +```bash +#!/usr/bin/env bash + +echo "Starting script." +set -x # Enable debug mode from here +ls -l +my_variable="test_data" +echo "Variable is: $my_variable" +set +x # Disable debug mode +echo "Debugging finished." +``` + +Save, make executable, and run: + +```bash +chmod +x debug_example.sh +./debug_example.sh +``` diff --git a/landing/docs/Bash-Scripts/0131-debugging.md b/landing/docs/Bash-Scripts/0131-debugging.md new file mode 100644 index 0000000..0e8ed31 --- /dev/null +++ b/landing/docs/Bash-Scripts/0131-debugging.md @@ -0,0 +1,44 @@ +# Debugging + +Ensure your Bash scripts run flawlessly. Master debugging to identify issues quickly and build robust code. + +### Debugging Your Scripts + +Troubleshoot your Bash scripts by tracing execution. Use `-x` directly or `set -x` for specific sections. + +Run your script with `bash -x` to see every command executed: + +```bash +bash -x ./your_script.sh +``` + +For targeted debugging, use `set -x` where you want to start tracing, and `set +x` to stop. + +Create `debug_example.sh`: + +```bash +touch debug_example.sh +``` + +Open `debug_example.sh` and add: + +```bash +#!/usr/bin/env bash + +echo "Starting script." +set -x # Enable debug mode from here +ls -l +my_variable="test_data" +echo "Variable is: $my_variable" +set +x # Disable debug mode +echo "Debugging finished." +``` + +Save, make executable, and run: + +```bash +chmod +x debug_example.sh +./debug_example.sh +``` + +Master these debugging techniques. They are indispensable for building high-quality, dependable Bash scripts. diff --git a/landing/docs/Bash-Scripts/014-creating-custom-bash-commands.md b/landing/docs/Bash-Scripts/014-creating-custom-bash-commands.md new file mode 100644 index 0000000..b43e2ba --- /dev/null +++ b/landing/docs/Bash-Scripts/014-creating-custom-bash-commands.md @@ -0,0 +1,82 @@ +# Custom Commands + +Optimize repetitive terminal tasks. Custom commands, or aliases, create shortcuts for long or frequently used commands. + +### Creating an Alias + +Consider a common scenario: checking web server connections with a lengthy `netstat` command: + +```bash +netstat -plant | grep '80\|443' | grep -v LISTEN | wc -l +``` + +Typing this repeatedly is inefficient. Create an alias as a shortcut. For example, let `conn` execute this command. + +```bash +alias conn="netstat -plant | grep '80\|443' | grep -v LISTEN | wc -l" +``` + +Now, simply type `conn`: + +```bash +conn +``` + +You'll get the same output. + +Enhance it with an informative message: + +```bash +alias conn="echo 'Total connections on port 80 and 443:' ; netstat -plant | grep '80\|443' | grep -v LISTEN | wc -l" +``` + +Running `conn` will now yield: + +``` +Total connections on port 80 and 443: +12 +``` + +Note: Aliases created this way are temporary. They disappear when your terminal session ends. + +### Making Aliases Permanent + +Aliases are session-bound by default. To make them permanent, add them to your shell's profile file. For Bash, this is typically `~/.bashrc`. + +Open `~/.bashrc` (or create it if it doesn't exist): + +```bash +nano ~/.bashrc +``` + +Add your alias to the end of the file: + +```bash +alias conn="echo 'Total connections on port 80 and 443:' ; netstat -plant | grep '80\|443' | grep -v LISTEN | wc -l" +``` + +Save and exit. + +Apply changes without restarting your terminal: + +```bash +source ~/.bashrc +``` + +Now, your custom command `conn` will be available in all new and sourced terminal sessions. + +### Listing Aliases + +To view all active aliases in your current shell, simply run: + +```bash +alias +``` + +This helps in troubleshooting command behavior. + +### Conclusion + +Aliases are powerful tools for optimizing your terminal workflow, offering quick command shortcuts. While full Bash scripts offer more complexity, aliases provide an immediate, user-level solution without requiring root access for installation. + +> {notice} This content was inspired by a piece by softwareshinobi on Dev Team Six. diff --git a/landing/docs/Bash-Scripts/015-writing-your-first-bash-script.md b/landing/docs/Bash-Scripts/015-writing-your-first-bash-script.md new file mode 100644 index 0000000..b317236 --- /dev/null +++ b/landing/docs/Bash-Scripts/015-writing-your-first-bash-script.md @@ -0,0 +1,142 @@ +# Your First Bash Script + +Time to build your first Bash script. We'll create a script to monitor server status, including: +* Disk usage +* CPU load +* RAM usage (Memory) +* TCP connections +* Kernel version + +Customize as needed. + +### Script Setup + +First, create your script file, `status.sh`: + +```bash +touch status.sh +``` + +Open `status.sh` with your text editor. Start with the shebang, `#!/usr/bin/env bash`. This tells the system how to execute the script. + +Add initial comments for clarity: + +```bash +#!/usr/bin/env bash + +# Script to report current server status. +``` + +### Variables + +Variables store data. Assign values using `=` (no spaces). Use `$()` for command substitution. + +Capture the server's hostname: + +```bash +server_name=$(hostname) +``` + +Echo the variable to see its value: + +```bash +echo "${server_name}" +``` + +### Functions + +Functions group commands for reuse. Let's create one for memory usage: + +```bash +function memory_check() { + echo "" + echo "Memory usage on ${server_name}: " + free -h + echo "" +} +``` + +This function prints a message and calls `free -h` for memory details. Call it by name (no parentheses): + +```bash +memory_check +``` + +Before seeing the complete solution, try implementing functions for: +* Disk usage +* CPU load +* TCP connections +* Kernel version + +Google commands if needed. There are multiple valid approaches. + +### The Complete Script + +Here's the full `status.sh` script: + +```bash +#!/usr/bin/env bash + +## +# Server status script: +# - Memory usage +# - CPU load +# - TCP connections +# - Kernel version +## + +server_name=$(hostname) + +function memory_check() { + echo "" + echo "Memory usage on ${server_name}: " + free -h + echo "" +} + +function cpu_check() { + echo "" + echo "CPU load on ${server_name}: " + echo "" + uptime + echo "" +} + +function tcp_check() { + echo "" + echo "TCP connections on ${server_name}: " + echo "" + cat /proc/net/tcp | wc -l + echo "" +} + +function kernel_check() { + echo "" + echo "Kernel version on ${server_name}: " + echo "" + uname -r + echo "" +} + +function all_checks() { + memory_check + cpu_check + tcp_check + kernel_check +} + +all_checks +``` + +Save `status.sh`, then make it executable and run: + +```bash +chmod +x status.sh +./status.sh +``` + +### Conclusion + +Bash scripting combines Linux commands to automate routine tasks, freeing you for more impactful work. This basic script demonstrates the power of automation. + +> {notice} This content was inspired by a piece by softwareshinobi on Dev Team Six. diff --git a/landing/docs/Bash-Scripts/016-creating-an-interactive-menu-in-bash.md b/landing/docs/Bash-Scripts/016-creating-an-interactive-menu-in-bash.md new file mode 100644 index 0000000..0b706f3 --- /dev/null +++ b/landing/docs/Bash-Scripts/016-creating-an-interactive-menu-in-bash.md @@ -0,0 +1,265 @@ +# Interactive Menu + +Build interactive Bash menus. This guide shows you how to create a menu where users choose which actions to run, leveraging previously defined functions for server status checks: + +* Memory usage +* CPU load +* TCP connections +* Kernel version + +Here's the base script containing these functions: + +```bash +#!/usr/bin/env bash + +## +# Server status script: +# - Memory usage +# - CPU load +# - Number of TCP connections +# - Kernel version +## + +server_name=$(hostname) + +function memory_check() { + echo "" + echo "Memory usage on ${server_name}: " + free -h + echo "" +} + +function cpu_check() { + echo "" + echo "CPU load on ${server_name}: " + echo "" + uptime + echo "" +} + +function tcp_check() { + echo "" + echo "TCP connections on ${server_name}: " + echo "" + cat /proc/net/tcp | wc -l + echo "" +} + +function kernel_check() { + echo "" + echo "Kernel version on ${server_name}: " + echo "" + uname -r + echo "" +} + +function all_checks() { + memory_check + cpu_check + tcp_check + kernel_check +} +``` + +We'll now integrate this with a menu, allowing users to select a function to execute. + +--- + +### Add Color for Readability + +Enhance your menu's readability with simple color functions. Add these variables and functions to your script: + +```bash +## +# Color Variables +## +green='\e[32m' +blue='\e[34m' +red='\e[31m' +clear='\e[0m' + +## +# Color Functions +## + +ColorGreen(){ + echo -ne $green$1$clear +} +ColorBlue(){ + echo -ne $blue$1$clear +} +ColorRed(){ + echo -ne $red$1$clear +} +``` + +Use them like: `$(ColorBlue 'Your text')`. + +--- + +### Build the Interactive Menu + +Create a `menu` function containing the display logic, user input, and a `case` statement for selection. + +```bash +menu(){ +echo -ne " +My Server Status Menu +$(ColorGreen '1)') Memory usage +$(ColorGreen '2)') CPU load +$(ColorGreen '3)') TCP connections +$(ColorGreen '4)') Kernel version +$(ColorGreen '5)') Check All +$(ColorGreen '0)') Exit +$(ColorBlue 'Choose an option:') " + read -r a + case $a in + 1) memory_check ; menu ;; + 2) cpu_check ; menu ;; + 3) tcp_check ; menu ;; + 4) kernel_check ; menu ;; + 5) all_checks ; menu ;; + 0) exit 0 ;; + *) echo -e $(ColorRed 'Invalid option.') ; menu ;; + esac +} +``` + +Here's how it works: +* The `echo -ne` block prints the menu options, applying colors. +* `read -r a` captures user input into variable `a`. +* The `case` statement executes the corresponding function. After each function, `menu` is called again to display the menu for another choice, creating a loop. `exit 0` handles the exit option. + +Finally, call the `menu` function at the end of your script to start the interaction: + +```bash +menu +``` + +--- + +### Complete Script and Testing + +Here's the entire script, `menu.sh`, combining all components: + +```bash +#!/usr/bin/env bash + +## +# BASH menu script that checks: +# - Memory usage +# - CPU load +# - Number of TCP connections +# - Kernel version +## + +server_name=$(hostname) + +function memory_check() { + echo "" + echo "Memory usage on ${server_name}: " + free -h + echo "" +} + +function cpu_check() { + echo "" + echo "CPU load on ${server_name}: " + echo "" + uptime + echo "" +} + +function tcp_check() { + echo "" + echo "TCP connections on ${server_name}: " + echo "" + cat /proc/net/tcp | wc -l + echo "" +} + +function kernel_check() { + echo "" + echo "Kernel version on ${server_name}: " + echo "" + uname -r + echo "" +} + +function all_checks() { + memory_check + cpu_check + tcp_check + kernel_check +} + +## +# Color Variables +## +green='\e[32m' +blue='\e[34m' +red='\e[31m' +clear='\e[0m' + +## +# Color Functions +## + +ColorGreen(){ + echo -ne $green$1$clear +} +ColorBlue(){ + echo -ne $blue$1$clear +} +ColorRed(){ + echo -ne $red$1$clear +} + +menu(){ +echo -ne " +My Server Status Menu +$(ColorGreen '1)') Memory usage +$(ColorGreen '2)') CPU load +$(ColorGreen '3)') TCP connections +$(ColorGreen '4)') Kernel version +$(ColorGreen '5)') Check All +$(ColorGreen '0)') Exit +$(ColorBlue 'Choose an option:') " + read -r a + case $a in + 1) memory_check ; menu ;; + 2) cpu_check ; menu ;; + 3) tcp_check ; menu ;; + 4) kernel_check ; menu ;; + 5) all_checks ; menu ;; + 0) exit 0 ;; + *) echo -e $(ColorRed 'Invalid option.') ; menu ;; + esac +} + +# Call the menu function +menu +``` + +Save this code as `menu.sh`: + +```bash +touch menu.sh +``` + +Open `menu.sh` and paste the script. Save and close. Then, make it executable and run: + +```bash +chmod +x menu.sh +./menu.sh +``` + +You'll see the colored menu, prompting for input. Select an option (e.g., `1` for memory check), and the corresponding information will display before the menu reappears, ready for another choice. + +--- + +### Conclusion + +You've built an interactive Bash menu, allowing users to effortlessly navigate script functionalities. This enhances user experience for your automation tools. + +> {notice} This content was inspired by a piece by softwareshinobi on Dev Team Six. diff --git a/landing/docs/Bash-Scripts/017-executing-bash-script-on-multiple-remote-server.md b/landing/docs/Bash-Scripts/017-executing-bash-script-on-multiple-remote-server.md new file mode 100644 index 0000000..c4e46f4 --- /dev/null +++ b/landing/docs/Bash-Scripts/017-executing-bash-script-on-multiple-remote-server.md @@ -0,0 +1,113 @@ +# Running On Multiple Servers + +Automate script execution across multiple remote servers. Instead of manual copying and logging in, learn to run Bash scripts on many machines with a single command. + +### Prerequisites + +You'll need a few remote Linux servers with **SSH access**. Gather their **IP addresses** or **hostnames** and list them in a file named `servers.txt`, one per line. + +Create `servers.txt`: + +```bash +touch servers.txt +``` + +Open `servers.txt` and add your server details: + +``` +your_server_ip_1 +your_server_ip_2 +your_server_ip_3 +``` + +--- + +### The Script for Remote Execution + +We'll use a simple Bash script that performs basic server checks: memory, CPU, TCP connections, and kernel version. Create a file named `remote_check.sh` and add the following content: + +```bash +touch remote_check.sh +``` + +Open `remote_check.sh` and add: + +```bash +#!/usr/bin/env bash + +## +# Server status script: +# - Memory usage +# - CPU load +# - Number of TCP connections +# - Kernel version +## + +server_name=$(hostname) + +function memory_check() { + echo "#######" + echo "The current memory usage on ${server_name} is: " + free -h + echo "#######" +} + +function cpu_check() { + echo "#######" + echo "The current CPU load on ${server_name} is: " + echo "" + uptime + echo "#######" +} + +function tcp_check() { + echo "#######" + echo "Total TCP connections on ${server_name}: " + echo "" + cat /proc/net/tcp | wc -l + echo "#######" +} + +function kernel_check() { + echo "#######" + echo "The exact Kernel version on ${server_name} is: " + echo "" + uname -r + echo "#######" +} + +function all_checks() { + memory_check + cpu_check + tcp_check + kernel_check +} + +all_checks +``` + +--- + +### Execute on Remote Servers + +With `remote_check.sh` and `servers.txt` ready, run the following single command. This loop iterates through each server, using **SSH** to execute the script without local file transfer or manual logins. + +```bash +for server in $(cat servers.txt); do ssh your_user@"${server}" 'bash -s' < ./remote_check.sh; done +``` + +**Breakdown:** +* `for server in $(cat servers.txt)`: Reads each IP/hostname from `servers.txt` into the `server` variable. +* `ssh your_user@"${server}"`: Connects to the remote server via SSH as `your_user`. +* `'bash -s'`: Executes a Bash shell on the remote server, reading commands from standard input. +* `< ./remote_check.sh`: Redirects the local `remote_check.sh` script's content to the remote Bash shell's standard input. + +Each server will then execute the script, printing its status checks directly to your local terminal. + +--- + +### Conclusion + +This method efficiently executes Bash scripts across multiple remote servers. It avoids manual file transfers and individual logins, proving scalable for more complex scripts and larger environments. For extensive, state-managed automation, dedicated tools are often recommended. + +> {notice} This content was inspired by a piece by softwareshinobi on Dev Team Six. diff --git a/landing/docs/Bash-Scripts/018-working-with-json-in-bash-using-jq.md b/landing/docs/Bash-Scripts/018-working-with-json-in-bash-using-jq.md new file mode 100644 index 0000000..c028604 --- /dev/null +++ b/landing/docs/Bash-Scripts/018-working-with-json-in-bash-using-jq.md @@ -0,0 +1,134 @@ +# Json Data + +`jq` is your lightweight, flexible command-line JSON processor. It's built in portable C with zero runtime dependencies, making it simple to install and powerful for parsing JSON in Bash. + +----- + +### Demo Setup: QuizAPI + +This demo uses the [QuizAPI](https://quizapi.io/) to fetch JSON data. Obtain a free **API key** from their [client area](https://quizapi.io/clientarea/settings/token) to follow along. + +----- + +### Installing `jq` + +`jq` is easily installed via your system's package manager or direct download. + + * **Ubuntu/Debian:** `sudo apt-get install jq` + * **Red Hat/Fedora:** `sudo dnf install jq` + * **Arch Linux:** `sudo pacman -S jq` + +For other systems, refer to the [official `jq` download page](https://www.google.com/search?q=%5Bhttps://stedolan.github.io/jq/download/%5D\(https://stedolan.github.io/jq/download/\)). Verify your installation: + +```bash +jq --version +``` + +----- + +### Basic JSON Parsing with `jq` + +Once `jq` is installed and you have your QuizAPI key, you can start processing JSON. + +First, set your API key: + +```bash +API_KEY=YOUR_API_KEY_HERE # Replace with your actual key +``` + +Fetch questions using `curl`: + +```bash +curl "https://quizapi.io/api/v1/questions?apiKey=${API_KEY}&limit=10" +``` + +The raw output is hard to read. Pipe it to `jq` for beautifully formatted and colored JSON: + +```bash +curl "https://quizapi.io/api/v1/questions?apiKey=${API_KEY}&limit=10" | jq +``` + +This command makes the JSON output structured and easy to inspect. + +----- + +### Extracting Specific Elements + +To get only the first element from a JSON array, use `.[0]`: + +```bash +curl "https://quizapi.io/api/v1/questions?apiKey=${API_KEY}&limit=10" | jq '.[0]' +``` + +This will output only the first JSON object in the array. + +----- + +### Fetching Key Values Across an Array + +To extract the value of a specific key (e.g., `question`) from every object in a JSON array, use `.[].key`: + +```bash +curl "https://quizapi.io/api/v1/questions?apiKey=${API_KEY}&limit=10" | jq '.[].question' +``` + +This will return a list of all questions from the API response. + +----- + +### Integrating `jq` into a Bash Script + +Let's create a script to fetch a question and its answers, then display them. We'll use `jq` to parse specific fields and assign them to Bash variables. + +Create `quiz_script.sh`: + +```bash +touch quiz_script.sh +``` + +Open `quiz_script.sh` and add (remember to replace `YOUR_API_KEY_HERE`): + +```bash +#!/usr/bin/env bash + +# Your QuizAPI Key (replace YOUR_API_KEY_HERE with your actual key) +API_KEY="YOUR_API_KEY_HERE" + +# Make an API call and get the first question object +# Using -s for silent mode to suppress curl's progress meter +QUIZ_DATA=$(curl -s "https://quizapi.io/api/v1/questions?apiKey=${API_KEY}&limit=1" 2>/dev/null) + +# Extract specific values using jq with raw output (-r) for Bash variables +question=$(echo "${QUIZ_DATA}" | jq -r '.[0].question') +answer_a=$(echo "${QUIZ_DATA}" | jq -r '.[0].answers.answer_a') +answer_b=$(echo "${QUIZ_DATA}" | jq -r '.[0].answers.answer_b') +answer_c=$(echo "${QUIZ_DATA}" | jq -r '.[0].answers.answer_c') +answer_d=$(echo "${QUIZ_DATA}" | jq -r '.[0].answers.answer_d') + +# Output the question and answers +echo " +Question: ${question} + +A) ${answer_a} +B) ${answer_b} +C) ${answer_c} +D) ${answer_d} +" +``` + +Save, make executable, and run: + +```bash +chmod +x quiz_script.sh +./quiz_script.sh +``` + +The script will print a random question and its corresponding answers. For more advanced, interactive Bash quizzes, explore community projects that build upon these `jq` principles. + +----- + +### Conclusion + +`jq` empowers you to process **JSON** directly within your Bash terminal, facilitating seamless interaction with **REST APIs**. For deeper dives, consult the [official `jq` manual](https://www.google.com/search?q=%5Bhttps://stedolan.github.io/jq/manual/%5D\(https://stedolan.github.io/jq/manual/\)) and the [QuizAPI documentation](https://quizapi.io/docs/1.0/overview). + +> {notice} This content was inspired by a piece by softwareshinobi on Dev Team Six. diff --git a/landing/docs/Bash-Scripts/023-bash-redirection.md b/landing/docs/Bash-Scripts/023-bash-redirection.md new file mode 100644 index 0000000..3aa5a10 --- /dev/null +++ b/landing/docs/Bash-Scripts/023-bash-redirection.md @@ -0,0 +1,217 @@ +# Redirection + +Master Bash redirection and pipes. These essential Linux features are critical for efficient system administration. Every command handles input, output, and errors through **File Descriptors (FDs)**: + +* **STDIN** (0): Standard Input – receives data. +* **STDOUT** (1): Standard Output – sends regular data. +* **STDERR** (2): Standard Error – sends error messages. + +--- + +### Pipes vs. Redirection + +Both manage data streams, but with a key difference: +* **Redirection** routes a command's input/output to or from a **file**. +* **Pipes** (`|`) connect the **output of one command directly to the input of another command**. + +--- + +### STDIN (Standard Input) + +Commands often expect input. By default, this is your keyboard, but you can redirect it from other sources. + +**Redirecting from a file (`<`)**: +Use `<` to feed a file's content as input to a command. Create `input.txt`: + +```bash +touch input.txt +``` +Open `input.txt` and add: +``` +Line 1 +Line 2 +``` +Save `input.txt`. +Then run: + +```bash +cat < input.txt +``` +This prints `input.txt` content, similar to `cat input.txt`. + +**Here-Documents (`<< DELIMITER`)**: +For multi-line input directly in your script or terminal, use a here-document with a custom delimiter (e.g., `EOF`). + +```bash +cat << EOF +Hello World! +How are you? +EOF +``` +This will print: +``` +Hello World! +How are you? +``` +Similarly, with `wc -l` to count lines: +```bash +wc -l << EOF +Hello World! +How are you? +EOF +``` +Output: +``` +2 +``` + +--- + +### STDOUT (Standard Output) + +Regular command output typically goes to your terminal. Redirect it to a file. + +**Overwrite (`>`)**: +Use `>` to send output to a file. If the file exists, its content is overwritten. Create `file.txt` (or ensure it's empty): + +```bash +echo "Hello World!" > file.txt +cat file.txt # Output: Hello World! +``` +Running again overwrites: + +```bash +echo "How are you?" > file.txt +cat file.txt # Output: How are you? (Previous content is gone) +``` + +**Append (`>>`)**: +Use `>>` to add output to the end of a file without overwriting existing content. + +```bash +echo "Hello World!" > file.txt # Start fresh +echo "How are you?" >> file.txt +cat file.txt +``` +Output: +``` +Hello World! +How are you? +``` + +You can also explicitly specify the STDOUT file descriptor (1): `echo "Hello" 1> file.txt`. + +--- + +### STDERR (Standard Error) + +Error messages, distinct from standard output, are sent to **STDERR**. Redirect them using file descriptor 2. + +**Redirecting Errors (`2>`)**: +Use `2>` to redirect error messages. For example, `ls --invalid-flag` generates an error. + +```bash +ls --invalid-flag 2> error.txt +cat error.txt # Contains the error message +``` +Use `2>>` to append error messages to a file. + +**Discarding Errors (`2> /dev/null`)**: +Send error output to `/dev/null` to completely suppress it. `/dev/null` is a special 'black hole' device that discards all data written to it. + +```bash +ls --invalid-flag 2> /dev/null # Error message is hidden +``` + +**Redirecting Both STDOUT and STDERR**: +You can manage both streams simultaneously. + +To separate regular output and errors into different files: + +```bash +# Assuming 'install_package.sh' generates both output and errors +./install_package.sh > output.txt 2> error.txt +``` + +To send both to the same file (concise syntax): + +```bash +./install_package.sh > combined_output.txt 2>&1 +``` +The `2>&1` redirects file descriptor 2 (STDERR) to the same location as file descriptor 1 (STDOUT), which is `combined_output.txt`. Alternatively, an even shorter Bash 4+ syntax: `&> combined_output.txt`. + +--- + +### Piping (`|`) + +Pipes connect the standard output of one command directly to the standard input of another, creating powerful command chains. + +**Basic Example:** Find `.txt` files in a directory listing. + +```bash +ls | grep ".txt" +``` +This sends `ls`'s output to `grep` for filtering. + +**Chaining Commands:** Analyze file ownership in a directory. + +```bash +ls -l /projects/bash_scripts | tail -n +2 | sed 's/\s\s*/ /g' | cut -d ' ' -f 3 | sort | uniq -c +``` +This sequence lists files, removes the header, cleans spacing, extracts owner names, sorts them, and counts unique occurrences. + +--- + +### Here-Documents (`<< DELIMITER`) + +Here-documents (`<<`) provide multi-line input directly within your script or terminal, ideal for commands that read from STDIN without needing a separate temporary file. + +Specify a custom delimiter (e.g., `EOF`): + +```bash +cat << END_MESSAGE +This text will be passed as input to cat. +It spans multiple lines. +END_MESSAGE +``` +Output: +``` +This text will be passed as input to cat. +It spans multiple lines. +``` +You can also pipe the output of a here-document to another command: + +```bash +wc -l << MESSAGE_LINES +Line one. +Line two. +Line three. +MESSAGE_LINES +``` +Output: `3` (counts the lines). Variables are expanded within here-documents. + +--- + +### Here-Strings (`<<<`) + +For piping a single string into a command's STDIN, use a here-string (`<<<`). This is cleaner than a here-document for single lines. + +```bash +wc -w <<<"This is a sample string for word count." +``` +Output: `7` (counts words). +Variables are also supported in here-strings. + +--- + +### Summary of Redirection and Piping Operators + +| **Operator** | **Description** | +| :--- | :--- | +| `>` | Redirect STDOUT to a file, overwriting existing content. | +| `>>` | Redirect STDOUT to a file, appending to existing content. | +| `<` | Redirect STDIN from a file. | +| `2>` | Redirect STDERR to a file, overwriting existing content. | +| `|` | Pipe STDOUT of one command to STDIN of another. | +| `<<` | Here-document: Provide multi-line STDIN from the script. | +| `<<<` | Here-string: Provide single-line STDIN from the command line. | diff --git a/landing/docs/commands/archives/gunzip.md b/landing/docs/Commands/archive/gunzip.md similarity index 100% rename from landing/docs/commands/archives/gunzip.md rename to landing/docs/Commands/archive/gunzip.md diff --git a/landing/docs/commands/archives/gzip.md b/landing/docs/Commands/archive/gzip.md similarity index 100% rename from landing/docs/commands/archives/gzip.md rename to landing/docs/Commands/archive/gzip.md diff --git a/landing/docs/commands/archives/tar.md b/landing/docs/Commands/archive/tar.md similarity index 100% rename from landing/docs/commands/archives/tar.md rename to landing/docs/Commands/archive/tar.md diff --git a/landing/docs/commands/archives/unzip.md b/landing/docs/Commands/archive/unzip.md similarity index 100% rename from landing/docs/commands/archives/unzip.md rename to landing/docs/Commands/archive/unzip.md diff --git a/landing/docs/commands/archives/zip.md b/landing/docs/Commands/archive/zip.md similarity index 100% rename from landing/docs/commands/archives/zip.md rename to landing/docs/Commands/archive/zip.md diff --git a/landing/docs/commands/terminal/alias.md b/landing/docs/Commands/core/alias.md similarity index 100% rename from landing/docs/commands/terminal/alias.md rename to landing/docs/Commands/core/alias.md diff --git a/landing/docs/commands/terminal/cd.md b/landing/docs/Commands/core/cd.md similarity index 100% rename from landing/docs/commands/terminal/cd.md rename to landing/docs/Commands/core/cd.md diff --git a/landing/docs/commands/terminal/clear.md b/landing/docs/Commands/core/clear.md similarity index 100% rename from landing/docs/commands/terminal/clear.md rename to landing/docs/Commands/core/clear.md diff --git a/landing/docs/commands/terminal/echo.md b/landing/docs/Commands/core/echo.md similarity index 100% rename from landing/docs/commands/terminal/echo.md rename to landing/docs/Commands/core/echo.md diff --git a/landing/docs/commands/system/env.md b/landing/docs/Commands/core/env.md similarity index 100% rename from landing/docs/commands/system/env.md rename to landing/docs/Commands/core/env.md diff --git a/landing/docs/commands/terminal/exit.md b/landing/docs/Commands/core/exit.md similarity index 100% rename from landing/docs/commands/terminal/exit.md rename to landing/docs/Commands/core/exit.md diff --git a/landing/docs/commands/terminal/history.md b/landing/docs/Commands/core/history.md similarity index 100% rename from landing/docs/commands/terminal/history.md rename to landing/docs/Commands/core/history.md diff --git a/landing/docs/commands/terminal/less.md b/landing/docs/Commands/core/less.md similarity index 100% rename from landing/docs/commands/terminal/less.md rename to landing/docs/Commands/core/less.md diff --git a/landing/docs/commands/system/man.md b/landing/docs/Commands/core/man.md similarity index 100% rename from landing/docs/commands/system/man.md rename to landing/docs/Commands/core/man.md diff --git a/landing/docs/commands/terminal/pwd.md b/landing/docs/Commands/core/pwd.md similarity index 100% rename from landing/docs/commands/terminal/pwd.md rename to landing/docs/Commands/core/pwd.md diff --git a/landing/docs/commands/terminal/sleep.md b/landing/docs/Commands/core/sleep.md similarity index 100% rename from landing/docs/commands/terminal/sleep.md rename to landing/docs/Commands/core/sleep.md diff --git a/landing/docs/commands/system/whereis.md b/landing/docs/Commands/core/whereis.md similarity index 100% rename from landing/docs/commands/system/whereis.md rename to landing/docs/Commands/core/whereis.md diff --git a/landing/docs/commands/terminal/yes.md b/landing/docs/Commands/core/yes.md similarity index 100% rename from landing/docs/commands/terminal/yes.md rename to landing/docs/Commands/core/yes.md diff --git a/landing/docs/commands/disk/fdisk.md b/landing/docs/Commands/disk/fdisk.md similarity index 100% rename from landing/docs/commands/disk/fdisk.md rename to landing/docs/Commands/disk/fdisk.md diff --git a/landing/docs/commands/disk/mount.md b/landing/docs/Commands/disk/mount.md similarity index 100% rename from landing/docs/commands/disk/mount.md rename to landing/docs/Commands/disk/mount.md diff --git a/landing/docs/commands/disk/parted.md b/landing/docs/Commands/disk/parted.md similarity index 100% rename from landing/docs/commands/disk/parted.md rename to landing/docs/Commands/disk/parted.md diff --git a/landing/docs/commands/files/cat.md b/landing/docs/Commands/files/cat.md similarity index 100% rename from landing/docs/commands/files/cat.md rename to landing/docs/Commands/files/cat.md diff --git a/landing/docs/commands/files/cp.md b/landing/docs/Commands/files/cp.md similarity index 100% rename from landing/docs/commands/files/cp.md rename to landing/docs/Commands/files/cp.md diff --git a/landing/docs/commands/files/diff.md b/landing/docs/Commands/files/diff.md similarity index 100% rename from landing/docs/commands/files/diff.md rename to landing/docs/Commands/files/diff.md diff --git a/landing/docs/commands/files/dir.md b/landing/docs/Commands/files/dir.md similarity index 100% rename from landing/docs/commands/files/dir.md rename to landing/docs/Commands/files/dir.md diff --git a/landing/docs/commands/disk/du.md b/landing/docs/Commands/files/du.md similarity index 100% rename from landing/docs/commands/disk/du.md rename to landing/docs/Commands/files/du.md diff --git a/landing/docs/commands/files/find.md b/landing/docs/Commands/files/find.md similarity index 100% rename from landing/docs/commands/files/find.md rename to landing/docs/Commands/files/find.md diff --git a/landing/docs/commands/terminal/grep.md b/landing/docs/Commands/files/grep.md similarity index 100% rename from landing/docs/commands/terminal/grep.md rename to landing/docs/Commands/files/grep.md diff --git a/landing/docs/commands/terminal/head.md b/landing/docs/Commands/files/head.md similarity index 100% rename from landing/docs/commands/terminal/head.md rename to landing/docs/Commands/files/head.md diff --git a/landing/docs/commands/files/ls.md b/landing/docs/Commands/files/ls.md similarity index 100% rename from landing/docs/commands/files/ls.md rename to landing/docs/Commands/files/ls.md diff --git a/landing/docs/commands/files/mkdir.md b/landing/docs/Commands/files/mkdir.md similarity index 100% rename from landing/docs/commands/files/mkdir.md rename to landing/docs/Commands/files/mkdir.md diff --git a/landing/docs/commands/files/mv.md b/landing/docs/Commands/files/mv.md similarity index 100% rename from landing/docs/commands/files/mv.md rename to landing/docs/Commands/files/mv.md diff --git a/landing/docs/commands/files/nano.md b/landing/docs/Commands/files/nano.md similarity index 100% rename from landing/docs/commands/files/nano.md rename to landing/docs/Commands/files/nano.md diff --git a/landing/docs/commands/files/rm.md b/landing/docs/Commands/files/rm.md similarity index 100% rename from landing/docs/commands/files/rm.md rename to landing/docs/Commands/files/rm.md diff --git a/landing/docs/commands/terminal/tail.md b/landing/docs/Commands/files/tail.md similarity index 100% rename from landing/docs/commands/terminal/tail.md rename to landing/docs/Commands/files/tail.md diff --git a/landing/docs/commands/files/touch.md b/landing/docs/Commands/files/touch.md similarity index 100% rename from landing/docs/commands/files/touch.md rename to landing/docs/Commands/files/touch.md diff --git a/landing/docs/commands/files/vim.md b/landing/docs/Commands/files/vim.md similarity index 100% rename from landing/docs/commands/files/vim.md rename to landing/docs/Commands/files/vim.md diff --git a/landing/docs/commands/terminal/xargs.md b/landing/docs/Commands/files/xargs.md similarity index 100% rename from landing/docs/commands/terminal/xargs.md rename to landing/docs/Commands/files/xargs.md diff --git a/landing/docs/Commands/index.md b/landing/docs/Commands/index.md new file mode 100644 index 0000000..8458b63 --- /dev/null +++ b/landing/docs/Commands/index.md @@ -0,0 +1,37 @@ +# Home + +You want to manage linux servers. Get results. Stop drowning in useless commands and ditch the theory. + +!["Shinobi Academy Linux"](/../cover.png) + +## About + +I've run critical systems for the Feds for years. There are the few battle tested commands I *actually* use. + +I've stripped the fluff, cut the fat, and distilled the chaos into your essential arsenal. Your direct path to mastery. + +## Server Sectors + +Broken down into actionable categories, so you can start **dominating:** + +* **Core:** Your foundational power. The commands you'll live in, every single day, to navigate and interact. + +* **Files:** Master your data. Create, move, edit, and find anything. This is where you own your content. + +* **Monitor:** See the heartbeat of your system. Diagnose problems, track performance, and stay ahead of trouble. + +* **Network:** Command your connections, communicate like a boss. From basic pings to secure remote access. + +* **Process:** Take control. Understand what's running, manage tasks, and keep your system lean and efficient. + +* **Software:** Install, update, and manage your applications. The tools to keep your system armed and ready. + +* **System:** Deep dives into the machine itself. Configure, reboot, shutdown, and understand your hardware. + +* **Users:** Secure your access. Manage permissions, create users, and control who does what on your system. + +* **Archive:** Compress, extract, and protect your data. Keep things tight and organized. + +* **Disk:** Understand your storage. Manage partitions, check space, and keep your drives optimized. + +Learn what matters. **Win.** diff --git a/landing/docs/commands/disk/df.md b/landing/docs/Commands/monitor/df.md similarity index 100% rename from landing/docs/commands/disk/df.md rename to landing/docs/Commands/monitor/df.md diff --git a/landing/docs/commands/terminal/htop.md b/landing/docs/Commands/monitor/htop.md similarity index 100% rename from landing/docs/commands/terminal/htop.md rename to landing/docs/Commands/monitor/htop.md diff --git a/landing/docs/commands/disk/lsblk.md b/landing/docs/Commands/monitor/lsblk.md similarity index 100% rename from landing/docs/commands/disk/lsblk.md rename to landing/docs/Commands/monitor/lsblk.md diff --git a/landing/docs/commands/networking/netstat.md b/landing/docs/Commands/monitor/netstat.md similarity index 100% rename from landing/docs/commands/networking/netstat.md rename to landing/docs/Commands/monitor/netstat.md diff --git a/landing/docs/commands/processes/ps.md b/landing/docs/Commands/monitor/ps.md similarity index 100% rename from landing/docs/commands/processes/ps.md rename to landing/docs/Commands/monitor/ps.md diff --git a/landing/docs/commands/terminal/top.md b/landing/docs/Commands/monitor/top.md similarity index 100% rename from landing/docs/commands/terminal/top.md rename to landing/docs/Commands/monitor/top.md diff --git a/landing/docs/commands/networking/curl.md b/landing/docs/Commands/network/curl.md similarity index 100% rename from landing/docs/commands/networking/curl.md rename to landing/docs/Commands/network/curl.md diff --git a/landing/docs/commands/networking/ifconfig.md b/landing/docs/Commands/network/ifconfig.md similarity index 100% rename from landing/docs/commands/networking/ifconfig.md rename to landing/docs/Commands/network/ifconfig.md diff --git a/landing/docs/commands/networking/nslookup.md b/landing/docs/Commands/network/nslookup.md similarity index 100% rename from landing/docs/commands/networking/nslookup.md rename to landing/docs/Commands/network/nslookup.md diff --git a/landing/docs/commands/networking/ping.md b/landing/docs/Commands/network/ping.md similarity index 100% rename from landing/docs/commands/networking/ping.md rename to landing/docs/Commands/network/ping.md diff --git a/landing/docs/commands/networking/ssh.md b/landing/docs/Commands/network/ssh.md similarity index 100% rename from landing/docs/commands/networking/ssh.md rename to landing/docs/Commands/network/ssh.md diff --git a/landing/docs/commands/networking/wget.md b/landing/docs/Commands/network/wget.md similarity index 100% rename from landing/docs/commands/networking/wget.md rename to landing/docs/Commands/network/wget.md diff --git a/landing/docs/commands/processes/kill.md b/landing/docs/Commands/process/kill.md similarity index 100% rename from landing/docs/commands/processes/kill.md rename to landing/docs/Commands/process/kill.md diff --git a/landing/docs/commands/processes/killall.md b/landing/docs/Commands/process/killall.md similarity index 100% rename from landing/docs/commands/processes/killall.md rename to landing/docs/Commands/process/killall.md diff --git a/landing/docs/commands/processes/nohup.md b/landing/docs/Commands/process/nohup.md similarity index 100% rename from landing/docs/commands/processes/nohup.md rename to landing/docs/Commands/process/nohup.md diff --git a/landing/docs/commands/system/apt.md b/landing/docs/Commands/software/apt.md similarity index 100% rename from landing/docs/commands/system/apt.md rename to landing/docs/Commands/software/apt.md diff --git a/landing/docs/commands/system/yum.md b/landing/docs/Commands/software/yum.md similarity index 100% rename from landing/docs/commands/system/yum.md rename to landing/docs/Commands/software/yum.md diff --git a/landing/docs/commands/system/crontab.md b/landing/docs/Commands/system/crontab.md similarity index 100% rename from landing/docs/commands/system/crontab.md rename to landing/docs/Commands/system/crontab.md diff --git a/landing/docs/commands/system/date.md b/landing/docs/Commands/system/date.md similarity index 100% rename from landing/docs/commands/system/date.md rename to landing/docs/Commands/system/date.md diff --git a/landing/docs/commands/system/hostname.md b/landing/docs/Commands/system/hostname.md similarity index 100% rename from landing/docs/commands/system/hostname.md rename to landing/docs/Commands/system/hostname.md diff --git a/landing/docs/commands/system/hostnamectl.md b/landing/docs/Commands/system/hostnamectl.md similarity index 100% rename from landing/docs/commands/system/hostnamectl.md rename to landing/docs/Commands/system/hostnamectl.md diff --git a/landing/docs/commands/system/reboot.md b/landing/docs/Commands/system/reboot.md similarity index 100% rename from landing/docs/commands/system/reboot.md rename to landing/docs/Commands/system/reboot.md diff --git a/landing/docs/commands/system/shutdown.md b/landing/docs/Commands/system/shutdown.md similarity index 100% rename from landing/docs/commands/system/shutdown.md rename to landing/docs/Commands/system/shutdown.md diff --git a/landing/docs/commands/system/su.md b/landing/docs/Commands/system/su.md similarity index 100% rename from landing/docs/commands/system/su.md rename to landing/docs/Commands/system/su.md diff --git a/landing/docs/commands/system/sudo.md b/landing/docs/Commands/system/sudo.md similarity index 100% rename from landing/docs/commands/system/sudo.md rename to landing/docs/Commands/system/sudo.md diff --git a/landing/docs/commands/system/uname.md b/landing/docs/Commands/system/uname.md similarity index 100% rename from landing/docs/commands/system/uname.md rename to landing/docs/Commands/system/uname.md diff --git a/landing/docs/commands/access/chmod.md b/landing/docs/Commands/users/chmod.md similarity index 100% rename from landing/docs/commands/access/chmod.md rename to landing/docs/Commands/users/chmod.md diff --git a/landing/docs/commands/access/chown.md b/landing/docs/Commands/users/chown.md similarity index 100% rename from landing/docs/commands/access/chown.md rename to landing/docs/Commands/users/chown.md diff --git a/landing/docs/commands/access/deluser.md b/landing/docs/Commands/users/deluser.md similarity index 100% rename from landing/docs/commands/access/deluser.md rename to landing/docs/Commands/users/deluser.md diff --git a/landing/docs/commands/access/groups.md b/landing/docs/Commands/users/groups.md similarity index 100% rename from landing/docs/commands/access/groups.md rename to landing/docs/Commands/users/groups.md diff --git a/landing/docs/commands/access/passwd.md b/landing/docs/Commands/users/passwd.md similarity index 100% rename from landing/docs/commands/access/passwd.md rename to landing/docs/Commands/users/passwd.md diff --git a/landing/docs/commands/access/useradd.md b/landing/docs/Commands/users/useradd.md similarity index 100% rename from landing/docs/commands/access/useradd.md rename to landing/docs/Commands/users/useradd.md diff --git a/landing/docs/commands/access/usermod.md b/landing/docs/Commands/users/usermod.md similarity index 100% rename from landing/docs/commands/access/usermod.md rename to landing/docs/Commands/users/usermod.md diff --git a/landing/docs/commands/access/whoami.md b/landing/docs/Commands/users/whoami.md similarity index 100% rename from landing/docs/commands/access/whoami.md rename to landing/docs/Commands/users/whoami.md diff --git a/landing/docs/commands/index.md b/landing/docs/commands/index.md deleted file mode 100644 index 2f56c53..0000000 --- a/landing/docs/commands/index.md +++ /dev/null @@ -1,15 +0,0 @@ -# Home - -You wanna manage Linux servers, right? You wanna stop wasting time wading through endless command lists? - -**Here's the truth:** You're drowning in noise. Hundreds of Linux commands? Who cares? You think Fortune 500 companies and the US government need *all* of them? They don't. I've managed their servers. And I've done it with a fraction of those commands. - -**Here's the deal:** I've stripped away the fluff. I've distilled the chaos. What's left? The 50 commands I *actually* use. The 50 commands that get the job done. - -**Why 50?** Because that's all you need. That's all *I* need. And if it's good enough for me, it's damn sure good enough for you. - -**Time is your most valuable asset.** You're not here to memorize every obscure Linux command. You're here to build, to scale, to dominate. You're here to *win*. - -**Learn the 50 commands that actually matter.** Get the system that cuts through the noise. Get the training that delivers results. This isn't theory. This is what I use. This is what *works*. - -**Good enough for SoftwareShinobi, good enough for you.** diff --git a/landing/docs/gemini b/landing/docs/gemini new file mode 100644 index 0000000..c961eca --- /dev/null +++ b/landing/docs/gemini @@ -0,0 +1 @@ +ok, now we gotta start rewriting articles. where a script mentions "devdojo" i want it to be renamed to "Dev Team Six". where 'bobby' is mentioned, use 'softwareshinobi' also lightly rewrite to talk like a more concise but less intense leila hormozi. dont make assumptions about a file existing, create everything from scratch.: