How to navigate without the arrow keys on the command line

Published on Aug. 22, 2023, 12:12 p.m.

Shortcut keys provide an easier and quicker method of navigating.Knowing the little tips and tricks can make your day less hectic.One of the advantages of working in a terminal is that.

1. Navigate without the arrow keys

While executing commands on the command line, sometimes you miss a part at the beginning.It’s common for users to use the Left and Right arrow keys on the keyboard.

Instead of Left arrow, left, left, left, use CTRL+A to move back one word.Alt+F moves forward one word, and Alt+B moves back one word.

Instead of Right arrow, right, right, right, use CTRL+E to move forward a word.

2. Don’t use the backspace or delete keys

You might be used to using the Backspace key on the keyboard .You can also do this task more efficiently and easily.

Use CTRL+U to erase all from the current cursor position to the beginning of the line.Similarly , CTRL+K erases everything from the current cursor position.

3. Execute multiple commands in a single line

Sometimes it’s convenient to execute multiple commands in one go, letting a series of commands run.

Instead of running these commands in three different lines, I use a semi-colon (;) to concatenate them in sequence.

$ git add .
$ git commit -m "message"
$ git push origin main

Use:

$ git add .;git commit -m "message";git push origin main

To stop the sequence of commands when one fails, use && instead:

$ git add . && git commit -m "message" && git push origin main

4. Alias often used commands.

You probably run commands often.Sometimes, these may be lengthy commands or a combination of different commands.

I create an alias for the commands I use most frequently .

To create an alias, open your .bashrc file in your favorite editor .

alias gpom= "git push origin main"

After creating the alias, restart your configuration and change your settings :

$ . ~/.bashrc

And then try your command:

$ gpom

You can create an alias with the alias - statement in .bashrc or in your shell configuration file.

5. Search and run a previous command without using the arrow keys

There is an easier way: You can search your history using the history command.

When you use the history command, the list of commands appears.These numbers are known as the history number of the command.You can type !{ History - Number, on your terminal to run the command of the corresponding number.

Instead of Up arrow, up, up, up, Enter, type history, and then look for the history-number of the command you want to run:

$ !{history-number}