CLI - Tips & Tricks
PATH
Print all entries in $PATH line by line
# 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 Upmore for last of last command - …
- Press
-
Search for a command is the command history:
Ctrl + RFor 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
How to know how to use a command?
-
Use
--help,-h,helpflag/option/sub-command-
Some commands support
--helpuname --helpuname -h # Does't work -
Some commands support
-hdig -hdig --help # Doesn't work -
Some commands support both
--help,-hand even have a sub-command namedhelpgo helpgo -hgo --help -
Some commands don’t support
--helpor-h, and don’t have ahelpsub-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 -
tldr unamecheat uname
https://github.com/atuinsh/atuin
https://github.com/sigoden/argc-completions
https://www.warp.dev/
https://fishshell.com/
https://github.com/tldr-pages/tldr
https://github.com/cheat/cheat