Quick Reference

Cheatsheets

Practical command references for Linux, networking, servers, containers, databases, and more.

Cheatsheet#fish-cheatsheet

Fish Cheatsheet

Fish (Friendly Interactive Shell) is a smart and user-friendly command line shell that comes with autosuggestions and syntax highlighting by default, requiring almost zero configuration.

Installation

# Debian / Ubuntu
sudo apt-add-repository ppa:fish-shell/release-3
sudo apt update
sudo apt install fish
 
# Arch Linux
sudo pacman -S fish
 
# macOS
brew install fish

Basic Configuration

fish --version            # Check version
chsh -s (which fish)      # Change default shell to Fish

Configuration file is located at ~/.config/fish/config.fish. Unlike Bash or Zsh, Fish uses ~/.config/fish/ for its configuration directory.

Core Features

Autosuggestions

As you type, Fish suggests commands based on your history and completions.

  • Press Right Arrow or Ctrl + F to accept the entire suggestion.
  • Press Alt + Right Arrow to accept the first word of the suggestion.

Web-based Configuration

Fish provides a beautiful web interface to configure colors, prompts, functions, and variables.

fish_config

Variables

Fish uses the set command instead of var=value.

# Local variable
set name "John"
echo $name
 
# Export variable (Environment variable) (-x)
set -x PATH /usr/local/bin $PATH
 
# Universal variable (-U) (Persists across sessions and reboots)
set -U EDITOR nvim
 
# Erase a variable (-e)
set -e name

Functions

Functions are typically saved in ~/.config/fish/functions/<name>.fish. Fish autoloads them automatically.

function greet
    echo "Hello, $argv[1]!"
end
 
greet "World"

To save a function permanently from the interactive shell:

funcsave greet

Aliases (Abbreviations)

Fish uses "abbreviations" instead of aliases. Abbreviations expand out when you press space, which is often preferred over hidden aliases.

abbr -a gco "git checkout"
abbr -a update "sudo apt update && sudo apt upgrade"

Control Flow & Loops

# If statement
if test $USER = "root"
    echo "You are admin"
else
    echo "You are a regular user"
end
 
# For loop
for file in *.txt
    echo "Text file: $file"
end