Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

As a new Linux user, one of the things that's kept me away from the Command Line (CL) is that, for tasks involving files and folders (i.e. everything!), the amount of typing involved makes using the CL inefficient. I myself have a tendency to use detailed file names. For example, if I have a book called "Elementary Differential Equations and Boundary Value Problems", which is in its 9th edition and is written by William Boyce and Richard DiPrima, then I'll name it like:

elementary_differentail_equations_and_boundary_value_problems_9ed_boyce_diprima.pdf.

So in my effort for learning to use the CL I've look around for ways to overcome this problem and found about Command-line completion with the Tab key. The thing with this is that it does word completion but only for commands, not for files and folders. I would like to know if there is a similar feature that works for files?

share|improve this question
3  
What shell are you using? All that I can think of that have tab completion at all support it for filenames in argument position in general. –  Michael Homer Aug 27 at 3:08
    
The standard one, I think. I just downloaded Xterm and have used that since. But, how do you do tab completion for files? Could you elaborate please. –  Kevin Garcia Aug 27 at 3:12
    
Type, say, xpdf elem and press Tab. Bash, which I guess is what you mean by "standard" shell will (by default) complete that name. –  Michael Homer Aug 27 at 3:26
    
What distribution are you using? Then we can sort out what your default shell is. –  Michael Homer Aug 27 at 3:29
    
I use Fedora 20. –  Kevin Garcia Aug 27 at 3:30

3 Answers 3

I use bash, and on tab, the file name completion happens as well.

But for the specific example that you have taken - of long file names, if you have many files with the same prefix in the directory, many tabs would be needed to get to the file!

I faced a similar problem with one codebase which I was working with, and the workaround I created for myself was, to have an alias + Perl script combination, to which I would give only the first letters, of the words in file name. E.g,

$ ls
elementary_differentail_equations.pdf # 1
elementary_differentail_equations_and_boundary_value_problems.pdf # 2
elementary_differentail_equations_and_boundary_value_problems_9ed_boyce_diprima.pdf # 3

$ opdf e d e                      # opens 1
$ opdf e d e a b v p              # opens 2
$ opdf e d e a b v p 9 b d        # opens 3

where opdf is the alias (say), which only looks for .pdf extension.

share|improve this answer
    
Can you post a link to the script? –  muru Aug 27 at 4:23
    
@muru, its here, its a perl script, plus you have to setup your environment to use it, as in, aliases etc. github.com/aniruddha-a/short_open –  vyom Aug 27 at 4:26
    
Thanks. I think zsh has a similar feature, but I'm too lazy to switch shells. –  muru Aug 27 at 4:30

When using Bash and its ability to perform completion via the Tab key, there are 2 aspects to the completion that might be getting confused.

When you type a letter at the prompt and start hitting Tab, you'll notice the behavior you're describing.

Example

$ elTab

el4-rpmlint  el5-rpmlint  elbadmin     elfedit      elif    elinks    else

This is searching your system's $PATH and presenting executables that match your search criteria, i.e. el.

However if you have a directory of files such as this one below, you can use the same completion capabilities via Tab like so.

Sample files:

$ ls -1
efile.pdf
elementary_differentail_equations_and_boundary_value_problems_9ed_boyce_diprima.pdf
elements1.pdf

Example

Performing this:

$ ls elTab

Bash would autocomplete this up to the word element. At which point it would stop since that's the largest string that is common among a group of files (or a single file) within the current directory. If you hit Tab twice now, Bash will list out the files that matched up to this point:

$ ls elementTabTab elementary_differentail_equations_and_boundary_value_problems_9ed_boyce_diprima.pdf elements1.pdf

$ ls element

It will then bring you back to your same location in your prompt. Bash basically did a ls element* for you in that moment. If you type a letter or two to help guide Bash on which file you want from the subset it presented you and hit Tab again, it will attempt to match some more of your files with your extended string you now have at the prompt:

$ ls elementaTab

Would be enough to get you the rest of your filename:

$ ls elementary_differentail_equations_and_boundary_value_problems_9ed_boyce_diprima.pdf

share|improve this answer

An alternative approach for the details of your question about what you are really trying to achieve: less typing.

You may also find that good aliases let you have the best of both worlds, i.e. long folder names. I like long folder names and I also like short names for typing and I achieve this with aliases such as:

alias zab='cd ~/mycar/activerecord-boolean-converter'
alias q='cd ~/Dropbox/95_2014/work/code/ruby__rails/ruby/ruby_quiz'
alias dummy='cd ~/zipcar/zipcar-rails-core/spec/dummy'

Then I just type, for example, q then press return

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.