Cursor navigation through key bindings
ctrl
+ a
: Moves the cursor to the start of the command.
ctrl
+ e
: Moves the cursor to the end of the command.
ctrl
+ w
: Deletes the single word to the left of the cursor.
ctrl
+ u
: Deletes all words to the left of the cursor.
ctrl
+ k
: Deletes all words to the right of the cursor.
ctrl
+ ➡️
: Moves the cursor forward to the beginning of the next word.
ctrl
+ ⬅️
: Moves the cursor backward to the beginning of the previous word.
Efficient command history navigation
Up arrow and Down arrow
⬆️ (up arrow)
: Retrieves the most recently used command.
For example, if you type the commands one
, two
, three
, four
in this order
⬆️
: Retrieves the four
command.
Pressing it again will cycle through previous commands in reverse chronological order.
⬆️
: Pressing the up arrow a second time retrieves the three
command.
If you've pressed the up arrow to navigate to an earlier command, pressing the down arrow will cycle forward through your history
⬇️ (down arrow)
: Pressing the down arrow will retrieves four
command.
Ctrl + r
This key binding is useful when you want to quickly find and reuse a previously entered command without scrolling through your entire command history using ⬆️
key.
Initiating the Search: When you press
ctrl
+r
, the terminal will display a prompt, often indicated by(reverse-i-search)
. This indicates that you're now in reverse search mode.Typing the Search Query: When you begin typing part of the command you want to find, the terminal automatically searches through your command history in reverse order and shows the most recent match that includes the characters you've typed so far.
- Press
ctrl
+r
again and again if the command you're looking for doesn't appear after your initial search.
- Press
Selecting a Match: Once you've found the desired command in the search results, you can press Enter to execute it immediately or use the arrow keys to navigate through multiple matches if there are any.
Exit: Press
esc
to come out of the search mode
mcfly
McFly incorporates an AI-based algorithm to bring context and intelligence to its search results rather than relying on a purely linear search of ctrl
+ r
It considers the current working directory and is more likely to suggest commands that you have run from that directory before.
Commands that resulted in an exit status of
Error
are less likely to be recommended.
Above are some of the most useful features of mcfly.
mcfly is the most efficient approach for the command history navigation.
Refer this to install and configure the mcfly https://www.linode.com/docs/guides/using-mcfly-to-search-bash-or-zsh-history/
Alias
alias is used to define custom shortcut which is alternative name for a longer command or series of commands.
# alias custom_comand='original command'
alias update='sudo apt update && sudo apt upgrade'
To make the alias permanent across bash sessions, define it in shell startup files like ~/.bashrc.
After defining the alias in the startup file, source the startup file or restart a bash session.
Functions
Define a custom bash functions in startup file.
mkdir is the most used linux command to create a new directory. Once you create a directory will cd to the created directory.
mkdir test
cd test
You can simplify this by defining a function that takes a directory name as an argument, creates the directory and then cd to it.
function mkcd
{
mkdir $1; cd $1
}
# mkcd test
# Creates a test directory and cd to the test
Command auto completion
When using CLI clients that offer a command-line interface for interacting with various services, you often benefit from the command auto-completion feature.
git
, kubectl
and helm
are some of the examples for CLI clients.
Command auto-completion is a feature that helps users complete commands or arguments by automatically suggesting or completing them based on the input provided.
After pressing tab after git c
, it suggests the subcommands that start with c.
If CLI client does not support command completion by default you can refer the documentation to configure it.
# define this in the bash startup files to enable the command completion
# for helm and kubectl
source <(helm completion bash)
source <(kubectl completion bash)
Thanks for reading.
I would love to hear your thoughts, suggestions, and any additional tips or tricks you'd like to share.
Keep exploring, keep experimenting, and keep pushing the boundaries of what's possible. Until next time, happy command-lining 😉