Control the Chaos: Learn Shell Paths, Bash Configs & I/O Magic (Part 2)

Control the Chaos: Learn Shell Paths, Bash Configs & I/O Magic (Part 2)

Get comfortable with the building blocks of shell scripting: paths, profiles, and I/O redirection made simple.

Generated image

Ever wonder how the Linux terminal handles all the magic behind the scenes? From jumping through folders, tweaking system settings, to redirecting output into files — it all happens with the help of paths, environment configurations, and I/O redirections.

This article is part 2 of our series and will walk you through these core concepts in a way that feels like a casual chat — not a boring lecture. Here is the link to part 1 — Control Everything with the Linux Shell — Without the Headache (Part 1)


Why Should You Care?

Here’s why this stuff matters (and how it helps you):

  • 🔄 You’ll understand how file navigation actually works (no more getting lost in directories).
  • ⚙️ Learn how the shell behaves and how you can tweak it to your liking.
  • 📤 Want to log errors or save output from a command to a file? You’ll know exactly how.
  • 🧠 Whether you’re just curious or want to level up your Linux skills, these tools are powerful (and not that hard once explained right).

Let’s break it down.👇


📁 Paths: Your Terminal GPS

  • Think of paths like directions on where to go in your system.
  • There are absolute paths (like full addresses: /usr/home) and relative paths (like "from here, go 2 steps forward").
  • / is the root directory, the base from where everything starts.
  • ~ is a shortcut to your current user's home directory. So cd ~ takes you straight there.

👉 Absolute path works no matter where you are.
👉 Relative path depends on your current location in the system.


🧰 Environment Configurations: Shell, Set, Go!

  • When you open a terminal, you’re starting a shell session — and it comes with its own settings.
  • These settings (colors, variables, aliases) are defined in config files like:
  • .bash_profile: Loads first, sets preferences and user-specific configurations.
  • .bashrc: Holds aliases, custom shortcuts, etc.
  • .profile: Acts as a fallback and supports other shell interpreters.

💡 Order of execution.bash_profile → .bashrc → .profile

You can add things like:

alias update='apt-get update'

…so the next time you type update, it runs the full command.

Also, /etc/skel contains default configs for new users — making it easy to clone settings system-wide.


🔄 Input-Output Redirections: Direct the Flow

Your terminal doesn’t always need you to type everything. Sometimes, it can read from or write to files instead of your screen or keyboard.

🔹 Standard Input (stdin)

  • Comes from your keyboard by default.
  • You can redirect input from a file using <:
cat < test.txt
  • You can use files as email content:
mail -s "Hello" test@gmail.com < body.txt

🔹 Here Document (<<)

Give multiple lines directly to a command:

cat >> test
<<EOF
Line 1
Line 2
EOF

The EOF (end-of-file) is a custom marker that ends input.

🔹 Here String (<<<)

Pass a quick string as input:

grep "findme" <<< "this is a findme test"

📤 Standard Output (stdout) & 📛 Standard Error (stderr)

By default, terminal outputs show on your screen. But you can change that:

  • > sends output to a file (overwrites it).
  • >> appends output to the file (adds to the end).
cat text.txt > copy.txt       # overwrites
echo "new" >> copy.txt # appends
  • 2> redirects errors only:
apt-get update 2> error.log
  • 2>> appends errors instead of overwriting.
  • Want to redirect both output and errors?
command > output.log 2>&1

That sends both stdout and stderr to output.log.


✅ TL;DR

  • Paths help you move around; absolute ones are full paths, relative ones depend on where you are.
  • Shell config files set your terminal’s behavior. Customize them to boost productivity.
  • Input/output redirection lets you use files as input and save outputs/errors elsewhere — perfect for automation and debugging.

Want to master the Linux shell without breaking a sweat? Stick around for Part 3 — it only gets better from here.

Post a Comment

Previous Post Next Post