Linux Bash Shell short cuts

This is a post on improving your productivity when you are working with BASH shell/terminal. BASH shell is having many inbuilt capabilities such as history, command chaining and BASH shortcut. In this post we will see what are BASH shortcuts and their usage.

Frequently used shortcut keys

Ctrl+a – Bring back the courser to start of the bash prompt
Ctrl+c – Cancel the command before executing it
Ctrl+d – Logout from the Shell
Ctrl+e – Move the courser to end of the command
Ctrl+l – Clear the screen
Ctrl+r – Search the history reverse order
Ctrl+p – go to previous command in history
Ctrl+n – Go to next command in history
Ctrl+s – Suspend terminal output(Useful for long out commands )
Ctrl+z – suspend the command/send command running to background

 Less frequently used shortcut keys

Alt+. – To paste last used word from previous command
Ctrl + b – move backward one character
Alt + c – capitalize to end of word starting at cursor
Alt + d – delete to end of word starting at cursor
Ctrl + f – move forward one character
Ctrl + h – delete character before the cursor
Ctrl + k – delete all characters from cursor to the end of the command line
Alt + l – make lowercase from cursor to end of word
Ctrl + q – contunue the output after pressing ctrl+s
Ctrl + s – stops the output to the screen (for long running verbose command)
Alt + u – make uppercase from cursor to end of word
Ctrl + u – delete all characters from cursor to the start of the command line
Ctrl + w – delete from cursor to start of word, for each press this will delete one word at a time
Ctrl + y – paste the word(s) which are cut by using ctrl+k or u or w
Ctrl + xx – move to and fro from cursor to start and vice-versa.

Auto completion

When we are at prompt we can press press TAB key to auto-complete commands, directories, removing files/directories etc. We will see these as examples below for better understanding.

Example1: Execute lsdiff command to see if any files are modified by using auto complete without executing entire command.

ls<press tab>

Below commands are displayed to see which commands starts with ls

ls           lsb_release  lshw         lsof         lspgpot      
lsattr       lscpu        lsinitramfs  lspci        lss16toppm   
lsblk        lsdiff       lsmod        lspcmcia     lsusb   

Now if you type d then press <tab> it will complete the lsdiff command as shown below because there is no other command which start with lsd name.


Example2: Directory structure autocompletion. Suppose I want to open smb.conf which is located in /etc/samba folder we can open this by just typing /et<tab>/sa<tab>/sm<tab> to open /etc/samba/smb.conf file.

vi /et<tab>

vi /etc/sa<tab>

vi /etc/samba/sm<tab>

vi /etc/samba/smb.conf


Example3: Bash support wildcards. Delete all the files which are .sh file extension by using *.

rm -rf *.sh

Example4: I want to list all the files which starts with file and ends with .txt and having one character in between them.

ls -l file?.txt

This command will list all the files such as file1.txt, filea.txt, filez.txt etc.

Example5: List all the files which ends with a or b or c and start with file.

ls -l file[abc]

This will list filea, fileb and filec

Example6: List all the files which end with a to z, how can I do that?

ls -l file[a-z]

lists the files from filea, fileb to filez.

Example7: Move all the files expect .sh file extention files from present directory to /opt.

mv !(*.sh) /opt

Please share your thoughts on this.


!! – To execute previous executed command
!n – To execute nth previous executed command
!-n – To execute nth command from latest executed command
!char – To execute command which start with char

Show your love by sharing this..!
Share on VKShare on StumbleUponShare on YummlyPrint this pageFlattr the authorShare on TumblrEmail this to someoneBuffer this pageShare on Google+Share on LinkedInShare on FacebookTweet about this on TwitterPin on PinterestShare on RedditDigg this
The following two tabs change content below.
My name is Surendra Kumar Anne. I hail from Vijayawada which is capital of south Indian state of Andhra Pradesh. I am a Linux evangelist who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. I work with ICE systems, Sydney as Sr. Consultant. You can contact me at surendra (@) linuxnix dot com.
  • Linksy

    Thank you sir learning a lot from this blog. 

  • Surendra

    Wlcm buddy..!

  • Umar Sheriff

    hello please post about lanux kerneli and embedded connection

  • Sathis Str

     surendra sir Very useful commands 

  • Neildaemond

    now I won’t feel so bad when I forget to use sudo :)

  • venkat

    awesesome short cuts surendra ..

    • Surendra

      I agree.. I use them on regular basis

  • SubratN

    Really, Great job… thank u..

  • Inam

    Hi Surendra,
    I am new to Linux. Need some shortcuts to get going specially on setting PATH and scripting. I will appreciate if you can send me some easy to understand material/videos or link to those. Thanks

    • Surendra Anne

      Hi Inam,

                 You can check our scripting site for that Hope that helps you start off.