In this chapter, we’ll cover:
- Command-line editing shortcuts.
- Using command history effectively.
- Keyboard tricks for faster navigation and editing.
The command line is all about efficiency, and mastering keyboard shortcuts can dramatically speed up your workflow. Whether you’re fixing a typo, recalling a previous command, or navigating a long command, these tricks will make your life easier.
The shell provides several shortcuts for editing commands. Here are the most useful ones:
The shell keeps a history of the commands you’ve typed. Here’s how to use it effectively:
Use the history command to see a list of previously executed commands.
$ historyn.string.nano or vi). Save and exit to run the edited command.Here are some additional tricks to speed up your workflow:
clear command).You can customize keyboard shortcuts by editing your shell configuration file (e.g., .bashrc). For example, to map Ctrl + P to something else:
$ bind '"\C-p": "echo Hello, Linux!"'Add this line to your .bashrc and reload it with source ~/.bashrc.
Mastering keyboard shortcuts can significantly improve your terminal efficiency. Custom keybindings using bind allow you to create shortcuts for frequently used commands, while tmux enables you to manage multiple sessions and windows within a single terminal.
By combining custom shell keybindings with tmux’s session management, you can reduce the time spent on repetitive tasks and maintain a more organized workflow.
# Install tmux
$ sudo apt install tmux
# Example usage:
$ bind '"\C-f": "ls -la"'
$ tmux new -s mysessionWe will discuss tmux in greater details in Chapter 26 - Learning tmux
Let’s put your new skills to the test:
1. Use Ctrl + Aand Ctrl + E to move the cursor to the beginning and end of a command.
2. Use Ctrl + R to search for a previous command.
3. Use Ctrl + K to delete everything from the cursor to the end of the line.
4. Use Ctrl + Z to pause a command and fg to bring it back to the foreground.
That’s it for Chapter 8! You’ve now learned how to work more efficiently on the command line using advanced keyboard tricks. In the next chapter, we’ll dive into permissions—understanding file permissions and ownership.