15

If I want to navigate inside folder with long hard-to-type name, is there way to use cd with some kind of shortened name of this folder, to get free from unnecessary work?

phuclv
  • 30,396
  • 15
  • 136
  • 260
Gill Bates
  • 165
  • 1
  • 1
  • 11

4 Answers4

22

The easiest solution would be to just press Tab to autocomplete folder names from the typed prefix, i.e. you type:

cd Foo

then press Tab, and it should complete with the first matching folder name.

As an alternative, Autojump is probably not the solution you directly asked for, but it's probably the most useful for changing folder names. It learns which folders you use frequently, and you can jump to them via entering:

j Foo

It will change to the folder based on that (part) name. You can limit the search to child directories with jc:

jc Foo

Note: It used to be possible to pass multiple arguments to bash, e.g. you could do cd Foo*, and that would expand to all matches of Foo*, where cd would change to the first of the arguments. However, with recent versions of cd this is no longer possible, resulting in an error: cd: too many arguments.

slhck
  • 235,242
16

You can use the Tab ↹ key to auto-complete partially typed filenames.

grawity
  • 501,077
1

There are various shells and shell extensions that support partial path autocomplete and fish is one of them beside zsh. For example cd /v/l/fsck Tab will convert the path to /var/log/fsck/. cd /u/s/appl Tab will expand the path to /usr/share/applications/

You can also use some fuzzy search software like

  • fuzzy bash completion

    This bash completion module performs "fuzzy" matching similar to textmate's "Go to File" fuzzy matching, "flex matching" in emacs' ido mode, etc.

      mkdir pizza
      mkdir jazz
      cd zz<TAB>
      # displays `pizza' and `jazz'
      rm -r jazz
      cd zz<TAB>
      # completes the word `pizza'
    
  • fzf: a general-purpose command-line fuzzy finder. Just press Alt-C to cd into the selected directory

    Demo: https://www.youtube.com/watch?v=qgG5Jhi_Els

    demo

  • Command-T: Command-T for shell

    Command-T is a Vim plug-in that provides an extremely fast "fuzzy" mechanism for:

    Command-T in action

See also Find file modes in console (fuzzy completion)

phuclv
  • 30,396
  • 15
  • 136
  • 260
1

You can try use zsh, it has advanced command completion features

cd /u/sh/lo + tab = cd /usr/share/locale

Also we can use zsh hash aliases and other magic zsh functions)

https://github.com/robbyrussell/oh-my-zsh https://github.com/zsh-users/zsh-completions

phuclv
  • 30,396
  • 15
  • 136
  • 260
user203508
  • 11
  • 1