🐧 Linux Shells Cheat Sheet

🐧 Linux Shells Cheat Sheet #

An overview of common and specialized Linux shells, from the standard Bash to the user-friendly Fish, and security-focused options like rbash and chroot.


πŸ“‹ Shell Paths at a Glance #

Path Description
/bin/sh The standard command language shell. Often a symbolic link to bash or dash for POSIX compatibility.
/bin/bash The Bourne Again Shell, a common interactive and scripting shell. Located in /bin for essential access.
/usr/bin/bash Another location for Bash. On many modern systems, /bin is a symlink to /usr/bin, making them identical.
/bin/rbash Restricted Bash. A version of bash with limited features for security.
/usr/bin/rbash Another location for Restricted Bash.
/bin/dash Debian Almquist Shell. A lightweight, fast, POSIX-compliant shell, often used as the default /bin/sh.
/usr/bin/dash Another location for the Dash shell.
/bin/bash (chrooted) Not a path, but bash running in a chroot jail, isolated from the main system’s file structure.

🌐 Interactive Shells #

These are the shells you typically use for day-to-day command-line work.

Bash (Bourne Again Shell) #

The most common default shell on Linux systems. It’s powerful, POSIX-compliant, and has been the standard for decades.

  • Key Features: Command history, job control, scripting capabilities.
  • Pros: Ubiquitous, stable, and well-documented. Scripts are highly portable.
  • Cons: Lacks modern features out-of-the-box like advanced autocompletion and syntax highlighting.

Zsh (Z Shell) #

A powerful shell with more features than Bash. It’s highly customizable, especially with frameworks like “Oh My Zsh”.

  • Key Features: Advanced autocompletion, spelling correction, theming, and a massive plugin ecosystem.
  • Pros: Highly extensible, great user experience with plugins, largely Bash-compatible.
  • Cons: Can be slower to start with many plugins. Not strictly POSIX-compliant.

Fish (Friendly Interactive Shell) #

A modern shell that focuses on being user-friendly and providing a great experience out-of-the-box.

  • Key Features: Autosuggestions, syntax highlighting, and web-based configuration.
  • Pros: Excellent for beginners, powerful features require no setup, simple syntax.
  • Cons: Not POSIX-compliant, which can break scripts written for Bash/Zsh.

πŸ”’ Restricted & Specialized Shells #

These shells are used for security, system administration, and creating isolated environments.

rbash (Restricted Bash Shell) #

A restricted mode of Bash that limits what a user can do. It’s used to create a more controlled and secure environment.

  • Restrictions:
    • Cannot use the cd command to change directories.
    • Cannot change the values of $PATH, $SHELL, $BASH_ENV, or $ENV.
    • Cannot execute scripts with / in the name.
    • Cannot redirect output.
  • Use Cases: Public terminals, shared servers, or limiting users to a specific set of commands.

Chroot Jail #

A chroot environment changes the apparent root directory for a process and its children. This effectively “jails” the process, isolating it from the rest of the file system.

  • How it Works: A process running in a chroot cannot see or access files outside of its designated directory tree.
  • Use Cases:
    • System Recovery: Repairing a broken system or reinstalling a bootloader.
    • Testing: Creating a safe, isolated space to test software.
    • Security: Running a service (like a web server) in a chrooted environment to limit potential damage if it’s compromised.

πŸ’‘ Which Shell Should You Use? #

  • For Scripting & Portability: Stick with Bash.
  • For a Rich, Customizable Experience: Zsh with “Oh My Zsh” is a fantastic choice.
  • For a User-Friendly, Modern Experience: Fish is excellent, especially for newcomers.
  • For Security & Limited Access: Use rbash or a chroot environment depending on the level of restriction needed.