The Shortcuts

The Shortcuts

We can speed up our command-line experience by taking advantage of the many built-in shortcuts.

These shortcuts are designed so that your hands never leave your keyboard "home base".

They take a little bit of practice to get comfortable with, but it's worth the effort!

Clearing

Use can use clear command to clear the entire screen, but there is also a shortcut ctrl+l which does the same thing.

Try it out!


Jumping

Use ctrl+a to move the cursor to the beginning of the line.

Use ctrl+e to move the cursor to the end of the line.

Use ctrl+f to move the cursor forward one character at a time (same as the right arrow).

Use ctrl+b to move the cursor backwards one character at a time (same as the left arrow).

These shortcuts are useful for the ones having arrow keys far right on their keyboard. It is a subtle convenience for them.

Use alt+f to move the cursor forward one word.

Use alt+b to move the cursor backwards one word.

Swapping

Use the shortcut ctrl+t to swap the current character under the cursor cursor with the one preceding it. This can be useful to correct the typos made by typing too quickly.

While swapping characters my not be that useful, but shortcut alt+t to swap words can come in handy.


Kill the Line

Use ctrl+k to kill the text from the current cursor location until the end of the line.

Use ctrl+u to kill the text from the current cursor location to the beginning of the line.

Killing the Word

Use alt+d to kill the text from the current cursor location through the end of the word.

Use alt+backspace to kill the text from the current cursor through the beginning of the word.

Reviving Text (Yanking)

When we kill text using commands like ctrl+k, ctrl+u, alt+d, and alt+backspace, the "killed" text is stored in a memory in an area known as the "kill-ring" (sounds like a wrestling event!).

We retrieve the most recently killed text using ctrl+y shortcut.

History

Bash keeps a record of the command we have previously entered. We can see the actual file at ~/.bash_history.

You can scroll through the history one command at a time using the up and down arrows.

We can also use the history command to view the entire history, though it's generally easier to manage if we pipe the output to less.

We can easily re-run an earlier command if we have its line number from the history. For example, to run the 73rd command in the history, we could run !73.

Often, it's easiest to find an earlier command by searching using a small portion of the command that you remember.

Type ctrl+r to enter "reverse-i-search". As you start typing, bash will search the history and show you the best match.

Hit ctrl+r to cycle through potential matches.

The better way to do this which I found useful is to open bash_history file using nano and then use search functionality / to search for your desired command.

Thanks for reading : )

要查看或添加评论,请登录

Shivm Soaini的更多文章

  • Pipelines

    Pipelines

    Pipes are used to redirect a stream from one program to another program. We can take the output of one command and…

  • The Standard Streams and Redirection

    The Standard Streams and Redirection

    The three standard streams are communication channels between a computer program and its environment. They are:…

  • Working with Files

    Working with Files

    The cat command The cat command concatenates and prints the contents of files. cat filename will read the contents of…

  • Deleting, Moving and Copying

    Deleting, Moving and Copying

    The rm command We use the rm (remove) command to remove files from our machine. For example, rm app.

  • The Nano Text editor

    The Nano Text editor

    Nano is a simple text editor that we can access right from the terminal. It's far more accessible than other popular…

  • Making Files and Folders

    Making Files and Folders

    The touch command To create a new file from the command line, use the touch command. Provide a filename, and that file…

  • Navigating the CLI Sea

    Navigating the CLI Sea

    The root directory The starting point for the file system is the root folder. We call it the root, but its actual…

  • Getting Help in Command Line Interface

    Getting Help in Command Line Interface

    Sometimes it's difficult to wrap our head around some of the commands we encounter. In this scenario, man pages can…

  • First Step in Command Line

    First Step in Command Line

    Some Familiar Terms A Shell is a computer interface to an operating system which expose the OS's services to the human…

  • A Brief History of Linux

    A Brief History of Linux

    The world of operating systems has many residents, but they can be segregated into two tribes: The Microsoft NT…

社区洞察

其他会员也浏览了