Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


Instead of writing

cd example-program-source-0.11.229-dev

Just to write something like that

cd example-program...


cd example-program~

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

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
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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .