How do you cd into the first available folder without typing out the name?

I would advice either to type first few letters and pressing tab. Bash has autocomplete feature that is really useful. If it is only directory in in current path just pressing tab will fill whole directory.

Typing in cd and pressing tab twice will display all options in current directory.

tab is generally really useful in bash as you have accessible almost all executables at one or two keypresses.

cd * as suggested above works only if the directory is first in the listing and not hidden. If there is file alphabetically before your directory this cd won't change your directory at all.


I think I actually figured it out actually

cd * 
cd */

But I haven't tested it if there are multiple files and one folder!


As @Rinzwind mentioned in the comments!

Let's say you have three long folders:

 /thisislongfolder1
 /thisislongfolder2
 /thisislongfolder3

If you type the first letter of the file, then hit tab it will autocomplete the file name! CRAZY STUFF!

So in the example above, you can type: t tab and it will autocomplete as much as it can: cd thisislongfolder (then type the number yourself).

Or you can do cd t*1 would take you into thisislongfolder1

Thank you Rinzwind!


cd $(ls -d */|head -n 1)

ls -d */ lists the directories, head -n 1 gives the first one in this list.


I have a nice setup for this it allows me not only to cd to ~/somereallylongfoldername but also cd to there even when I'm in the / folder

the first thing I use is zsh with oh-my-zsh this will also allow you to cd without having to worry about case or even without typing cd

  1. install git and zsh
sudo apt-get install zsh git
  1. install Oh My ZSH

curl -L http://install.ohmyz.sh | sh

  1. Change the default shell to ZSH
chsh -s /bin/zsh

open and edit your .zshrc that is located in your home folder not it is hidden

nano ~/.zshrc

then add the following line to the bottom of the file export CDPATH=$CDPATH:/:/home/$USER/:/media/$USER/

If you like my theme you can also change the line #ZSH_THEME="robbyrussell" to ZSH_THEME="pygmalion"

Save and close the file then restart ie. close and reopen the shell or just open a new tab and try it out

not you can use the tab key to complete names and in ZSH you don't even have to have the case right you can type docu and press tab and it will turn it into ~/Documents

enter image description here