0

In Linux is there a way to cd folders in grep style?

For example you have directory named:

a__french_music___

I would like to write to terminal cdgrep fre and using Tab for autocompletion -->

cdgrep a__french_music___

Or to list all related alternatives if no a single directory exists.

1
  • 1
    Not exactly an answer but 'cd *fre*' will make you enter that folder. If multiple folders match you will get "too many arguments" in return instead. Commented Feb 23, 2023 at 15:20

2 Answers 2

1

This is not grep style, but Oh My Zsh comes with case-insensitive autocompletion for the cd command.

You can type cd fre, then press the Tab key to cycle through matches (only matches in the current directory will be shown), then the Return key when you are ready to select a match. If only one match is found, it will be automatically selected.

1
  • wow!!!! traditional scripts (bash commands) can run to this shell as .sh or are they incompatible? Commented Feb 24, 2023 at 19:10
0

You might try some readline shortcuts in bash:

  • type cd *fre* and press Esc+* (by default). It will expand to cd a__french_music___. If there are multiple matching folders, it will put them all on the same line though.

  • type cd *fre and press Esc+G (it auto-appends a *). If there is only one match, it will expand that onto the current line. If there are multiple matches, it will list them below like:

    $ ls *fre
    a__freaky/ a__french/ a__fresh/ 
    
1
  • this is much more complicated than oh myzesh solution... :) Commented Feb 24, 2023 at 19:12

You must log in to answer this question.

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