GRAPES

"We strive to provide Good, Reliable, Advanced, Professional, Enriching & Safe (GRAPES) experience by our products & services"

Useful Keyboard Shortcuts for Shell’s Command Line

Useful Keyboard Shortcuts for Shell’s Command Line

I prefer the command line in a shell terminal to perform various tasks including but not limited to file/directory creation, file/directory deletion, listing the contents of the directory, going or changing directory, modify the read/write & ownership privileges..etc. The unix shell is packed with many commands which makes your life easy for daily activities.  In this post, I would like to discuss some of the keyboard shortcuts which we can use on the command line.  Although, I am taking tcsh shell for the discussion but most of these shortcuts should be applicable to other shells as well.

Shortcuts with <CTRL> key

  • <CTRL> + l key combination causes the screen to be cleared.  We can use this to let the command line go to the beginning of the window and have the screen cleared!

    Terminal before performing clear screen using <CTRL>+l

     

    Terminal after clearing the screen using <CTRL>+l

     

  • <CTRL> + c key combination can be used to abort a running command.  Very useful when you want the running command to be aborted immediately

    Aborting sleep command using <CTRL>+c key sequence

     

  • <CTRL> + z key combination suspends a running command.  We use this when you don’t want the running command to abort but rather get suspended for some time.  You can resume the execution of the command using the “fg” (foreground) or “bg” (background) commands

    Sleep command getting suspended using <CTRL> + z key sequence

     

    Suspended Sleep command getting resumed using the “fg” command

     

  • <CTRL> + a key sequence will take the cursor to the beginning of the command line.  This is very useful when you want to go back to the beginning of the command (for example to correct a typo..etc) without having to use the arrow keys

    Terminal showing the cursor is at end of the command line text

     

    Terminal showing the cursor at the beginning of the command line using <CTRL>+a key

     

  • <CTRL> + e key sequence causes the cursor to move to the end of the command line.  Again very useful if you like to move the cursor to the end without pressing the arrow keys

    Terminal showing the cursor at the end of the command line after using <CTRL> + e key

     

  • <CTRL> + b key sequence emulates left arrow and causes the cursor to move left one character
  • <CTRL> + f key sequence emulates right arrow and causes the cursor to move right one character
  • <CTRL> + u key sequence clears the entire command line text and stores it in an internal buffer.  The contents of the internal buffer can then be pasted using the <CTRL> + y key sequence

    Terminal showing the cursor is at end of the command line text

     

    Terminal showing that the command line text is completely removed after <CTRL> + u key sequence

     

    Terminal showing the contents of the internal buffer being pasted after <CTRL> + y key sequence

     

  • <CTRL> + h key sequence deletes one character to the left of the cursor.  It’s similar to the <Backspace> key

    Terminal showing cursor at the letter ‘a’

     

    Terminal after key sequence <CTRL> + h (letter ‘e’ is deleted)

     

  • <CTRL> + d key sequence deletes one character at the cursor.  It emulates the <DEL> key

    Terminal after the key sequence <CTRL> + d (letter ‘a’ at the cursor got deleted)

     

  • <CTRL> + t key sequence causes the character at the cursor to be swapped with the character to the left of the cursor

    Terminal showing cursor at the letter ‘a’

     

    Character ‘a’ which was at the cursor got swapped with character ‘e’ after <CTRL> + t key sequence

     

Shortcuts with <Esc> key

  • <ESC> + <Backspace> key sequence causes a complete word to be deleted to the left of the cursor.  Very useful if you want to delete a word rather than just one character.  The deleted word is stored in the internal buffer and can be pasted back using the <CTRL> + y key sequence.

    Terminal showing the cursor at the beginning of the word “fft”

     

    Terminal showing the word “foreach” got deleted after <ESC> + <Backspace> key sequence

     

  • <ESC> + D key sequence causes a complete word to be deleted at the cursor.  Very useful if you want to delete a word rather than just one character.  The deleted word is stored in the internal buffer and can be pasted back using the <CTRL> + y key sequence

    Terminal showing that the word “fft” at the cursor got deleted after <ESC> + <D> sequence

     

  • <ESC> + p key sequence causes the shell to recall the command which was executed before in the shell.  By pressing this key combination one can cycle through all the previous commands which were executed before.  Furthermore, if you enter the first few characters of the command which was executed before and then using the ‘<ESC> + p’ key sequence then it recalls all the commands which got executed before matching those first few characters.

    Terminal showing letter ‘f’ in the command line

     

    Terminal showing the previous command being recalled which has ‘f’ in the beginning at the 1st application of <ESC> + p key

     

    Terminal showing the previous command being recalled which has ‘f’ in the beginning at the 2nd application of <ESC> + p key

     

  • <ESC> + b key sequence  causes the cursor to move left one word
  • <ESC> + f key sequence causes the cursor to move right one word

Please feel free to provide feedback and comment.  And don’t forget to give 👍 if you like the post

Avatar photo

Amjad

Website: https://blog.al-zakirah202.familyds.com

I'm Amjad from Bangalore in India. I got a Bachelor's degree in Electronics & Communications from National Institute of Engineering in 2004. I currently work as Product & Test Engineer at a Semiconductor Company. I am currently married with 3 kids - fortunate to be blessed with a good wife as well! I enjoy programming and automating things wherever possible. I have presented many papers and delivered talks in technical conferences. Among my hobbies are setting up home servers for media, photo, books and others, language learning, electronic circuit analysis, software development and many more..

Leave a Reply

Your email address will not be published. Required fields are marked *