AvoidErrors
  • HOME
  • WINDOWS
  • APPLE
  • MS OFFICE
  • RASPBERRY PI
  • WORDPRESS
  • TECH TIPS
  • LINUX
  • VIRTUALIZATION
  • FORUM
No Result
View All Result
AvoidErrors
No Result
View All Result

The Best Keyboard Shortcuts for Bash (aka the Linux and macOS Terminal)

Miguel by Miguel
April 25, 2017
in Apple, Linux
0
Share on FacebookShare on Reddit
RECOMMENDED: Transfer Windows and Installed Data to Another Hard Drive

The bash shell comes packed with a wide variety of keyboard shortcuts we can put to use.

These will work in bash on all operating system. Some of them might not work if you’re accessing bash remotely through an SSH or telnet session, depending on how you have your keys mapped.

Managing processes

Following key maps can be used to handle processes inside Bash:

  • Ctrl+C: This kills the current process running in inside bash. This generates a SIGINT signal to the process, which is just a request – most processes will accept it, but some may ignore it.
  • Ctrl+Z: Suspend the current foreground process running in bash. This sends the SIGTSTP signal to the process.

  • Ctrl+D: Close the bash shell. This sends an EOF (End-of-file) marker to bash, and bash exits when it receives this marker. This is similar to running the exit command.

Controlling the Screen

The following shortcuts allow you to control what appears on the screen.

  • Clear the screen : Use Ctrl+L. This is similar to running the “clear” command but shorter.
  • Ctrl+S: This will stop all the output to the screen. This is useful when a command with lots of verbose output is run. This will not stop the command itself.
  • Ctrl+Q: Resume output to the screen after stopping it with Ctrl+S.

Deleting Text

Following shortcuts are used to quickly delete characters:

  • Ctrl+D or Delete: Delete the character under the cursor.
  • Ctrl+H or Backspace: Delete the character before the cursor.
  • Alt+D: Delete all characters after the cursor on the current line.

Fixing Typos

These shortcuts allow you to fix typos and undo your key presses.

  • Ctrl+T: Swap the last two characters before the cursor with each other. You can use this to quickly fix typos when you type two characters in the wrong order.
  • Alt+T: Swap the current word with the previous word.
  • Ctrl+_: Undo your last key press. You can repeat this to undo multiple times.

Tab Completion

Tab completion is an important feature. While typing a file, directory, or command name, press Tab and bash will automatically complete what you’re typing, if possible. If not, bash will show you various possible matches and you can continue typing and pressing Tab to finish typing.

For example, if you any file, might be with a long name, long_file_name in /home/shubham/ and it’s the only file name starting with “lo” in that directory, you can type /home/shubham/r, press Tab, and bash will automatically fill in /home/shubham/long_file_name for you. If you have multiple files or directories starting with “lo”, bash will inform you of your possibilities.

You can start typing one of them and press “Tab” to continue. Here is an example:

Moving the Cursor

Use the following shortcuts to quickly move the cursor around the current line while typing a command.

  • Ctrl+A or Home: Go to the beginning of the line.
  • Ctrl+E or End: Go to the end of the line.
  • Alt+B: Go left (back) one word.
  • Ctrl+B: Go left (back) one character.
  • Alt+F: Go right (forward) one word.
  • Ctrl+F: Go right (forward) one character.
  • Ctrl+XX: Move between the beginning of the line and the current position of the cursor. This allows you to press Ctrl+XX to return to the start of the line, change something, and then press Ctrl+XX to go back to your original cursor position. To use this shortcut, hold the Ctrl key and tap the X key twice.

Previous Post

How to Use Bash History in the Linux or macOS Terminal

Next Post

Difference Between Bash, sh and other Linux Shells

Miguel

Miguel

I started this tech blog back in 2011 as a place to write down processes I took to fix my client systems and network. Now I write some tips and tricks to help others with the tech issues that one might encounter.

Related Posts

How to Share Notes and Folders with Family and Friends on iPhone or iPad
Apple

How to Recover Previously Deleted Notes on iPhone or iPad

by Ori Otokpa
July 25, 2022
How To Set Custom Vibrations on iPhone or iPad
Apple

How To Set Custom Vibrations on iPhone or iPad

by Ori Otokpa
July 25, 2022

Subscribe to get weekly tutorials direct to your inbox!

Windows

Fix .net Framework 3.5 Missing on Windows 11

by Rhousse
August 13, 2022
Clean Install Windows 11 Without USB
Windows

How to turn off Delivery Optimization on Windows 11

by Muhammad Imran Habib
August 13, 2022
How to Enable Dark Mode on Windows 11
Windows

How to Prevent Users from Changing Proxy Settings in Windows 11

by Muhammad Imran Habib
August 13, 2022
How to Check Laptop Battery Details in Windows 10
Windows

How to Create a New Custom Power Plan in Windows 11

by Muhammad Imran Habib
August 13, 2022
  • Disclaimer & Privacy Policy
  • FAQ
© 2022 Powered by Cloudways
No Result
View All Result
  • HOME
  • WINDOWS
  • APPLE
  • MS OFFICE
  • RASPBERRY PI
  • WORDPRESS
  • TECH TIPS
  • LINUX
  • VIRTUALIZATION
  • FORUM

© 2022 AvoidErrors Powered by Cloudways | Privacy

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.