Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo
* * * * * 2 votes

Using Tab Autocomplete


  • Please log in to reply
7 replies to this topic

#1 Al1000

Al1000

  • Global Moderator
  • 5,997 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Scotland
  • Local time:03:03 PM

Posted 23 February 2016 - 04:37 AM

Using Tab Autocomplete



Guide Overview

The purpose of this guide is to teach you how to use Tab Autocomplete to automatically complete paths and file names in a Linux terminal. The way it works is simple. All you do is press the Tab button on your keyboard, and the terminal automatically completes file names and paths. When you are used to using Tab Autocomplete, you will find using the terminal will be faster and you'll make less mistakes.

Tools Needed
  • Linux
Instructions
  • Example 1
    In this example I'll open a file in my home directory called Sustrans_glasgow_mapguide_Jan09.pdf using a pdf reader called Okular.

    In my terminal I type the name of the application, okular, then the first letter of the file I want to open:
    okular S
    ..then press Tab on my keyboard, and the terminal automatically completes the name of the file
    okular Sustrans_glasgow_mapguide_Jan09.pdf
    This is because Sustrans_glasgow_mapguide_Jan09.pdf is the only file in my home directory that begins with the character "S" so Tab autocomplete knows that must be the file that I want.
  • Example 2
    In this example I'll read a file called alternatives.log.1 at /var/log/alternatives.log.1, using cat
    In my terminal I type:
    cat /v
    Now I press Tab on my keyboard, and nothing happens. Why not? Because there is more than one directory beginning with the letter "v" in my root directory, so the terminal doesn't know which one I'm referring to. So I continue to type the next letter:
    cat /va
    Now I press Tab on my keyboard again, and the terminal automatically completes the line:
    cat /var/
    Because there is only one directory in my root directory beginning with "va" the terminal now knows which directory I want. See how it works?

    So I continue and type the next letter of the path:
    cat /var/l
    Now I press Tab on the keyboard, and again nothing happens. As you might have guessed, this is because there is more than one directory in my /var directory beginning with a lower case L.

    Continuing to type the next letter:
    cat /var/lo
    ...I press Tab on the keyboard and again nothing happens, because there is more than one directory in /var beginning with "lo" so the terminal doesn't know which directory I want.

    Typing the next letter
    cat /var/log
    ...the terminal now knows which directory I want when I press Tab:
    cat/var/log/
    Typing the next character in the path:
    cat /var/log/a
    ..then pressing Tab, again nothing happens, because there is more than one file on /var/log beginning with the character "a"

    Proceeding to type the next character:
    cat /var/log/al
    ... then pressing Tab, the terminal now partially completes the name of the file:
    cat /var/log/alternatives.log
    There is more than one file starting with alternatives.log in /var/log/ and the terminal knows that I want one of these files, but I still have to tell it which one.

    At this point, when the name of the path is almost complete, it would be just as well to type the rest of the path in manually.
I hope that this tutorial provides a basic understanding of how Tab Autocomplete works, and enough information for people to learn how to use it.

BC AdBot (Login to Remove)

 


m

#2 DeimosChaos

DeimosChaos

  • BC Advisor
  • 1,400 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:United States, Delaware
  • Local time:10:03 AM

Posted 02 March 2016 - 02:32 PM

When in the command line a lot, you will begin to rely very heavily on tab auto completion, it makes your life one hundred times easier and you can do things a whole lot faster! Nice tutorial AI!


OS - Ubuntu 14.04/16.04 & Windows 10
Custom Desktop PC / Lenovo Y580 / Sager NP8258 / Dell XPS 13 (9350)
_____________________________________________________
Bachelor of Science in Computing Security from Drexel University
Security +


#3 mremski

mremski

  • Members
  • 455 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:NH
  • Local time:10:03 AM

Posted 02 March 2016 - 03:14 PM

Depending on the shell you are using, say tcsh instead of bash, you may have to configure tab autocompletion.  For tcsh, in your .tcshrc file add a line that says:

 

set filec

 

If your filename has spaces or other special characters in it, you will need to "escape" or "quote" them, typically by a backslack before the space or special characters.

 

man autocomplete bash or man autocomplete tcsh will give you more good info.


FreeBSD since 3.3, only time I touch Windows is to fix my wife's computer


#4 Al1000

Al1000
  • Topic Starter

  • Global Moderator
  • 5,997 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Scotland
  • Local time:03:03 PM

Posted 09 March 2016 - 10:58 AM

Thanks DC. I had considered doing this once before, but thought that a tutorial isn't really necessary for pressing the TAB button. However having seen so many errors on the forum by users that could have been avoided by using TAB autocomplete, I decided that perhaps it would be worth writing after all.

 

Thanks for the additional info mremski; I didn't know TAB autocomplete has to be configured in other shells.



#5 DeimosChaos

DeimosChaos

  • BC Advisor
  • 1,400 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:United States, Delaware
  • Local time:10:03 AM

Posted 09 March 2016 - 12:03 PM

Most novice users probably have no idea about using it. So this a good awareness of the feature and how to use it.


OS - Ubuntu 14.04/16.04 & Windows 10
Custom Desktop PC / Lenovo Y580 / Sager NP8258 / Dell XPS 13 (9350)
_____________________________________________________
Bachelor of Science in Computing Security from Drexel University
Security +


#6 PieLam

PieLam

  • Members
  • 237 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Memphis, TN
  • Local time:10:03 AM

Posted 14 July 2016 - 09:13 AM

Just my two cents...
 
For a newbie, like me, this tutorial has been real helpful and 'on time' as I thought the tab autocomplete would require adding some kind of program or something requiring a download & install to the terminal.
 
I didn't think that tab autocomplete was a built-in feature!
 
Good tutorial AI!    :clapping:
 


#7 DeimosChaos

DeimosChaos

  • BC Advisor
  • 1,400 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:United States, Delaware
  • Local time:10:03 AM

Posted 14 July 2016 - 09:16 AM

It is just built right in PieLam! 

 

Though, not every single terminal application uses it... so every once in a great while you might run into it not actually working. But more times than not it actually works.


OS - Ubuntu 14.04/16.04 & Windows 10
Custom Desktop PC / Lenovo Y580 / Sager NP8258 / Dell XPS 13 (9350)
_____________________________________________________
Bachelor of Science in Computing Security from Drexel University
Security +


#8 Al1000

Al1000
  • Topic Starter

  • Global Moderator
  • 5,997 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Scotland
  • Local time:03:03 PM

Posted 15 July 2016 - 08:08 AM

Thanks PieLam!

 

It's a handy feature.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users