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 Up
more for last of last command - …
- Press
-
Search for a command is the command history:
Ctrl + R
For a default bash, zsh prompt, it looks like this
(reverse-i-search)`’:
-
Use
atuin
1 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
,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 namedhelp
go help
go -h
go --help
-
Some commands don’t support
--help
or-h
, and don’t have ahelp
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
-
tldr uname
cheat 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