CLI - Tips & Tricks

PATH

# For bash, zsh
echo $PATH | sed 's/:/\n/g'
# For fish
echo $PATH | sed 's//\n/g'
# Output
/home/admin/.local/bin # The shell checks this directory first
/home/admin/bin
/usr/local/bin
/usr/local/sbin
/usr/bin
/usr/sbin

Command history

What is command history

(Almost) everything you type to the terminal is saved.

Where is the command history

The command history is stored at $HISTFILE, which by default:

  • For bash, it’s ~/.bash_history,
  • For zsh, it’s ~/..zsh_history,
  • For fish, its’s ~/.local/share/fish/fish_history

How to use command history

  • Access last command:

    • Press Arrow Up
    • Press Arrow Up more for last of last command
  • Search for a command is the command history: Ctrl + R

    For a default bash, zsh prompt, it looks like this

    (reverse-i-search)`’:
    
  • Use atuin1 for a magical 🪄 shell history, which:

    • records additional context for your commands
    • synchronizes your history between machines/shells

Command completion

  • Use Warp2 terminal
  • Use fish3 shell
  • Use argc-completions4

How to know how to use a command?

  • Use --help, -h, help flag/option/sub-command

    • Some commands support --help

      uname --help
      
      uname -h # Does't work
      
    • Some commands support -h

      dig -h
      
      dig --help # Doesn't work
      
    • Some commands support both --help, -h and even have a sub-command named help

      go help
      
      go -h
      
      go --help
      
    • Some commands don’t support --help or -h, and don’t have a help sub-command either, e.g. ssh, ssh-keygen

      $ ssh -h
      unknown option -- h
      
      $ ssh --help
      unknown option -- -
      
      $ ssh help
      ssh: Could not resolve hostname help: Name or service not known
      
  • Access the command’s manual pages

    man uname
    
  • Use tldr5, cheat6

    tldr uname
    
    cheat uname
    
1

https://github.com/atuinsh/atuin

4

https://github.com/sigoden/argc-completions

2

https://www.warp.dev/

3

https://fishshell.com/

5

https://github.com/tldr-pages/tldr

6

https://github.com/cheat/cheat