jump to navigation

Turn on Bash Smart Completion January 28, 2006

Posted by Carthik in administration, commands, snippets, ubuntu.
trackback

The Bash shell has this sweet feature where you can use the TAB key to auto-complete certain things. For example, when I am in my home directory, the following command:
$cd Do[TAB-key]
will automatically yield:
$cd Documents

If you are an absolute novice, like I was, not so long ago, discovering tab completion in the terminal can make you go “Wow!”. Wait till you hear the rest now 🙂

Though you can use the TAB key to complete the names of files and directories, by default the completion is pretty “dumb”. If you have already typed $cd D you would expect that the tab key would cause only the directory names to be completed, but if I try it on my machine, the tab completion tool uses filenames too.

Now, don’t despair! There is now a smart bash tab completion trick you can use. Smart completion even complete the arguments to commands!!

To enable smart completion, edit your /etc/bash.bashrc file. Uncomment the following lines, by removing the # in the beginning of the lines:

#if [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
#fi

Now you can use tab completion to power your way through commands.

You can even extend bash smart completion to your own favourite commands by using /etc/bash_completion, the “complete” utility and /etc/bash_completion.d . Explaining the nitty-gritty is beyond me. I refer you to the Debian Administration gurus for more information regarding smarter bash completion.

Comments»

1. stian karlsen - January 28, 2006

good to know!

2. AviDardik.com » Turn on Bash Smart Completion - January 28, 2006

[…] Another sweet little tip from the Ubuntu Blog: The Bash shell has this sweet feature where you can use the TAB key to auto-complete certain things. For example, when I am in my home directory, the following command: $cd Do[TAB-key] will automatically yield: $cd Documents If you are an absolute novice, like I was, not so long ago, discovering tab completion in the terminal can make you go “Wow!?. Wait till you hear the rest now […]

3. Sionide - January 29, 2006

I love little things like this which make Ubuntu a much better place 🙂

4. James - January 30, 2006

I need to try this. I’ve been wondering if it was possible to auto-complete command arguments.

5. thetorpedodog - February 3, 2006

You can also edit `~/.bashrc` to enable it only for yourself if you don’t want to disturb anybody else or you don’t have the privileges to edit `/etc/bash.bashrc`.

6. ozroc - April 4, 2006

Oh!…
I was really tired of losing tab completion when running anything under sudo…

I come from Debian and doing sudo just everytime is horrible… This stupid trick makes things much easyer.

Thanks!

7. bumsbacke - July 26, 2006

ozroc, just switch to root using “sudo su”

8. also-rr - October 18, 2006

This is now turned on by default in Kubuntu at least (as of 6.06) and is a pain in the backside as the behaviour isn’t correct in many situations.

So, here is how to turn it off http://www.revis.co.uk/site/?q=node/110 (and reasons why you should, and some workarounds).

Anyone know where to submit a bug report? 🙂

9. Ronnie - December 14, 2006

ozroc, just switch to root using “sudo su”

“sudo -l” is safer i thought

10. Installing using an RPM file « Ubuntu Blog - April 15, 2007

[…] keep the version number. Otherwise alien adds a “1″ to the version number. – Tip: Use Smart Tab Completion to avoid mistyping the file […]

11. lundner - May 14, 2007

thanx!thats what i searched 😉

12. the Jester - June 14, 2007

THANK YOU!!! It was working, reinstalled, and it stopped.

13. rengie - June 21, 2007

Great! Thanks! Indeed a supplement to my learning at http://www.mlmtraining.com

14. Web Hosting - ok it definately php was the splash screen one thing Im concerned about though during the boot I seen a few buffer - October 14, 2007

[…] check this out (better than fixed) https://ubuntu.wordpress.com/2006/01/28/turn-on-bash-smart-completion/ […]

15. AR - November 28, 2007

How about this line to .bashrc
bind ‘set completion-ignore-case on’
Now cd doc[TAB]
yields cd Documents

Somebody likes somebody does not like.

16. Linux T&T » Blog Archive » Bash completion Ubuntu - January 22, 2008
17. Bash Tip #2 | subprocess - March 13, 2008

[…] and it’s too late in the day for extra caffeine, so that’ll have to be it.  But, look here for tips on making your tab completion more powerful.  It’ll even complete command line […]

18. Alikus - May 5, 2008
19. Bash completion Ubuntu/Gentoo : Linux T&T - October 15, 2008
20. Araneidae - October 18, 2008

Hmm. Have to say I just searched for this page … so I could turn “smart” (AKA brain damaged) completion OFF. Can’t bear the way it thinks it’s being clever, and either hides files from me (“I’m sure that file is in that directory, you know”) or invents gibberish (on /media devices, in particular). This is on Ubuntu 8.04.

21. Am!NeS0Ft’s blog - January 7, 2009

[…] will keep the version number. Otherwise alien adds a “1″ to the version number. – Tip: Use Smart Tab Completion to avoid mistyping the file […]

22. Aurorix - May 4, 2009

@Araneidae
Agreed. I turned the damned thing off because it’s a right pain in the arse and kept getting in my way. For example try tab-completing to unzip a file that doesn’t end in extension .zip. It won’t let you. You either have to rename the file first, or work around it somehow (like type ‘ls’, then tab-complete the filename, then backup to replace ‘ls’ with ‘unzip’).

I can’t stand software that thinks it knows what I’m doing better than I do.

23. yksitie - November 27, 2009

Hi!
I am not used to hit the tab twice when a file name is not unique. For example when you have two files like result.dat and residuals.dat and you type res[TAB] nothing happens. You have to hit the TAB twice to see the list of all files starting with res . Is there a way to turn this to me unexpected behaviour off? I mean to see the list of all files starting with res hitting TAB once instead of twice?

24. Ubuntu Notes Dump « bishfoo - April 2, 2010

[…] Turn on bash auto-complete. (Source) sudo gedit /etc/bash.bashrc # Uncomment these 3 lines. #if [ -f /etc/bash_completion ]; then # . […]

25. Sağlık Bilgilendirme - April 2, 2010

Thank you for the opportunity you gave

26. sky - April 8, 2010

@23:

Put “set show-all-if-ambiguous on” in your /etc/inputrc or ~/.inputrc to make single tab show all

27. Jan Tomka - May 19, 2010

Quite some time ago I put together ClearCase UNIX tools completion for Bash. Have a look at it if you’re using ccase with bash or if you’re looking to write your own completion script: http://jan.tomka.name/project/clearcase-completion-bash

28. isveç şurubu - May 26, 2010

sağlık iksiri

29. biber hapı - May 26, 2010

Biber hapı ile zayıflarken stres gibi faktörlerini de en aşağıya indirebilirsiniz. Stresli olduğumuz durumlarda daha fazla yemek yeriz ve daha fazla kilo alırız. Bu stresi en azına indirebiliriz ve biber hapı ile destekleyerek daha iyi kilo verebiliriz.

30. dileeprocks - June 12, 2010

Thanq,this is what I need

31. Ubuntu Notes « bishfoo - July 27, 2010

[…] Turn on bash auto-complete. (Source) sudo gedit /etc/bash.bashrc # Uncomment these 3 lines. #if [ -f /etc/bash_completion ]; then # . […]

32. Jaydeep - August 9, 2010

I am new to UBUNTU and finding it awesome ……… 😀

33. bayan escort - August 9, 2010

Thanks for helpful information bayan escort siteleri you catch up us with your sagol instructional çok explanation.

34. Iconic - August 19, 2010

This was greatly helpful for me when I went from an USB Stick Live Ubuntu 10.04 (Lucid Lynx LTS) installation to my LTS-upto-LTS replaced HDD installation, and while it was working perfect with USB Live, it seemed to me that I did it somewhere wrong.

You saved some time for me, fellow.

35. escort bayanlar - September 5, 2010

thanks so much all admin turkiyenin 1 numarali eskort ilan sitesi.

36. escort siteleri - September 5, 2010

thankss good bloq.

37. porno sikiş - September 27, 2010

I need to try this. I’ve been wondering if it was possible to auto-complete command arguments.

38. Ubuntu Bash Completion - September 27, 2010

[…] above was tested on Ubuntu 10.04. See https://embraceubuntu.com/2006/01/28/turn-on-bash-smart-completion/ for some more information for bash completion for the root user. Bash, Bash Completion, Linux, […]

39. sex sikiş - September 28, 2010

This is now turned on by default in Kubuntu at least (as of 6.06) and is a pain in the backside as the behaviour isn’t correct in many situations.

40. escort şevval - February 15, 2011

Health has been good to your site on your hands

41. escort sude - February 15, 2011

Health has been good to your site on your hands

42. etiler escort bayan - February 28, 2011

Health has been good to your site on your hands

43. Best Crib Mattress - March 29, 2011

I like the valuable information you provide to your articles. I will bookmark your blog and test once more right here frequently. I am reasonably sure I will be told many new stuff proper right here! Best of luck for the next!

44. andymiken - July 14, 2011

Many thanks sharing fantastic informations. Ones websiteis consequently cool. We are impressed from the main factors that you’ve with this blog. The item reveals precisely how nicely people perceive this specific subject. Thank your share with me! http://www.fakeray-bansunglasses.com.

45. antalya böcek ilaçlama - August 7, 2011

antalya ev ilaçlama

46. Turn on Bash Smart Completion « Putokaz - December 10, 2011

[…] https://embraceubuntu.com/2006/01/28/turn-on-bash-smart-completion/ LD_AddCustomAttr("AdOpt", "1"); LD_AddCustomAttr("Origin", "other"); […]

47. Intrepid - January 6, 2012

It still works in 2012. (Meanwhile it is included in Ubuntu, I am not sure if it was in 6.04 too)

But it also very useful for other distros (I use BackTrack)

48. Simon - January 12, 2012

Thanks, I used your instructions to disable it under ~/.bashrc

Found it very annoying when it was stopping tab completion for things like:
$ sudo cryptsetup luksClose /dev/mapper/ [TAB] – doesn’t work!

But try:
$ cryptsetup luksOpen /dev/mapper/ [TAB] – that does work!

49. lalalala - December 29, 2012

Thanks a lot

50. fjr advisors llc - July 19, 2013

You could definitely see your skills in the work
you write. The arena hopes for more passionate writers like you who are not afraid to say how they
believe. Always follow your heart.

51. minecraft cracked - December 11, 2013

Beyond just building, various effects can be applied within the world you create, which makes the game more interesting and allows for
mini-games. I did feel a sort of anxiety that I had
not experience before in Minecraft Premium Account Generator, all I thought had been “I must survive. “Far” will make you see distant terrain features from above, making your line of sight virtually unlimited.

52. AnandKumar Patel - January 31, 2014

Nice. There is also a way to make your own autocompletes in bash! you can look and play around with an example here:
http://runnable.com/Uug-FAUPXc4hAADF/autocomplete-for-bash

53. Pamela - May 22, 2014

If you work in seo education therapy, does not create optimal performers.
Maybe much more connected and meaningful with your partner, stop all contact immediately with the persons with whom you enact fantasy scenarios that you
may be feeling anxious, depressed or stressed.
In the two-hour sessions, which convene twice monthly for six
months, if that’s what Mr.

54. Towing and Repossession Software - May 29, 2014

This website was… how do I say it? Relevant!! Finally I’ve found
something that helped me. Appreciate it!

55. Repo XR ™ - Repossession Software - August 5, 2014

When a individual car or truck is chosen by a person the program will exhibit which auto sections have presently been marketed relating to the car or
truck. ” Do keep receipts and bills of all expenses incurred in the accident to be presented to your insurer. Its not even a bad idea to pre-choose your hotel and make reservations before you leave.

56. publication manual of the american psychological association - August 23, 2014

I don’t know whether it’s just me or if everyone else experiencing problems with your website.
It appears like some of the written text in your content are running
off the screen. Can someone else please provide feedback and let
me know if this is happening to them as well? This might be a problem with my web
browser because I’ve had this happen previously. Kudos

57. Erika - October 8, 2014

Awesome issues here. I am ver satisfied to look your post.

Thanks a lot and I’m looking ahead to contact you.

Will you please drop me a e-mail?

58. outdoor weddings - December 17, 2014

outdoor weddings

Turn on Bash Smart Completion | Ubuntu Blog

59. (old) Instructions for Installing RPM Files Using Alien | The Worst Physical Theory - February 28, 2015

[…] will keep the version number. Otherwise alien adds a “1″ to the version number.- Tip: Use Smart Tab Completion to avoid mistyping the file names  $sudo dpkg -i name-of-deb-file.deb- This will install […]

60. Muftmovies2U.Net - April 26, 2015

Hiya very nice website!! Guy .. Excellent .. Wonderful
.. I will bookmark your site and take the feeds also? I’m glad to search
out so many helpful information right here within the put up, we want work out more strategies
in this regard, thanks for sharing. . . . . .

61. Fishres.Ru - April 14, 2017

Fishres.Ru

Turn on Bash Smart Completion | Ubuntu Blog

62. judi online bola - July 14, 2018

Yes! Finally something about bermain poker tanpa deposit.

63. Hillary B - November 6, 2022

Hi thanks for poosting this


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: