Search code examples
bashcd

cd into a directory without knowing its name in bash


If I know there will be a single folder inside a directory, but I do not know it's name, is there a simple way in bash to go into it? If I wanted to do a check to make sure a folder exists within the current directory, can that be done?


Solution

  • If there is only one sub-directory inside your current path then you can use this glob pattern to do cd:

    cd */
    

    Pattern */ matches all the sub-directories from current path and since there is only one so this cd will just change directory to single sub-directory.