Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I was wondering whether there is a way in the linux shell to type the first unique part of a filename or dirname and then add "~" or "..." and avoid writing the entire filename.

For example if I have to cd to the directory

example-program-source-0.11.229-dev

Instead of writing

cd example-program-source-0.11.229-dev

Just to write something like that

cd example-program...

Or

cd example-program~

I think there should be something like that integrated in shell, but I don't know what to search for exactly.

Thanks a lot!

share|improve this question
    
are you asking for the auto-completion in the terminal, or a way in a script? –  Anarko_Bizounours Aug 17 '12 at 14:34
add comment

2 Answers

up vote 20 down vote accepted

Most shells support what is known as "Tab Completion". Just type the unique part of the filename, and then hit your Tab key. The shell should auto-complete the rest of the filename for you. If there are still multiple files which match what you've typed so far, the shell will either cycle through the matching files as you hit Tab, or will print a list of all matching files when you double-hit Tab, depending on the configuration. Bash by default prints a list when you tap Tab twice.

share|improve this answer
add comment

You may use * as a wildcard:

cd example-program*

Note that this will expand to all the files matching the wildcard. In your case you can only use it if there are only one path starting with example-program. If there are multiple directories with the prefix, the command would effectively be expanded to for example:

cd example-program-source-0.11.229-dev example-program-other example-program.txt

This can be useful if you in fact want to work on multiple files, for example if you want to show the contents of all .log files in a folder:

cat *.log
share|improve this answer
    
For the OP's purpose, I use something like cd example*dev where I know that this will result in a single match. –  RedGrittyBrick Aug 17 '12 at 14:41
    
Thanks. Both solutions work perfectly, but Darth Android's one is easier. Anyway thanks. +1 from me ;) –  Itay Grudev Aug 17 '12 at 16:03
add comment

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.